mithril.js v2.0.0-rc.5 Release Notes

Release Date: 2019-05-29 // almost 5 years ago
  • PSA: ESM builds have been dropped from v2.0 as of #2366. Please update your scripts accordingly, as only CommonJS is supported until we can figure out a way to enable ES module support in a way that doesn't break everyone. (I've had to help troubleshoot way too many Webpack issues to feel comfortable with side-by-side support.)

    ๐Ÿš€ If all goes well with this release candidate, it will go stable as you see it now.

    ๐Ÿ’ฅ Breaking changes

    • API: Component vnode children are not normalized into vnodes on ingestion; normalization only happens if and when they are ingested by the view (#2155 (thanks to @magikstm for related optimization #2064))
    • API: m.redraw() is always asynchronous (#1592)
    • API: m.mount() will only render its own root when called, it will not trigger a redraw() (#1592)
    • ๐Ÿ‘ API: Assigning to vnode.state (as in vnode.state = ...) is no longer supported. Instead, an error is thrown if vnode.state changes upon the invocation of a lifecycle hook.
    • API: m.request will no longer reject the Promise on server errors (eg. status >= 400) if the caller supplies an extract callback. This gives applications more control over handling server responses.
    • hyperscript: when attributes have a null or undefined value, they are treated as if they were absent. #1773 (#2174)
    • ๐Ÿ“œ API: m.request errors no longer copy response fields to the error, but instead assign the parsed JSON response to error.response and the HTTP status code error.code.
    • hyperscript: when an attribute is defined on both the first and second argument (as a CSS selector and an attrs field, respectively), the latter takes precedence, except for class attributes that are still added together. #2172 (#2174)
    • render: Align custom elements to work like normal elements, minus all the HTML-specific magic. (#2221)
    • cast className using toString (#2309)
    • โšก๏ธ render: call attrs' hooks first, with express exception of onbeforeupdate to allow attrs to block components from even diffing (#2297)
    • ๐Ÿšš API: m.withAttr removed. (#2317)
    • ๐Ÿšš request: data has now been split to params and body and useBody has been removed in favor of just using body. (#2361)
    • route, request: Interpolated arguments are URL-escaped (and for declared routes, URL-unescaped) automatically. If you want to use a raw route parameter, use a variadic parameter like in /asset/:path.../view. This was previously only available in m.route route definitions, but it's now usable in both that and where paths are accepted. (#2361)
    • route, request: Interpolated arguments are not appended to the query string. This means m.request({url: "/api/user/:id/get", params: {id: user.id}}) would result in a request like GET /api/user/1/get, not one like GET /api/user/1/get?id=1. If you really need it in both places, pass the same value via two separate parameters with the non-query-string parameter renamed, like in m.request({url: "/api/user/:urlID/get", params: {id: user.id, urlID: user.id}}). (#2361)
    • route, request: m.route.set, m.request, and m.jsonp all use the same path template syntax now, and vary only in how they receive their parameters. Furthermore, declared routes in m.route shares the same syntax and semantics, but acts in reverse as if via pattern matching. (#2361)
    • 0๏ธโƒฃ request: options.responseType now defaults to "json" if extract is absent, and deserialize receives the parsed response, not the raw string. If you want the old behavior, use responseType: "text". (#2335)

    ๐Ÿ†• News

    • ๐Ÿ‘ Mithril now only officially supports IE11, Firefox ESR, and the last two versions of Chrome/FF/Edge/Safari. (#2296)
    • ๐Ÿ”€ API: Introduction of m.redraw.sync() (#1592)
    • API: Event handlers may also be objects with handleEvent methods (#1949, #2222).
    • API: m.route.link accepts an optional options object (#1930)
    • ๐Ÿ“œ API: m.request better error message on JSON parse error - (#2195, @codeclown)
    • โฑ API: m.request supports timeout as attr - (#1966)
    • ๐Ÿ‘ API: m.request supports responseType as attr - (#2193)
    • ๐Ÿคก Mocks: add limited support for the DOMParser API (#2097)
    • ๐Ÿ‘ API: add support for raw SVG in m.trust() string (#2097)
    • ๐Ÿšš render/core: remove the DOM nodes recycling pool (#2122)
    • render/core: revamp the core diff engine, and introduce a longest-increasing-subsequence-based logic to minimize DOM operations when re-ordering keyed nodes.
    • ๐Ÿ“„ docs: Emphasize Closure Components for stateful components, use them for all stateful component examples.
    • API: ES module bundles are now available for mithril and mithril/stream (#2194 @porsager).
      • All of the m.* properties from mithril are re-exported as named exports in addition to being attached to m.
      • m() itself from mithril is exported as the default export.
      • mithril/stream's primary export is exported as the default export.
    • fragments: allow same attrs/children overloading logic as hyperscript (#2328)
    • route: Declared routes may check against path names with query strings. (#2361)
    • ๐Ÿ‘ route: Declared routes in m.route now support - and . as delimiters for path segments. This means you can have a route like "/edit/:file.:ext". (#2361)
      • Previously, this was possible to do in m.route.set, m.request, and m.jsonp, but it was wholly untested for and also undocumented.
    • ๐Ÿ— API: m.buildPathname and m.parsePathname added. (#2361)

    ๐Ÿ› Bug fixes

    • API: m.route.set() causes all mount points to be redrawn (#1592)
    • ๐Ÿ’… render/attrs: Using style objects in hyperscript calls will now properly diff style properties from one render to another as opposed to re-writing all element style properties every render.
    • ๐Ÿšš render/attrs All vnodes attributes are properly removed when absent or set to null or undefined #1804 #2082 (#1865, #2130)
    • render/core: Render state correctly on select change event #1916 (#1918 @robinchew, #2052)
    • โšก๏ธ render/core: fix various updateNodes/removeNodes issues when the pool and fragments are involved #1990, #1991, #2003, #2021
    • render/core: fix crashes when the keyed vnodes with the same key had different tag values #2128 @JacksonJN (#2130)
    • render/core: fix cached nodes behavior in some keyed diff scenarios #2132 (#2130)
    • ๐Ÿšš render/events: addEventListener and removeEventListener are always used to manage event subscriptions, preventing external interference.
    • render/events: Event listeners allocate less memory, swap at low cost, and are properly diffed now when rendered via m.mount()/m.redraw().
    • render/events: Object.prototype properties can no longer interfere with event listener calls.
    • ๐Ÿšš render/events: Event handlers, when set to literally undefined (or any non-function), are now correctly removed.
    • ๐Ÿ›  render/hooks: fixed an ommission that caused oninit to be called unnecessarily in some cases #1992
    • ๐Ÿ“„ docs: tweaks: (#2104 @mikeyb, #2205, @cavemansspa, #2250 @isiahmeadows, #2265, @isiahmeadows)
    • render/core: avoid touching Object.prototype. __proto__ setter with key: " __proto__" in certain situations (#2251)
    • render/core: Vnodes stored in the dom node supplied to m.render() are now normalized #2266
    • ๐Ÿ’… render/core: CSS vars can now be specified in {style} attributes (#2192 @barneycarroll), (#2311 @porsager), (#2312 @isiahmeadows)
    • request: don't modify params, call extract/serialize/deserialize with correct this value (#2288)
    • render: simplify component removal (#2214)
    • ๐Ÿšš render: remove some redundancy within the component initialization code (#2213)
    • ๐Ÿ‘€ API: mithril loads mithril/index.js, not the bundle, so users of mithril/hyperscript, mithril/render, and similar see the same Mithril instance as those just using mithril itself.
      • https://unpkg.com/mithril is configured to receive the minified bundle, not the development bundle.
      • The raw bundle itself remains accessible at mithril.js, and is not browser-wrapped.
      • Note: this will increase overhead with bundlers like Webpack, Rollup, and Browserify.