isomorfeus-preact 10.6.14 → 10.6.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isomorfeus-preact.rb +4 -4
  3. data/lib/isomorfeus_preact/lucid_component/api.rb +1 -1
  4. data/lib/isomorfeus_preact/lucid_component/initializer.rb +2 -4
  5. data/lib/isomorfeus_preact/lucid_func/initializer.rb +1 -1
  6. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +1 -1
  7. data/lib/preact/component/api.rb +2 -2
  8. data/lib/preact/component/callbacks.rb +6 -6
  9. data/lib/preact/component/initializer.rb +2 -2
  10. data/lib/preact/component/native_component_constructor.rb +1 -1
  11. data/lib/preact/component/resolution.rb +2 -2
  12. data/lib/preact/params.rb +16 -0
  13. data/lib/preact/props.rb +69 -0
  14. data/lib/preact/state.rb +87 -0
  15. data/lib/preact/version.rb +1 -1
  16. data/lib/preact.rb +4 -2
  17. data/node_modules/.package-lock.json +3 -3
  18. data/node_modules/preact/LICENSE +21 -21
  19. data/node_modules/preact/README.md +187 -187
  20. data/node_modules/preact/compat/dist/compat.js +1 -1
  21. data/node_modules/preact/compat/dist/compat.js.map +1 -1
  22. data/node_modules/preact/compat/dist/compat.mjs +1 -1
  23. data/node_modules/preact/compat/dist/compat.module.js +1 -1
  24. data/node_modules/preact/compat/dist/compat.module.js.map +1 -1
  25. data/node_modules/preact/compat/dist/compat.umd.js +1 -1
  26. data/node_modules/preact/compat/dist/compat.umd.js.map +1 -1
  27. data/node_modules/preact/compat/jsx-dev-runtime.js +1 -1
  28. data/node_modules/preact/compat/jsx-dev-runtime.mjs +1 -1
  29. data/node_modules/preact/compat/jsx-runtime.js +1 -1
  30. data/node_modules/preact/compat/jsx-runtime.mjs +1 -1
  31. data/node_modules/preact/compat/package.json +19 -19
  32. data/node_modules/preact/compat/scheduler.js +15 -15
  33. data/node_modules/preact/compat/scheduler.mjs +23 -23
  34. data/node_modules/preact/compat/server.js +15 -15
  35. data/node_modules/preact/compat/server.mjs +4 -4
  36. data/node_modules/preact/compat/src/Children.js +21 -21
  37. data/node_modules/preact/compat/src/PureComponent.js +15 -15
  38. data/node_modules/preact/compat/src/forwardRef.js +51 -51
  39. data/node_modules/preact/compat/src/index.d.ts +141 -141
  40. data/node_modules/preact/compat/src/index.js +187 -187
  41. data/node_modules/preact/compat/src/internal.d.ts +47 -47
  42. data/node_modules/preact/compat/src/memo.js +34 -34
  43. data/node_modules/preact/compat/src/portals.js +80 -80
  44. data/node_modules/preact/compat/src/render.js +229 -230
  45. data/node_modules/preact/compat/src/suspense-list.d.ts +14 -14
  46. data/node_modules/preact/compat/src/suspense-list.js +126 -126
  47. data/node_modules/preact/compat/src/suspense.d.ts +15 -15
  48. data/node_modules/preact/compat/src/suspense.js +270 -270
  49. data/node_modules/preact/compat/src/util.js +28 -28
  50. data/node_modules/preact/compat/test-utils.js +1 -1
  51. data/node_modules/preact/debug/dist/debug.js.map +1 -1
  52. data/node_modules/preact/debug/dist/debug.module.js.map +1 -1
  53. data/node_modules/preact/debug/dist/debug.umd.js.map +1 -1
  54. data/node_modules/preact/debug/package.json +18 -18
  55. data/node_modules/preact/debug/src/check-props.js +54 -54
  56. data/node_modules/preact/debug/src/component-stack.js +146 -146
  57. data/node_modules/preact/debug/src/constants.js +3 -3
  58. data/node_modules/preact/debug/src/debug.js +442 -442
  59. data/node_modules/preact/debug/src/index.js +6 -6
  60. data/node_modules/preact/debug/src/internal.d.ts +82 -82
  61. data/node_modules/preact/debug/src/util.js +11 -11
  62. data/node_modules/preact/devtools/dist/devtools.js +1 -1
  63. data/node_modules/preact/devtools/dist/devtools.js.map +1 -1
  64. data/node_modules/preact/devtools/dist/devtools.mjs +1 -1
  65. data/node_modules/preact/devtools/dist/devtools.module.js +1 -1
  66. data/node_modules/preact/devtools/dist/devtools.module.js.map +1 -1
  67. data/node_modules/preact/devtools/dist/devtools.umd.js +1 -1
  68. data/node_modules/preact/devtools/dist/devtools.umd.js.map +1 -1
  69. data/node_modules/preact/devtools/package.json +16 -16
  70. data/node_modules/preact/devtools/src/devtools.js +10 -10
  71. data/node_modules/preact/devtools/src/index.d.ts +8 -8
  72. data/node_modules/preact/devtools/src/index.js +15 -15
  73. data/node_modules/preact/dist/preact.js.map +1 -1
  74. data/node_modules/preact/dist/preact.min.js.map +1 -1
  75. data/node_modules/preact/dist/preact.module.js.map +1 -1
  76. data/node_modules/preact/dist/preact.umd.js.map +1 -1
  77. data/node_modules/preact/hooks/dist/hooks.js +1 -1
  78. data/node_modules/preact/hooks/dist/hooks.js.map +1 -1
  79. data/node_modules/preact/hooks/dist/hooks.mjs +1 -1
  80. data/node_modules/preact/hooks/dist/hooks.module.js +1 -1
  81. data/node_modules/preact/hooks/dist/hooks.module.js.map +1 -1
  82. data/node_modules/preact/hooks/dist/hooks.umd.js +1 -1
  83. data/node_modules/preact/hooks/dist/hooks.umd.js.map +1 -1
  84. data/node_modules/preact/hooks/package.json +26 -26
  85. data/node_modules/preact/hooks/src/index.d.ts +139 -139
  86. data/node_modules/preact/hooks/src/index.js +386 -388
  87. data/node_modules/preact/hooks/src/internal.d.ts +75 -75
  88. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +1 -1
  89. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +1 -1
  90. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +1 -1
  91. data/node_modules/preact/jsx-runtime/package.json +19 -19
  92. data/node_modules/preact/jsx-runtime/src/index.d.ts +50 -50
  93. data/node_modules/preact/jsx-runtime/src/index.js +77 -77
  94. data/node_modules/preact/package.json +291 -287
  95. data/node_modules/preact/src/cjs.js +3 -3
  96. data/node_modules/preact/src/clone-element.js +34 -34
  97. data/node_modules/preact/src/component.js +225 -225
  98. data/node_modules/preact/src/constants.js +3 -3
  99. data/node_modules/preact/src/create-context.js +68 -68
  100. data/node_modules/preact/src/create-element.js +98 -98
  101. data/node_modules/preact/src/diff/catch-error.js +38 -38
  102. data/node_modules/preact/src/diff/children.js +335 -335
  103. data/node_modules/preact/src/diff/index.js +516 -516
  104. data/node_modules/preact/src/diff/props.js +158 -158
  105. data/node_modules/preact/src/index.d.ts +310 -310
  106. data/node_modules/preact/src/index.js +13 -13
  107. data/node_modules/preact/src/internal.d.ts +146 -146
  108. data/node_modules/preact/src/jsx.d.ts +1005 -1005
  109. data/node_modules/preact/src/options.js +16 -16
  110. data/node_modules/preact/src/render.js +75 -75
  111. data/node_modules/preact/src/util.js +27 -27
  112. data/node_modules/preact/test-utils/dist/testUtils.js.map +1 -1
  113. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +1 -1
  114. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +1 -1
  115. data/node_modules/preact/test-utils/package.json +19 -19
  116. data/node_modules/preact/test-utils/src/index.d.ts +3 -3
  117. data/node_modules/preact/test-utils/src/index.js +117 -117
  118. data/package.json +1 -1
  119. metadata +7 -7
  120. data/lib/preact/component/params.rb +0 -18
  121. data/lib/preact/component/props.rb +0 -55
  122. data/lib/preact/component/state.rb +0 -58
