You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix#2434
* Treat holes as unkeyed, normalize boolean/null/undefined
This brings a lot better consistency with that API, even though it's
slightly breaking. (I had to update a bunch of tests to correspond with
it.)
* Fill in PR number [skip ci]
Copy file name to clipboardExpand all lines: docs/change-log.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,15 @@
45
45
- Previously, it was only set for all non-`GET` methods and only when `useBody: true` was passed (the default), and it was always set for them. Now it's automatically omitted when no body is present, so the hole is slightly broadened.
46
46
- route: query parameters in hash strings are no longer supported ([#2448](https://github.com/MithrilJS/mithril.js/pull/2448)[@isiahmeadows](https://github.com/isiahmeadows))
47
47
- It's technically invalid in hashes, so I'd rather push people to keep in line with spec.
48
+
- render: validate all elements are either keyed or unkeyed, and treat `null`/`undefined`/booleans as strictly unkeyed ([#2452](https://github.com/MithrilJS/mithril.js/pull/2452)[@isiahmeadows](https://github.com/isiahmeadows))
49
+
- Gives a nice little perf boost with keyed fragments.
50
+
- Minor, but imperceptible impact (within the margin of error) with unkeyed fragments.
51
+
- Also makes the model a lot more consistent - all values are either keyed or unkeyed.
52
+
- vnodes: normalize boolean children to `null`/`undefined` at the vnode level, always stringify non-object children that aren't holes ([#2452](https://github.com/MithrilJS/mithril.js/pull/2452)[@isiahmeadows](https://github.com/isiahmeadows))
53
+
- Previously, `true` was equivalent to `"true"` and `false` was equivalent to `""`.
54
+
- Previously, numeric children weren't coerced. Now, they are.
55
+
- Unlikely to break most components, but it *could* break some users.
56
+
- This increases consistency with how booleans are handled with children, so it should be more intuitive.
48
57
49
58
#### News
50
59
@@ -101,6 +110,7 @@
101
110
- route: arbitrary prefixes are properly supported now, including odd prefixes like `?#` and invalid prefixes like `#foo#bar` ([#2448](https://github.com/MithrilJS/mithril.js/pull/2448)[@isiahmeadows](https://github.com/isiahmeadows))
102
111
- request: correct IE workaround for response type non-support ([#2449](https://github.com/MithrilJS/mithril.js/pull/2449)[@isiahmeadows](https://github.com/isiahmeadows))
103
112
- render: correct `contenteditable` check to also check for `contentEditable` property name ([#2450](https://github.com/MithrilJS/mithril.js/pull/2450)[@isiahmeadows](https://github.com/isiahmeadows))
Copy file name to clipboardExpand all lines: docs/hyperscript.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,7 +159,7 @@ m("button", {
159
159
160
160
If the value of such an attribute is `null` or `undefined`, it is treated as if the attribute was absent.
161
161
162
-
If there are class names in both first and second arguments of `m()`, they are merged together as you would expect. If the value of the class in the second argument is `null`or `undefined`, it is ignored.
162
+
If there are class names in both first and second arguments of `m()`, they are merged together as you would expect. If the value of the class in the second argument is `null`or `undefined`, it is ignored.
163
163
164
164
If another attribute is present in both the first and the second argument, the second one takes precedence even if it is is `null` or `undefined`.
Copy file name to clipboardExpand all lines: docs/keys.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,27 @@ function correctUserList(users) {
75
75
}
76
76
```
77
77
78
+
Also, you might want to reinitialize a component. You can use the common pattern of a single-item keyed fragment where you change the key to destroy and reinitialize the element.
79
+
80
+
```javascript
81
+
functionResettableToggle() {
82
+
var toggleKey =false
83
+
84
+
functionreset() {
85
+
toggleKey =!toggleKey
86
+
}
87
+
88
+
return {
89
+
view:function() {
90
+
return [
91
+
m("button", {onclick: reset}, "Reset toggle"),
92
+
[m(Toggle, {key: toggleKey})]
93
+
]
94
+
}
95
+
}
96
+
}
97
+
```
98
+
78
99
---
79
100
80
101
### Debugging key related issues
@@ -178,6 +199,10 @@ m("div", [
178
199
])
179
200
```
180
201
202
+
In fact, this will cause an error to be thrown, to remind you to not do it. So don't do it!
203
+
204
+
Note that `null`s, `undefined`s, and booleans are considered unkeyed nodes. If you want the keyed equivalent, use `m.fragment({key: ...}, [])`, a keyed empty fragment.
205
+
181
206
#### Avoid passing model data directly to components if the model uses `key` as a data property
182
207
183
208
The `key` property may appear in your data model in a way that conflicts with Mithril's key logic. For example, a component may represent an entity whose `key` property is expected to change over time. This can lead to components receiving the wrong data, re-initialize, or change positions unexpectedly. If your data model uses the `key` property, make sure to wrap the data such that Mithril doesn't misinterpret it as a rendering instruction:
0 commit comments