|
8 | 8 | getOwner, |
9 | 9 | runWithOwner |
10 | 10 | } from "@solidjs/signals"; |
11 | | -import { createErrorBoundary, createLoadingBoundary } from "./hydration.js"; |
| 11 | +import { createErrorBoundary, createLoadingBoundary, sharedConfig } from "./hydration.js"; |
12 | 12 | import type { Accessor, RevealOrder } from "@solidjs/signals"; |
13 | 13 | export type { RevealOrder }; |
14 | 14 | import type { Element as SolidElement } from "../types.js"; |
@@ -98,13 +98,22 @@ export function For<T extends readonly any[], U extends SolidElement>(props: { |
98 | 98 | // path, created lazily under the component's owner on first read. |
99 | 99 | const owner = getOwner(); |
100 | 100 | let mapped: (() => any) | undefined; |
101 | | - const list = () => { |
102 | | - if (mapped === undefined) |
103 | | - mapped = runWithOwner(owner, () => |
104 | | - mapArray(() => props.each, props.children as any, options as any) |
105 | | - ) as () => any; |
106 | | - return mapped(); |
107 | | - }; |
| 101 | + const create = () => |
| 102 | + runWithOwner(owner, () => |
| 103 | + mapArray(() => props.each, props.children as any, options as any) |
| 104 | + ) as () => any; |
| 105 | + // Hydration id parity (#3161): hydration ids mint at CREATION time, and |
| 106 | + // the server spends the list's id slot at For's source position — so a |
| 107 | + // hydrating client must create the map HERE, not on first read. Deferred |
| 108 | + // creation ran at insert's hole evaluation, AFTER later siblings had |
| 109 | + // already claimed their template keys, shifting every hydration id after |
| 110 | + // the list (the siblings hydrated detached: dead buttons). Outside |
| 111 | + // hydration the laziness stands — it is the driver seam's point: an |
| 112 | + // engaged list never builds the mapArray at all. (A driver-ENGAGED |
| 113 | + // hydration does not read this accessor either; driveList claims rows |
| 114 | + // positionally through their own _hk keys.) |
| 115 | + if (sharedConfig.hydrating) mapped = create(); |
| 116 | + const list = () => (mapped ?? (mapped = create()))(); |
108 | 117 | if (props.keyed !== false && !("fallback" in props) && props.children.length < 2) |
109 | 118 | // `keyed` rides along so the driver implements the DECLARED identity |
110 | 119 | // semantics (reference vs key fn) — see driveList's identity ruling. |
|
0 commit comments