@@ -1,335 +1,335 @@
1
- import { diff, unmount, applyRef } from './index';
2
- import { createVNode, Fragment } from '../create-element';
3
- import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
4
- import { getDomSibling } from '../component';
5
-
6
- /**
7
- * Diff the children of a virtual node
8
- * @param {import('../internal').PreactElement} parentDom The DOM element whose
9
- * children are being diffed
10
- * @param {import('../internal').ComponentChildren[]} renderResult
11
- * @param {import('../internal').VNode} newParentVNode The new virtual
12
- * node whose children should be diff'ed against oldParentVNode
13
- * @param {import('../internal').VNode} oldParentVNode The old virtual
14
- * node whose children should be diff'ed against newParentVNode
15
- * @param {object} globalContext The current context object - modified by getChildContext
16
- * @param {boolean} isSvg Whether or not this DOM node is an SVG node
17
- * @param {Array<import('../internal').PreactElement>} excessDomChildren
18
- * @param {Array<import('../internal').Component>} commitQueue List of components
19
- * which have callbacks to invoke in commitRoot
20
- * @param {import('../internal').PreactElement} oldDom The current attached DOM
21
- * element any new dom elements should be placed around. Likely `null` on first
22
- * render (except when hydrating). Can be a sibling DOM element when diffing
23
- * Fragments that have siblings. In most cases, it starts out as `oldChildren[0]._dom`.
24
- * @param {boolean} isHydrating Whether or not we are in hydration
25
- */
26
- export function diffChildren(
27
- parentDom,
28
- renderResult,
29
- newParentVNode,
30
- oldParentVNode,
31
- globalContext,
32
- isSvg,
33
- excessDomChildren,
34
- commitQueue,
35
- oldDom,
36
- isHydrating
37
- ) {
38
- let i, j, oldVNode, childVNode, newDom, firstChildDom, refs;
39
-
40
- // This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
41
- // as EMPTY_OBJ._children should be `undefined`.
42
- let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;
43
-
44
- let oldChildrenLength = oldChildren.length;
45
-
46
- newParentVNode._children = [];
47
- for (i = 0; i < renderResult.length; i++) {
48
- childVNode = renderResult[i];
49
-
50
- if (childVNode == null || typeof childVNode == 'boolean') {
51
- childVNode = newParentVNode._children[i] = null;
52
- }
53
- // If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
54
- // or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
55
- // it's own DOM & etc. pointers
56
- else if (
57
- typeof childVNode == 'string' ||
58
- typeof childVNode == 'number' ||
59
- // eslint-disable-next-line valid-typeof
60
- typeof childVNode == 'bigint'
61
- ) {
62
- childVNode = newParentVNode._children[i] = createVNode(
63
- null,
64
- childVNode,
65
- null,
66
- null,
67
- childVNode
68
- );
69
- } else if (Array.isArray(childVNode)) {
70
- childVNode = newParentVNode._children[i] = createVNode(
71
- Fragment,
72
- { children: childVNode },
73
- null,
74
- null,
75
- null
76
- );
77
- } else if (childVNode._depth > 0) {
78
- // VNode is already in use, clone it. This can happen in the following
79
- // scenario:
80
- // const reuse = <div />
81
- // <div>{reuse}<span />{reuse}</div>
82
- childVNode = newParentVNode._children[i] = createVNode(
83
- childVNode.type,
84
- childVNode.props,
85
- childVNode.key,
86
- null,
87
- childVNode._original
88
- );
89
- } else {
90
- childVNode = newParentVNode._children[i] = childVNode;
91
- }
92
-
93
- // Terser removes the `continue` here and wraps the loop body
94
- // in a `if (childVNode) { ... } condition
95
- if (childVNode == null) {
96
- continue;
97
- }
98
-
99
- childVNode._parent = newParentVNode;
100
- childVNode._depth = newParentVNode._depth + 1;
101
-
102
- // Check if we find a corresponding element in oldChildren.
103
- // If found, delete the array item by setting to `undefined`.
104
- // We use `undefined`, as `null` is reserved for empty placeholders
105
- // (holes).
106
- oldVNode = oldChildren[i];
107
-
108
- if (
109
- oldVNode === null ||
110
- (oldVNode &&
111
- childVNode.key == oldVNode.key &&
112
- childVNode.type === oldVNode.type)
113
- ) {
114
- oldChildren[i] = undefined;
115
- } else {
116
- // Either oldVNode === undefined or oldChildrenLength > 0,
117
- // so after this loop oldVNode == null or oldVNode is a valid value.
118
- for (j = 0; j < oldChildrenLength; j++) {
119
- oldVNode = oldChildren[j];
120
- // If childVNode is unkeyed, we only match similarly unkeyed nodes, otherwise we match by key.
121
- // We always match by type (in either case).
122
- if (
123
- oldVNode &&
124
- childVNode.key == oldVNode.key &&
125
- childVNode.type === oldVNode.type
126
- ) {
127
- oldChildren[j] = undefined;
128
- break;
129
- }
130
- oldVNode = null;
131
- }
132
- }
133
-
134
- oldVNode = oldVNode || EMPTY_OBJ;
135
-
136
- // Morph the old element into the new one, but don't append it to the dom yet
137
- diff(
138
- parentDom,
139
- childVNode,
140
- oldVNode,
141
- globalContext,
142
- isSvg,
143
- excessDomChildren,
144
- commitQueue,
145
- oldDom,
146
- isHydrating
147
- );
148
-
149
- newDom = childVNode._dom;
150
-
151
- if ((j = childVNode.ref) && oldVNode.ref != j) {
152
- if (!refs) refs = [];
153
- if (oldVNode.ref) refs.push(oldVNode.ref, null, childVNode);
154
- refs.push(j, childVNode._component || newDom, childVNode);
155
- }
156
-
157
- if (newDom != null) {
158
- if (firstChildDom == null) {
159
- firstChildDom = newDom;
160
- }
161
-
162
- if (
163
- typeof childVNode.type == 'function' &&
164
- childVNode._children === oldVNode._children
165
- ) {
166
- childVNode._nextDom = oldDom = reorderChildren(
167
- childVNode,
168
- oldDom,
169
- parentDom
170
- );
171
- } else {
172
- oldDom = placeChild(
173
- parentDom,
174
- childVNode,
175
- oldVNode,
176
- oldChildren,
177
- newDom,
178
- oldDom
179
- );
180
- }
181
-
182
- if (typeof newParentVNode.type == 'function') {
183
- // Because the newParentVNode is Fragment-like, we need to set it's
184
- // _nextDom property to the nextSibling of its last child DOM node.
185
- //
186
- // `oldDom` contains the correct value here because if the last child
187
- // is a Fragment-like, then oldDom has already been set to that child's _nextDom.
188
- // If the last child is a DOM VNode, then oldDom will be set to that DOM
189
- // node's nextSibling.
190
- newParentVNode._nextDom = oldDom;
191
- }
192
- } else if (
193
- oldDom &&
194
- oldVNode._dom == oldDom &&
195
- oldDom.parentNode != parentDom
196
- ) {
197
- // The above condition is to handle null placeholders. See test in placeholder.test.js:
198
- // `efficiently replace null placeholders in parent rerenders`
199
- oldDom = getDomSibling(oldVNode);
200
- }
201
- }
202
-
203
- newParentVNode._dom = firstChildDom;
204
-
205
- // Remove remaining oldChildren if there are any.
206
- for (i = oldChildrenLength; i--; ) {
207
- if (oldChildren[i] != null) {
208
- if (
209
- typeof newParentVNode.type == 'function' &&
210
- oldChildren[i]._dom != null &&
211
- oldChildren[i]._dom == newParentVNode._nextDom
212
- ) {
213
- // If the newParentVNode.__nextDom points to a dom node that is about to
214
- // be unmounted, then get the next sibling of that vnode and set
215
- // _nextDom to it
216
- newParentVNode._nextDom = getDomSibling(oldParentVNode, i + 1);
217
- }
218
-
219
- unmount(oldChildren[i], oldChildren[i]);
220
- }
221
- }
222
-
223
- // Set refs only after unmount
224
- if (refs) {
225
- for (i = 0; i < refs.length; i++) {
226
- applyRef(refs[i], refs[++i], refs[++i]);
227
- }
228
- }
229
- }
230
-
231
- function reorderChildren(childVNode, oldDom, parentDom) {
232
- // Note: VNodes in nested suspended trees may be missing _children.
233
- let c = childVNode._children;
234
- let tmp = 0;
235
- for (; c && tmp < c.length; tmp++) {
236
- let vnode = c[tmp];
237
- if (vnode) {
238
- // We typically enter this code path on sCU bailout, where we copy
239
- // oldVNode._children to newVNode._children. If that is the case, we need
240
- // to update the old children's _parent pointer to point to the newVNode
241
- // (childVNode here).
242
- vnode._parent = childVNode;
243
-
244
- if (typeof vnode.type == 'function') {
245
- oldDom = reorderChildren(vnode, oldDom, parentDom);
246
- } else {
247
- oldDom = placeChild(
248
- parentDom,
249
- vnode,
250
- vnode,
251
- c,
252
- vnode._dom,
253
- oldDom
254
- );
255
- }
256
- }
257
- }
258
-
259
- return oldDom;
260
- }
261
-
262
- /**
263
- * Flatten and loop through the children of a virtual node
264
- * @param {import('../index').ComponentChildren} children The unflattened
265
- * children of a virtual node
266
- * @returns {import('../internal').VNode[]}
267
- */
268
- export function toChildArray(children, out) {
269
- out = out || [];
270
- if (children == null || typeof children == 'boolean') {
271
- } else if (Array.isArray(children)) {
272
- children.some(child => {
273
- toChildArray(child, out);
274
- });
275
- } else {
276
- out.push(children);
277
- }
278
- return out;
279
- }
280
-
281
- function placeChild(
282
- parentDom,
283
- childVNode,
284
- oldVNode,
285
- oldChildren,
286
- newDom,
287
- oldDom
288
- ) {
289
- let nextDom;
290
- if (childVNode._nextDom !== undefined) {
291
- // Only Fragments or components that return Fragment like VNodes will
292
- // have a non-undefined _nextDom. Continue the diff from the sibling
293
- // of last DOM child of this child VNode
294
- nextDom = childVNode._nextDom;
295
-
296
- // Eagerly cleanup _nextDom. We don't need to persist the value because
297
- // it is only used by `diffChildren` to determine where to resume the diff after
298
- // diffing Components and Fragments. Once we store it the nextDOM local var, we
299
- // can clean up the property
300
- childVNode._nextDom = undefined;
301
- } else if (
302
- oldVNode == null ||
303
- newDom != oldDom ||
304
- newDom.parentNode == null
305
- ) {
306
- outer: if (oldDom == null || oldDom.parentNode !== parentDom) {
307
- parentDom.appendChild(newDom);
308
- nextDom = null;
309
- } else {
310
- // `j<oldChildrenLength; j+=2` is an alternative to `j++<oldChildrenLength/2`
311
- for (
312
- let sibDom = oldDom, j = 0;
313
- (sibDom = sibDom.nextSibling) && j < oldChildren.length;
314
- j += 2
315
- ) {
316
- if (sibDom == newDom) {
317
- break outer;
318
- }
319
- }
320
- parentDom.insertBefore(newDom, oldDom);
321
- nextDom = oldDom;
322
- }
323
- }
324
-
325
- // If we have pre-calculated the nextDOM node, use it. Else calculate it now
326
- // Strictly check for `undefined` here cuz `null` is a valid value of `nextDom`.
327
- // See more detail in create-element.js:createVNode
328
- if (nextDom !== undefined) {
329
- oldDom = nextDom;
330
- } else {
331
- oldDom = newDom.nextSibling;
332
- }
333
-
334
- return oldDom;
335
- }
1
+ import { diff, unmount, applyRef } from './index';
2
+ import { createVNode, Fragment } from '../create-element';
3
+ import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
4
+ import { getDomSibling } from '../component';
5
+
6
+ /**
7
+ * Diff the children of a virtual node
8
+ * @param {import('../internal').PreactElement} parentDom The DOM element whose
9
+ * children are being diffed
10
+ * @param {import('../internal').ComponentChildren[]} renderResult
11
+ * @param {import('../internal').VNode} newParentVNode The new virtual
12
+ * node whose children should be diff'ed against oldParentVNode
13
+ * @param {import('../internal').VNode} oldParentVNode The old virtual
14
+ * node whose children should be diff'ed against newParentVNode
15
+ * @param {object} globalContext The current context object - modified by getChildContext
16
+ * @param {boolean} isSvg Whether or not this DOM node is an SVG node
17
+ * @param {Array<import('../internal').PreactElement>} excessDomChildren
18
+ * @param {Array<import('../internal').Component>} commitQueue List of components
19
+ * which have callbacks to invoke in commitRoot
20
+ * @param {import('../internal').PreactElement} oldDom The current attached DOM
21
+ * element any new dom elements should be placed around. Likely `null` on first
22
+ * render (except when hydrating). Can be a sibling DOM element when diffing
23
+ * Fragments that have siblings. In most cases, it starts out as `oldChildren[0]._dom`.
24
+ * @param {boolean} isHydrating Whether or not we are in hydration
25
+ */
26
+ export function diffChildren(
27
+ parentDom,
28
+ renderResult,
29
+ newParentVNode,
30
+ oldParentVNode,
31
+ globalContext,
32
+ isSvg,
33
+ excessDomChildren,
34
+ commitQueue,
35
+ oldDom,
36
+ isHydrating
37
+ ) {
38
+ let i, j, oldVNode, childVNode, newDom, firstChildDom, refs;
39
+
40
+ // This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
41
+ // as EMPTY_OBJ._children should be `undefined`.
42
+ let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;
43
+
44
+ let oldChildrenLength = oldChildren.length;
45
+
46
+ newParentVNode._children = [];
47
+ for (i = 0; i < renderResult.length; i++) {
48
+ childVNode = renderResult[i];
49
+
50
+ if (childVNode == null || typeof childVNode == 'boolean') {
51
+ childVNode = newParentVNode._children[i] = null;
52
+ }
53
+ // If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
54
+ // or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
55
+ // it's own DOM & etc. pointers
56
+ else if (
57
+ typeof childVNode == 'string' ||
58
+ typeof childVNode == 'number' ||
59
+ // eslint-disable-next-line valid-typeof
60
+ typeof childVNode == 'bigint'
61
+ ) {
62
+ childVNode = newParentVNode._children[i] = createVNode(
63
+ null,
64
+ childVNode,
65
+ null,
66
+ null,
67
+ childVNode
68
+ );
69
+ } else if (Array.isArray(childVNode)) {
70
+ childVNode = newParentVNode._children[i] = createVNode(
71
+ Fragment,
72
+ { children: childVNode },
73
+ null,
74
+ null,
75
+ null
76
+ );
77
+ } else if (childVNode._depth > 0) {
78
+ // VNode is already in use, clone it. This can happen in the following
79
+ // scenario:
80
+ // const reuse = <div />
81
+ // <div>{reuse}<span />{reuse}</div>
82
+ childVNode = newParentVNode._children[i] = createVNode(
83
+ childVNode.type,
84
+ childVNode.props,
85
+ childVNode.key,
86
+ null,
87
+ childVNode._original
88
+ );
89
+ } else {
90
+ childVNode = newParentVNode._children[i] = childVNode;
91
+ }
92
+
93
+ // Terser removes the `continue` here and wraps the loop body
94
+ // in a `if (childVNode) { ... } condition
95
+ if (childVNode == null) {
96
+ continue;
97
+ }
98
+
99
+ childVNode._parent = newParentVNode;
100
+ childVNode._depth = newParentVNode._depth + 1;
101
+
102
+ // Check if we find a corresponding element in oldChildren.
103
+ // If found, delete the array item by setting to `undefined`.
104
+ // We use `undefined`, as `null` is reserved for empty placeholders
105
+ // (holes).
106
+ oldVNode = oldChildren[i];
107
+
108
+ if (
109
+ oldVNode === null ||
110
+ (oldVNode &&
111
+ childVNode.key == oldVNode.key &&
112
+ childVNode.type === oldVNode.type)
113
+ ) {
114
+ oldChildren[i] = undefined;
115
+ } else {
116
+ // Either oldVNode === undefined or oldChildrenLength > 0,
117
+ // so after this loop oldVNode == null or oldVNode is a valid value.
118
+ for (j = 0; j < oldChildrenLength; j++) {
119
+ oldVNode = oldChildren[j];
120
+ // If childVNode is unkeyed, we only match similarly unkeyed nodes, otherwise we match by key.
121
+ // We always match by type (in either case).
122
+ if (
123
+ oldVNode &&
124
+ childVNode.key == oldVNode.key &&
125
+ childVNode.type === oldVNode.type
126
+ ) {
127
+ oldChildren[j] = undefined;
128
+ break;
129
+ }
130
+ oldVNode = null;
131
+ }
132
+ }
133
+
134
+ oldVNode = oldVNode || EMPTY_OBJ;
135
+
136
+ // Morph the old element into the new one, but don't append it to the dom yet
137
+ diff(
138
+ parentDom,
139
+ childVNode,
140
+ oldVNode,
141
+ globalContext,
142
+ isSvg,
143
+ excessDomChildren,
144
+ commitQueue,
145
+ oldDom,
146
+ isHydrating
147
+ );
148
+
149
+ newDom = childVNode._dom;
150
+
151
+ if ((j = childVNode.ref) && oldVNode.ref != j) {
152
+ if (!refs) refs = [];
153
+ if (oldVNode.ref) refs.push(oldVNode.ref, null, childVNode);
154
+ refs.push(j, childVNode._component || newDom, childVNode);
155
+ }
156
+
157
+ if (newDom != null) {
158
+ if (firstChildDom == null) {
159
+ firstChildDom = newDom;
160
+ }
161
+
162
+ if (
163
+ typeof childVNode.type == 'function' &&
164
+ childVNode._children === oldVNode._children
165
+ ) {
166
+ childVNode._nextDom = oldDom = reorderChildren(
167
+ childVNode,
168
+ oldDom,
169
+ parentDom
170
+ );
171
+ } else {
172
+ oldDom = placeChild(
173
+ parentDom,
174
+ childVNode,
175
+ oldVNode,
176
+ oldChildren,
177
+ newDom,
178
+ oldDom
179
+ );
180
+ }
181
+
182
+ if (typeof newParentVNode.type == 'function') {
183
+ // Because the newParentVNode is Fragment-like, we need to set it's
184
+ // _nextDom property to the nextSibling of its last child DOM node.
185
+ //
186
+ // `oldDom` contains the correct value here because if the last child
187
+ // is a Fragment-like, then oldDom has already been set to that child's _nextDom.
188
+ // If the last child is a DOM VNode, then oldDom will be set to that DOM
189
+ // node's nextSibling.
190
+ newParentVNode._nextDom = oldDom;
191
+ }
192
+ } else if (
193
+ oldDom &&
194
+ oldVNode._dom == oldDom &&
195
+ oldDom.parentNode != parentDom
196
+ ) {
197
+ // The above condition is to handle null placeholders. See test in placeholder.test.js:
198
+ // `efficiently replace null placeholders in parent rerenders`
199
+ oldDom = getDomSibling(oldVNode);
200
+ }
201
+ }
202
+
203
+ newParentVNode._dom = firstChildDom;
204
+
205
+ // Remove remaining oldChildren if there are any.
206
+ for (i = oldChildrenLength; i--; ) {
207
+ if (oldChildren[i] != null) {
208
+ if (
209
+ typeof newParentVNode.type == 'function' &&
210
+ oldChildren[i]._dom != null &&
211
+ oldChildren[i]._dom == newParentVNode._nextDom
212
+ ) {
213
+ // If the newParentVNode.__nextDom points to a dom node that is about to
214
+ // be unmounted, then get the next sibling of that vnode and set
215
+ // _nextDom to it
216
+ newParentVNode._nextDom = getDomSibling(oldParentVNode, i + 1);
217
+ }
218
+
219
+ unmount(oldChildren[i], oldChildren[i]);
220
+ }
221
+ }
222
+
223
+ // Set refs only after unmount
224
+ if (refs) {
225
+ for (i = 0; i < refs.length; i++) {
226
+ applyRef(refs[i], refs[++i], refs[++i]);
227
+ }
228
+ }
229
+ }
230
+
231
+ function reorderChildren(childVNode, oldDom, parentDom) {
232
+ // Note: VNodes in nested suspended trees may be missing _children.
233
+ let c = childVNode._children;
234
+ let tmp = 0;
235
+ for (; c && tmp < c.length; tmp++) {
236
+ let vnode = c[tmp];
237
+ if (vnode) {
238
+ // We typically enter this code path on sCU bailout, where we copy
239
+ // oldVNode._children to newVNode._children. If that is the case, we need
240
+ // to update the old children's _parent pointer to point to the newVNode
241
+ // (childVNode here).
242
+ vnode._parent = childVNode;
243
+
244
+ if (typeof vnode.type == 'function') {
245
+ oldDom = reorderChildren(vnode, oldDom, parentDom);
246
+ } else {
247
+ oldDom = placeChild(
248
+ parentDom,
249
+ vnode,
250
+ vnode,
251
+ c,
252
+ vnode._dom,
253
+ oldDom
254
+ );
255
+ }
256
+ }
257
+ }
258
+
259
+ return oldDom;
260
+ }
261
+
262
+ /**
263
+ * Flatten and loop through the children of a virtual node
264
+ * @param {import('../index').ComponentChildren} children The unflattened
265
+ * children of a virtual node
266
+ * @returns {import('../internal').VNode[]}
267
+ */
268
+ export function toChildArray(children, out) {
269
+ out = out || [];
270
+ if (children == null || typeof children == 'boolean') {
271
+ } else if (Array.isArray(children)) {
272
+ children.some(child => {
273
+ toChildArray(child, out);
274
+ });
275
+ } else {
276
+ out.push(children);
277
+ }
278
+ return out;
279
+ }
280
+
281
+ function placeChild(
282
+ parentDom,
283
+ childVNode,
284
+ oldVNode,
285
+ oldChildren,
286
+ newDom,
287
+ oldDom
288
+ ) {
289
+ let nextDom;
290
+ if (childVNode._nextDom !== undefined) {
291
+ // Only Fragments or components that return Fragment like VNodes will
292
+ // have a non-undefined _nextDom. Continue the diff from the sibling
293
+ // of last DOM child of this child VNode
294
+ nextDom = childVNode._nextDom;
295
+
296
+ // Eagerly cleanup _nextDom. We don't need to persist the value because
297
+ // it is only used by `diffChildren` to determine where to resume the diff after
298
+ // diffing Components and Fragments. Once we store it the nextDOM local var, we
299
+ // can clean up the property
300
+ childVNode._nextDom = undefined;
301
+ } else if (
302
+ oldVNode == null ||
303
+ newDom != oldDom ||
304
+ newDom.parentNode == null
305
+ ) {
306
+ outer: if (oldDom == null || oldDom.parentNode !== parentDom) {
307
+ parentDom.appendChild(newDom);
308
+ nextDom = null;
309
+ } else {
310
+ // `j<oldChildrenLength; j+=2` is an alternative to `j++<oldChildrenLength/2`
311
+ for (
312
+ let sibDom = oldDom, j = 0;
313
+ (sibDom = sibDom.nextSibling) && j < oldChildren.length;
314
+ j += 2
315
+ ) {
316
+ if (sibDom == newDom) {
317
+ break outer;
318
+ }
319
+ }
320
+ parentDom.insertBefore(newDom, oldDom);
321
+ nextDom = oldDom;
322
+ }
323
+ }
324
+
325
+ // If we have pre-calculated the nextDOM node, use it. Else calculate it now
326
+ // Strictly check for `undefined` here cuz `null` is a valid value of `nextDom`.
327
+ // See more detail in create-element.js:createVNode
328
+ if (nextDom !== undefined) {
329
+ oldDom = nextDom;
330
+ } else {
331
+ oldDom = newDom.nextSibling;
332
+ }
333
+
334
+ return oldDom;
335
+ }