@reckona/mreact-compat 0.0.164 → 0.0.165
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dom-children.d.ts +1 -0
- package/dist/dom-children.d.ts.map +1 -1
- package/dist/dom-children.js +10 -1
- package/dist/dom-children.js.map +1 -1
- package/dist/dom-host-rules.d.ts +15 -1
- package/dist/dom-host-rules.d.ts.map +1 -1
- package/dist/dom-host-rules.js +17 -1
- package/dist/dom-host-rules.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +20 -2
- package/dist/events.js.map +1 -1
- package/dist/fiber-commit.d.ts.map +1 -1
- package/dist/fiber-commit.js +51 -31
- package/dist/fiber-commit.js.map +1 -1
- package/dist/hooks.d.ts +2 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +57 -15
- package/dist/hooks.js.map +1 -1
- package/dist/host-reconciler.d.ts +2 -2
- package/dist/host-reconciler.d.ts.map +1 -1
- package/dist/host-reconciler.js +193 -29
- package/dist/host-reconciler.js.map +1 -1
- package/dist/root.js +3 -2
- package/dist/root.js.map +1 -1
- package/package.json +3 -3
- package/src/dom-children.ts +16 -1
- package/src/dom-host-rules.ts +42 -3
- package/src/events.ts +27 -2
- package/src/fiber-commit.ts +61 -37
- package/src/hooks.ts +61 -16
- package/src/host-reconciler.ts +264 -35
- package/src/root.ts +3 -2
package/dist/host-reconciler.js
CHANGED
|
@@ -3,8 +3,8 @@ import { consumerContext, isReactCompatConsumer, isReactCompatProvider, renderWi
|
|
|
3
3
|
import { applyPostChildFormProps, applyProps } from "./dom-props.js";
|
|
4
4
|
import { syncChildNodes, syncOwnedChildNodes, syncScopedChildNodes } from "./dom-children.js";
|
|
5
5
|
import { setLogicalEventParent } from "./host-event-binder.js";
|
|
6
|
-
import { NoFlags, Placement, Update } from "./fiber-flags.js";
|
|
7
|
-
import { createHostElement, hostElementMatches, isHostElement, namespaceForHostChildren, namespaceForHostElement, } from "./dom-host-rules.js";
|
|
6
|
+
import { ChildDeletion, NoFlags, Placement, Update } from "./fiber-flags.js";
|
|
7
|
+
import { createHostElement, hostElementMatches, isDomHostElement, isHostElement, namespaceForHostChildren, namespaceForHostElement, } from "./dom-host-rules.js";
|
|
8
8
|
import { createFiber, createWorkInProgress } from "./fiber.js";
|
|
9
9
|
import { renderWithRootRuntime, renderWithProfiler, renderWithStrictModeMemoCapture, renderStrictModeReplay, runWithHostCommit, restoreRuntimeSnapshot, takeRuntimeSnapshot, getDevToolsHookState, collectRuntimeInstanceKeys, hasContextDependency, hasChangedContextDependency, subscribeReactiveTextBinding, } from "./hooks.js";
|
|
10
10
|
import { isThenable } from "./thenable.js";
|
|
@@ -12,6 +12,7 @@ import { hasDirtyClassUpdate, isClassComponentType, recoverClassComponentError,
|
|
|
12
12
|
import { areMemoPropsEqual, getPendingProps, shallowEqual } from "./prop-comparison.js";
|
|
13
13
|
import { reportElementTextMismatch, reportExtraHydrationNodes, reportHydrationNodeTypeMismatch, reportMissingHydrationNode, reportReactSuspenseServerError, reportRecoverable, withHydrationComponentStack, } from "./hydration.js";
|
|
14
14
|
const committedPortalContainers = new Set();
|
|
15
|
+
const pendingHostRefUpdates = [];
|
|
15
16
|
const SKIP_COMMIT_PATH = "\0";
|
|
16
17
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
17
18
|
let suspensePrimaryRenderDepth = 0;
|
|
@@ -93,35 +94,55 @@ export function renderHydratingHostFiberRoot(root, element, runtime, scope, opti
|
|
|
93
94
|
}
|
|
94
95
|
export function commitHostFiberRoot(root, finishedWork, options = {}) {
|
|
95
96
|
runWithHostCommit(() => {
|
|
97
|
+
let committed = false;
|
|
96
98
|
try {
|
|
97
99
|
committedPortalContainers.clear();
|
|
100
|
+
pendingHostRefUpdates.length = 0;
|
|
98
101
|
const commitPath = getRootCommitPath(options);
|
|
99
102
|
if (!hasChildListMutation(finishedWork)) {
|
|
100
103
|
commitHostDirtyChildren(finishedWork.child, root.container, root.container, commitPath, options);
|
|
104
|
+
committed = true;
|
|
101
105
|
return;
|
|
102
106
|
}
|
|
103
107
|
if (!finishedWork.childListChanged &&
|
|
104
108
|
finishedWork.subtreeChildListChanged &&
|
|
105
109
|
commitHostKeyedChildListMutation(finishedWork.child, root.container, root.container, commitPath, options)) {
|
|
110
|
+
committed = true;
|
|
106
111
|
return;
|
|
107
112
|
}
|
|
108
113
|
const nodes = commitHostChildren(finishedWork.child, root.container, root.container, commitPath, options);
|
|
109
114
|
syncChildNodes(root.container, nodes);
|
|
115
|
+
committed = true;
|
|
110
116
|
}
|
|
111
117
|
finally {
|
|
118
|
+
if (committed) {
|
|
119
|
+
flushPendingHostRefUpdates();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
pendingHostRefUpdates.length = 0;
|
|
123
|
+
}
|
|
112
124
|
committedPortalContainers.clear();
|
|
113
125
|
}
|
|
114
126
|
});
|
|
115
127
|
}
|
|
116
128
|
export function commitHydratingHostFiberRoot(root, finishedWork, scope, options = {}) {
|
|
117
129
|
runWithHostCommit(() => {
|
|
130
|
+
let committed = false;
|
|
118
131
|
try {
|
|
119
132
|
committedPortalContainers.clear();
|
|
133
|
+
pendingHostRefUpdates.length = 0;
|
|
120
134
|
const eventRoot = root.container;
|
|
121
135
|
const nodes = commitHostChildren(finishedWork.child, scope.parent, eventRoot, "", options);
|
|
122
136
|
syncScopedChildNodes(scope.parent, scope.before, scope.after, nodes);
|
|
137
|
+
committed = true;
|
|
123
138
|
}
|
|
124
139
|
finally {
|
|
140
|
+
if (committed) {
|
|
141
|
+
flushPendingHostRefUpdates();
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
pendingHostRefUpdates.length = 0;
|
|
145
|
+
}
|
|
125
146
|
committedPortalContainers.clear();
|
|
126
147
|
}
|
|
127
148
|
});
|
|
@@ -137,6 +158,9 @@ function reconcileHostChild(parent, currentFirstChild, node, runtime, path, opti
|
|
|
137
158
|
parent.subtreeChildListChanged = false;
|
|
138
159
|
if (node === null || node === undefined || typeof node === "boolean") {
|
|
139
160
|
parent.childListChanged = currentFirstChild !== undefined;
|
|
161
|
+
if (currentFirstChild !== undefined) {
|
|
162
|
+
markOptimizedChildrenForDeletion(parent, currentFirstChild);
|
|
163
|
+
}
|
|
140
164
|
return { fiber: undefined, consumed: 0 };
|
|
141
165
|
}
|
|
142
166
|
const children = Array.isArray(node) ? node : undefined;
|
|
@@ -155,6 +179,7 @@ function reconcileHostChild(parent, currentFirstChild, node, runtime, path, opti
|
|
|
155
179
|
let previous;
|
|
156
180
|
let consumed = 0;
|
|
157
181
|
let skipRemainingKeyedLookup = false;
|
|
182
|
+
const usedCurrentChildren = currentFirstChild === undefined ? undefined : new Set();
|
|
158
183
|
for (let index = 0; index < childCount; index += 1) {
|
|
159
184
|
const child = children === undefined ? node : children[index];
|
|
160
185
|
const key = getNodeKey(child);
|
|
@@ -196,8 +221,18 @@ function reconcileHostChild(parent, currentFirstChild, node, runtime, path, opti
|
|
|
196
221
|
const result = createHostFiber(parent, matchedCurrent, child, key, runtime, getReconcileChildPath(path, child, index, options), previousNodes === undefined ? options : { ...options, previousNodes });
|
|
197
222
|
const fiber = result.fiber;
|
|
198
223
|
if (fiber === undefined) {
|
|
224
|
+
if (matchedCurrent !== undefined) {
|
|
225
|
+
usedCurrentChildren?.add(matchedCurrent);
|
|
226
|
+
markOptimizedChildForDeletion(parent, matchedCurrent);
|
|
227
|
+
}
|
|
199
228
|
continue;
|
|
200
229
|
}
|
|
230
|
+
if (matchedCurrent !== undefined) {
|
|
231
|
+
usedCurrentChildren?.add(matchedCurrent);
|
|
232
|
+
if (fiber !== matchedCurrent && fiber.alternate !== matchedCurrent) {
|
|
233
|
+
markOptimizedChildForDeletion(parent, matchedCurrent);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
201
236
|
if (key === undefined) {
|
|
202
237
|
currentUnkeyed = currentUnkeyed?.sibling;
|
|
203
238
|
}
|
|
@@ -222,6 +257,7 @@ function reconcileHostChild(parent, currentFirstChild, node, runtime, path, opti
|
|
|
222
257
|
}
|
|
223
258
|
previous = fiber;
|
|
224
259
|
}
|
|
260
|
+
markUnusedCurrentChildrenForDeletion(parent, currentFirstChild, usedCurrentChildren);
|
|
225
261
|
parent.childListChanged = childFiberListShapeChanged(currentFirstChild, first);
|
|
226
262
|
return { fiber: first, consumed };
|
|
227
263
|
}
|
|
@@ -240,6 +276,7 @@ function reconcileKeyedRowHostChildren(parent, currentFirstChild, children, opti
|
|
|
240
276
|
let subtreeFlags = NoFlags;
|
|
241
277
|
let subtreeChildListChanged = false;
|
|
242
278
|
let hasRefSubtree = false;
|
|
279
|
+
let appendSuffix;
|
|
243
280
|
const canReuseUnchangedRows = hasSameKeyOrderPrefix(currentFirstChild, children);
|
|
244
281
|
const row = createKeyedRowHostElementScratch();
|
|
245
282
|
for (let index = 0; index < children.length; index += 1) {
|
|
@@ -248,12 +285,14 @@ function reconcileKeyedRowHostChildren(parent, currentFirstChild, children, opti
|
|
|
248
285
|
return undefined;
|
|
249
286
|
}
|
|
250
287
|
let matchedCurrent;
|
|
288
|
+
let matchedByAppendSuffix = false;
|
|
251
289
|
if (skipRemainingKeyedLookup) {
|
|
252
290
|
matchedCurrent = undefined;
|
|
253
291
|
}
|
|
254
292
|
else if (currentKeyed === undefined) {
|
|
255
293
|
listShapeChanged = true;
|
|
256
294
|
skipRemainingKeyedLookup = true;
|
|
295
|
+
matchedByAppendSuffix = true;
|
|
257
296
|
matchedCurrent = undefined;
|
|
258
297
|
}
|
|
259
298
|
else if (currentKeyed?.key === row.key) {
|
|
@@ -262,12 +301,16 @@ function reconcileKeyedRowHostChildren(parent, currentFirstChild, children, opti
|
|
|
262
301
|
}
|
|
263
302
|
else if (currentKeyed?.sibling?.key === row.key &&
|
|
264
303
|
canSkipSingleDeletedKeyedFiber(children, index, currentKeyed.sibling)) {
|
|
304
|
+
const deleted = currentKeyed;
|
|
305
|
+
const matched = currentKeyed.sibling;
|
|
265
306
|
listShapeChanged = true;
|
|
266
|
-
|
|
267
|
-
|
|
307
|
+
markOptimizedChildForDeletion(parent, deleted);
|
|
308
|
+
matchedCurrent = matched;
|
|
309
|
+
currentKeyed = matched.sibling;
|
|
268
310
|
}
|
|
269
311
|
else if (canSkipRemainingKeyedLookup(currentKeyed, children, index)) {
|
|
270
312
|
listShapeChanged = true;
|
|
313
|
+
markOptimizedChildrenForDeletion(parent, currentKeyed);
|
|
271
314
|
skipRemainingKeyedLookup = true;
|
|
272
315
|
currentKeyed = undefined;
|
|
273
316
|
matchedCurrent = undefined;
|
|
@@ -279,6 +322,9 @@ function reconcileKeyedRowHostChildren(parent, currentFirstChild, children, opti
|
|
|
279
322
|
? createKeyedRowHostFiber(parent, undefined, row, options)
|
|
280
323
|
: (canReuseUnchangedRows ? getReusableKeyedRowHostFiber(matchedCurrent, row) : undefined) ??
|
|
281
324
|
createKeyedRowHostFiber(parent, matchedCurrent, row, options);
|
|
325
|
+
if (matchedByAppendSuffix && appendSuffix === undefined) {
|
|
326
|
+
appendSuffix = { fiber, index };
|
|
327
|
+
}
|
|
282
328
|
if (first === undefined) {
|
|
283
329
|
first = fiber;
|
|
284
330
|
}
|
|
@@ -302,13 +348,41 @@ function reconcileKeyedRowHostChildren(parent, currentFirstChild, children, opti
|
|
|
302
348
|
}
|
|
303
349
|
if (currentKeyed !== undefined) {
|
|
304
350
|
listShapeChanged = true;
|
|
351
|
+
markOptimizedChildrenForDeletion(parent, currentKeyed);
|
|
305
352
|
}
|
|
306
353
|
parent.hasRefSubtree = hasRefSubtree;
|
|
307
354
|
parent.subtreeFlags = subtreeFlags;
|
|
308
355
|
parent.subtreeChildListChanged = subtreeChildListChanged;
|
|
309
356
|
parent.childListChanged = listShapeChanged;
|
|
357
|
+
if (appendSuffix !== undefined && canStoreAppendSuffixCommitHint(parent)) {
|
|
358
|
+
parent.memoizedState = appendSuffix;
|
|
359
|
+
}
|
|
310
360
|
return { fiber: first, consumed: 0 };
|
|
311
361
|
}
|
|
362
|
+
function canStoreAppendSuffixCommitHint(parent) {
|
|
363
|
+
return (parent.tag === "fragment" ||
|
|
364
|
+
parent.tag === "host-component" ||
|
|
365
|
+
parent.tag === "host-root");
|
|
366
|
+
}
|
|
367
|
+
function markOptimizedChildForDeletion(parent, _child) {
|
|
368
|
+
parent.flags |= ChildDeletion;
|
|
369
|
+
}
|
|
370
|
+
function markOptimizedChildrenForDeletion(parent, _firstChild) {
|
|
371
|
+
parent.flags |= ChildDeletion;
|
|
372
|
+
}
|
|
373
|
+
function markUnusedCurrentChildrenForDeletion(parent, firstChild, used) {
|
|
374
|
+
if (firstChild === undefined || used === undefined) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
let cursor = firstChild;
|
|
378
|
+
while (cursor !== undefined) {
|
|
379
|
+
if (!used.has(cursor)) {
|
|
380
|
+
parent.flags |= ChildDeletion;
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
cursor = cursor.sibling;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
312
386
|
function hasSameKeyOrderPrefix(currentFirstChild, children) {
|
|
313
387
|
let current = currentFirstChild;
|
|
314
388
|
for (let index = 0; index < children.length; index += 1) {
|
|
@@ -579,7 +653,7 @@ function createHostFiberImpl(parent, current, node, key, runtime, path, options
|
|
|
579
653
|
? existing
|
|
580
654
|
: current?.tag === "host-text" && current.stateNode instanceof Text
|
|
581
655
|
? current.stateNode
|
|
582
|
-
: getDocumentRef(options)
|
|
656
|
+
: createHostTextNode(getDocumentRef(options));
|
|
583
657
|
if (existing instanceof Text && existing.data !== String(node)) {
|
|
584
658
|
reportRecoverable(options, "text", path, new Error("Hydration text mismatch."));
|
|
585
659
|
}
|
|
@@ -1005,13 +1079,12 @@ function commitHostDirtyFiber(fiber, parent, eventRoot, path, options = {}) {
|
|
|
1005
1079
|
!propsAreChildrenOnly &&
|
|
1006
1080
|
fiber.hydrateExisting !== true &&
|
|
1007
1081
|
isRowTextOnlyUpdate(fiber.memoizedProps, props);
|
|
1008
|
-
if (!propsAreUnchanged && !propsAreChildrenOnly && !textOnlyRowUpdate) {
|
|
1082
|
+
if (isDomHostElement(element) && !propsAreUnchanged && !propsAreChildrenOnly && !textOnlyRowUpdate) {
|
|
1009
1083
|
applyProps(element, props, path, {
|
|
1010
1084
|
...options,
|
|
1011
1085
|
eventRoot,
|
|
1012
1086
|
preserveHydrationAttributes: fiber.hydrateExisting,
|
|
1013
1087
|
});
|
|
1014
|
-
applyChangedRef(previousProps?.ref, props.ref, element);
|
|
1015
1088
|
}
|
|
1016
1089
|
if (directTextChild !== undefined) {
|
|
1017
1090
|
const text = syncDirectHostTextChild(element, directTextChild);
|
|
@@ -1021,24 +1094,45 @@ function commitHostDirtyFiber(fiber, parent, eventRoot, path, options = {}) {
|
|
|
1021
1094
|
fiber.childListChanged ||
|
|
1022
1095
|
fiber.subtreeChildListChanged) {
|
|
1023
1096
|
const childNodes = commitHostChildren(fiber.child, element, eventRoot, `${path}.c`, options);
|
|
1024
|
-
if (!(childNodes.length === 0 && committedPortalContainers.has(element)) &&
|
|
1025
|
-
!shouldPreserveContentEditableChildren(element, props, childNodes)) {
|
|
1097
|
+
if (!(isDomHostElement(element) && childNodes.length === 0 && committedPortalContainers.has(element)) &&
|
|
1098
|
+
!(isDomHostElement(element) && shouldPreserveContentEditableChildren(element, props, childNodes))) {
|
|
1026
1099
|
syncChildNodes(element, childNodes);
|
|
1027
1100
|
}
|
|
1028
1101
|
}
|
|
1029
1102
|
else if (fiber.subtreeFlags !== NoFlags) {
|
|
1030
1103
|
commitHostDirtyChildren(fiber.child, element, eventRoot, `${path}.c`, options);
|
|
1031
1104
|
}
|
|
1032
|
-
|
|
1105
|
+
if (isDomHostElement(element)) {
|
|
1106
|
+
applyPostChildFormProps(element, props, previousProps);
|
|
1107
|
+
}
|
|
1108
|
+
applyChangedRef(previousProps?.ref, props.ref, element);
|
|
1033
1109
|
fiber.memoizedProps = props;
|
|
1034
1110
|
finishCommittedFiber(fiber);
|
|
1035
1111
|
return;
|
|
1036
1112
|
}
|
|
1037
1113
|
if (fiber.tag === "portal") {
|
|
1038
1114
|
const container = fiber.stateNode;
|
|
1039
|
-
if (container
|
|
1040
|
-
|
|
1041
|
-
|
|
1115
|
+
if (isPortalHostContainer(container)) {
|
|
1116
|
+
if (container instanceof Element) {
|
|
1117
|
+
setLogicalEventParent(container, parent);
|
|
1118
|
+
}
|
|
1119
|
+
const portalEventRoot = container instanceof Element && eventRoot !== container && eventRoot.contains(container)
|
|
1120
|
+
? eventRoot
|
|
1121
|
+
: container instanceof Element
|
|
1122
|
+
? container
|
|
1123
|
+
: eventRoot;
|
|
1124
|
+
const portalOptions = withPortalDocumentRef(options, container);
|
|
1125
|
+
if (fiber.childListChanged ||
|
|
1126
|
+
fiber.subtreeChildListChanged ||
|
|
1127
|
+
(fiber.subtreeFlags & Placement) !== NoFlags) {
|
|
1128
|
+
const childNodes = commitHostChildren(fiber.child, container, portalEventRoot, `${path}.portal`, portalOptions);
|
|
1129
|
+
const previousNodes = committedHostNodesFromState(fiber.alternate?.memoizedState);
|
|
1130
|
+
syncOwnedChildNodes(container, previousNodes, childNodes);
|
|
1131
|
+
fiber.memoizedState = childNodes;
|
|
1132
|
+
}
|
|
1133
|
+
else {
|
|
1134
|
+
commitHostDirtyChildren(fiber.child, container, portalEventRoot, `${path}.portal`, portalOptions);
|
|
1135
|
+
}
|
|
1042
1136
|
}
|
|
1043
1137
|
fiber.memoizedProps = fiber.pendingProps;
|
|
1044
1138
|
finishCommittedFiber(fiber);
|
|
@@ -1080,6 +1174,10 @@ function commitHostKeyedChildListMutation(fiber, parent, eventRoot, path, option
|
|
|
1080
1174
|
return committed;
|
|
1081
1175
|
}
|
|
1082
1176
|
function commitHostKeyedChildListMutationFiber(fiber, parent, eventRoot, path, options = {}) {
|
|
1177
|
+
if (fiber.tag === "portal") {
|
|
1178
|
+
commitHostDirtyFiber(fiber, parent, eventRoot, path, options);
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1083
1181
|
if (fiber.childListChanged) {
|
|
1084
1182
|
const mutationParent = fiber.tag === "host-component" && isHostElement(fiber.stateNode)
|
|
1085
1183
|
? fiber.stateNode
|
|
@@ -1119,10 +1217,14 @@ function commitHostKeyedChildListMutationFiber(fiber, parent, eventRoot, path, o
|
|
|
1119
1217
|
return true;
|
|
1120
1218
|
}
|
|
1121
1219
|
function commitHostAppendSuffix(fiber, parent, eventRoot, path, options) {
|
|
1122
|
-
const
|
|
1220
|
+
const appendHint = readAppendSuffixCommitHint(fiber.memoizedState);
|
|
1221
|
+
const append = appendHint ?? getAppendSuffix(fiber.alternate?.child, fiber.child);
|
|
1123
1222
|
if (append === undefined) {
|
|
1124
1223
|
return false;
|
|
1125
1224
|
}
|
|
1225
|
+
if (appendHint !== undefined) {
|
|
1226
|
+
fiber.memoizedState = undefined;
|
|
1227
|
+
}
|
|
1126
1228
|
let cursor = append.fiber;
|
|
1127
1229
|
let index = append.index;
|
|
1128
1230
|
while (cursor !== undefined) {
|
|
@@ -1134,6 +1236,15 @@ function commitHostAppendSuffix(fiber, parent, eventRoot, path, options) {
|
|
|
1134
1236
|
}
|
|
1135
1237
|
return true;
|
|
1136
1238
|
}
|
|
1239
|
+
function readAppendSuffixCommitHint(value) {
|
|
1240
|
+
if (typeof value !== "object" || value === null) {
|
|
1241
|
+
return undefined;
|
|
1242
|
+
}
|
|
1243
|
+
const candidate = value;
|
|
1244
|
+
return candidate.fiber !== undefined && typeof candidate.index === "number"
|
|
1245
|
+
? { fiber: candidate.fiber, index: candidate.index }
|
|
1246
|
+
: undefined;
|
|
1247
|
+
}
|
|
1137
1248
|
function commitHostSingleRemoval(fiber, parent) {
|
|
1138
1249
|
const removed = getSingleRemovedFiber(fiber.alternate?.child, fiber.child);
|
|
1139
1250
|
if (removed === undefined) {
|
|
@@ -1276,13 +1387,12 @@ function commitHostFiber(fiber, parent, eventRoot, path, options = {}) {
|
|
|
1276
1387
|
!propsAreChildrenOnly &&
|
|
1277
1388
|
fiber.hydrateExisting !== true &&
|
|
1278
1389
|
isRowTextOnlyUpdate(fiber.memoizedProps, props);
|
|
1279
|
-
if (!propsAreUnchanged && !propsAreChildrenOnly && !textOnlyRowUpdate) {
|
|
1390
|
+
if (isDomHostElement(element) && !propsAreUnchanged && !propsAreChildrenOnly && !textOnlyRowUpdate) {
|
|
1280
1391
|
applyProps(element, props, path, {
|
|
1281
1392
|
...options,
|
|
1282
1393
|
eventRoot,
|
|
1283
1394
|
preserveHydrationAttributes: fiber.hydrateExisting,
|
|
1284
1395
|
});
|
|
1285
|
-
applyChangedRef(previousProps?.ref, props.ref, element);
|
|
1286
1396
|
}
|
|
1287
1397
|
if (directTextChild !== undefined) {
|
|
1288
1398
|
const text = syncDirectHostTextChild(element, directTextChild);
|
|
@@ -1294,15 +1404,18 @@ function commitHostFiber(fiber, parent, eventRoot, path, options = {}) {
|
|
|
1294
1404
|
fiber.hydrateExisting === true ||
|
|
1295
1405
|
(fiber.subtreeFlags & Placement) !== NoFlags) {
|
|
1296
1406
|
const childNodes = commitHostChildren(fiber.child, element, eventRoot, `${path}.c`, options);
|
|
1297
|
-
if (!(childNodes.length === 0 && committedPortalContainers.has(element)) &&
|
|
1298
|
-
!shouldPreserveContentEditableChildren(element, props, childNodes)) {
|
|
1407
|
+
if (!(isDomHostElement(element) && childNodes.length === 0 && committedPortalContainers.has(element)) &&
|
|
1408
|
+
!(isDomHostElement(element) && shouldPreserveContentEditableChildren(element, props, childNodes))) {
|
|
1299
1409
|
syncChildNodes(element, childNodes);
|
|
1300
1410
|
}
|
|
1301
1411
|
}
|
|
1302
1412
|
else if (fiber.subtreeFlags !== NoFlags) {
|
|
1303
1413
|
commitHostChildren(fiber.child, element, eventRoot, `${path}.c`, options);
|
|
1304
1414
|
}
|
|
1305
|
-
|
|
1415
|
+
if (isDomHostElement(element)) {
|
|
1416
|
+
applyPostChildFormProps(element, props, previousProps);
|
|
1417
|
+
}
|
|
1418
|
+
applyChangedRef(previousProps?.ref, props.ref, element);
|
|
1306
1419
|
fiber.memoizedProps = props;
|
|
1307
1420
|
finishCommittedFiber(fiber);
|
|
1308
1421
|
return [element];
|
|
@@ -1381,16 +1494,21 @@ function commitHostFiber(fiber, parent, eventRoot, path, options = {}) {
|
|
|
1381
1494
|
}
|
|
1382
1495
|
if (fiber.tag === "portal") {
|
|
1383
1496
|
const container = fiber.stateNode;
|
|
1384
|
-
if (!(container
|
|
1497
|
+
if (!isPortalHostContainer(container)) {
|
|
1385
1498
|
return [];
|
|
1386
1499
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
const
|
|
1392
|
-
?
|
|
1393
|
-
:
|
|
1500
|
+
if (container instanceof Element) {
|
|
1501
|
+
setLogicalEventParent(container, parent);
|
|
1502
|
+
committedPortalContainers.add(container);
|
|
1503
|
+
}
|
|
1504
|
+
const portalEventRoot = container instanceof Element && eventRoot !== container && eventRoot.contains(container)
|
|
1505
|
+
? eventRoot
|
|
1506
|
+
: container instanceof Element
|
|
1507
|
+
? container
|
|
1508
|
+
: eventRoot;
|
|
1509
|
+
const portalOptions = withPortalDocumentRef(options, container);
|
|
1510
|
+
const childNodes = commitHostChildren(fiber.child, container, portalEventRoot, `${path}.portal`, portalOptions);
|
|
1511
|
+
const previousNodes = committedHostNodesFromState(fiber.alternate?.memoizedState);
|
|
1394
1512
|
syncOwnedChildNodes(container, previousNodes, childNodes);
|
|
1395
1513
|
fiber.memoizedState = childNodes;
|
|
1396
1514
|
fiber.memoizedProps = fiber.pendingProps;
|
|
@@ -1907,6 +2025,12 @@ function normalizeChildren(node) {
|
|
|
1907
2025
|
function getDocumentRef(options) {
|
|
1908
2026
|
return options.documentRef ?? document;
|
|
1909
2027
|
}
|
|
2028
|
+
function createHostTextNode(documentRef) {
|
|
2029
|
+
if ("createTextNode" in documentRef && typeof documentRef.createTextNode === "function") {
|
|
2030
|
+
return documentRef.createTextNode("");
|
|
2031
|
+
}
|
|
2032
|
+
return document.createTextNode("");
|
|
2033
|
+
}
|
|
1910
2034
|
function collectExistingKeyedFibers(firstChild) {
|
|
1911
2035
|
const keyed = new Map();
|
|
1912
2036
|
let cursor = firstChild;
|
|
@@ -2029,7 +2153,47 @@ function applyChangedRef(previousRef, nextRef, node) {
|
|
|
2029
2153
|
if (Object.is(previousRef, nextRef)) {
|
|
2030
2154
|
return;
|
|
2031
2155
|
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2156
|
+
queueHostRefUpdate(previousRef, null);
|
|
2157
|
+
queueHostRefUpdate(nextRef, node);
|
|
2158
|
+
}
|
|
2159
|
+
function queueHostRefUpdate(ref, node) {
|
|
2160
|
+
if (ref === null || ref === undefined) {
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2163
|
+
pendingHostRefUpdates.push({ ref, node });
|
|
2164
|
+
}
|
|
2165
|
+
function flushPendingHostRefUpdates() {
|
|
2166
|
+
const pending = pendingHostRefUpdates.splice(0);
|
|
2167
|
+
for (const { ref, node } of pending) {
|
|
2168
|
+
applyRef(ref, node);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
function isPortalHostContainer(value) {
|
|
2172
|
+
if (value instanceof Element) {
|
|
2173
|
+
return true;
|
|
2174
|
+
}
|
|
2175
|
+
if (typeof value !== "object" || value === null) {
|
|
2176
|
+
return false;
|
|
2177
|
+
}
|
|
2178
|
+
const candidate = value;
|
|
2179
|
+
return (typeof candidate.appendChild === "function" &&
|
|
2180
|
+
typeof candidate.insertBefore === "function" &&
|
|
2181
|
+
typeof candidate.removeChild === "function" &&
|
|
2182
|
+
typeof candidate.ownerDocument?.createElement === "function");
|
|
2183
|
+
}
|
|
2184
|
+
function withPortalDocumentRef(options, container) {
|
|
2185
|
+
const ownerDocument = container.ownerDocument;
|
|
2186
|
+
if (typeof ownerDocument === "object" &&
|
|
2187
|
+
ownerDocument !== null &&
|
|
2188
|
+
typeof ownerDocument.createElement === "function") {
|
|
2189
|
+
return {
|
|
2190
|
+
...options,
|
|
2191
|
+
documentRef: ownerDocument,
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
return options;
|
|
2195
|
+
}
|
|
2196
|
+
function committedHostNodesFromState(state) {
|
|
2197
|
+
return Array.isArray(state) ? state : [];
|
|
2034
2198
|
}
|
|
2035
2199
|
//# sourceMappingURL=host-reconciler.js.map
|