@shadow-js/web 1.0.4 → 1.0.6
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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/dev/class-style.js +6 -1
- package/dist/dev/class-style.js.map +1 -1
- package/dist/dev/control-flow/dynamic.js +4 -4
- package/dist/dev/control-flow/no-hydration.js +1 -1
- package/dist/dev/control-flow/portal.js +1 -1
- package/dist/dev/element.js +2 -2
- package/dist/dev/extend.js +6 -6
- package/dist/dev/head/use-head.js +1 -1
- package/dist/dev/head/validate.js +1 -1
- package/dist/dev/hydration.js +21 -13
- package/dist/dev/hydration.js.map +1 -1
- package/dist/dev/index.d.ts +5 -5
- package/dist/dev/index.js +6 -6
- package/dist/dev/insert.js +12 -1
- package/dist/dev/insert.js.map +1 -1
- package/dist/dev/jsx/global.d.ts +2 -2
- package/dist/dev/jsx/html.d.ts +1 -1
- package/dist/dev/jsx/intrinsic.d.ts +1 -1
- package/dist/dev/jsx/mathml.d.ts +1 -1
- package/dist/dev/jsx/svg.d.ts +1 -1
- package/dist/dev/jsx-runtime.d.ts +3 -3
- package/dist/dev/render.js +22 -11
- package/dist/dev/render.js.map +1 -1
- package/dist/dev/select-value.d.ts +3 -1
- package/dist/dev/select-value.js +11 -1
- package/dist/dev/select-value.js.map +1 -1
- package/dist/dev/server/class-style.js +1 -1
- package/dist/dev/server/element.js +3 -3
- package/dist/dev/server/form-controls.js +1 -1
- package/dist/dev/server/hydration-script.js +1 -1
- package/dist/dev/server/portals.js +1 -1
- package/dist/dev/server/raw-text.js +1 -1
- package/dist/dev/server/render.js +2 -2
- package/dist/dev/server/stream.js +3 -3
- package/dist/dev/spread.js +12 -4
- package/dist/dev/spread.js.map +1 -1
- package/dist/dev/template.js +3 -3
- package/dist/prod/class-style.js +1 -1
- package/dist/prod/class-style.js.map +1 -1
- package/dist/prod/control-flow/dynamic.js +1 -1
- package/dist/prod/control-flow/no-hydration.js +1 -1
- package/dist/prod/control-flow/portal.js +1 -1
- package/dist/prod/element.js +1 -1
- package/dist/prod/events.js +1 -1
- package/dist/prod/events.js.map +1 -1
- package/dist/prod/extend.js +1 -1
- package/dist/prod/head/use-head.js +1 -1
- package/dist/prod/head/validate.js +1 -1
- package/dist/prod/hydration.js +1 -1
- package/dist/prod/hydration.js.map +1 -1
- package/dist/prod/index.js +1 -1
- package/dist/prod/insert.js +1 -1
- package/dist/prod/insert.js.map +1 -1
- package/dist/prod/render.js +1 -1
- package/dist/prod/render.js.map +1 -1
- package/dist/prod/select-value.js +1 -1
- package/dist/prod/select-value.js.map +1 -1
- package/dist/prod/server/class-style.js +1 -1
- package/dist/prod/server/element.js +1 -1
- package/dist/prod/server/form-controls.js +2 -2
- package/dist/prod/server/hydration-script.js +1 -1
- package/dist/prod/server/portals.js +1 -1
- package/dist/prod/server/raw-text.js +1 -1
- package/dist/prod/server/render.js +1 -1
- package/dist/prod/server/stream.js +1 -1
- package/dist/prod/spread.js +1 -1
- package/dist/prod/spread.js.map +1 -1
- package/dist/prod/template.js +1 -1
- package/dist/server/class-style.js +1 -1
- package/dist/server/class-style.js.map +1 -1
- package/dist/server/control-flow/dynamic.js +1 -1
- package/dist/server/control-flow/portal.js +1 -1
- package/dist/server/control-flow/suspense.js +1 -1
- package/dist/server/element.js +1 -1
- package/dist/server/events.js +1 -1
- package/dist/server/events.js.map +1 -1
- package/dist/server/extend.js +1 -1
- package/dist/server/head/use-head.js +1 -1
- package/dist/server/head/validate.js +1 -1
- package/dist/server/hydration.js +1 -1
- package/dist/server/hydration.js.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/insert.js +1 -1
- package/dist/server/insert.js.map +1 -1
- package/dist/server/render.js +1 -1
- package/dist/server/render.js.map +1 -1
- package/dist/server/select-value.js +1 -1
- package/dist/server/select-value.js.map +1 -1
- package/dist/server/server/class-style.js +1 -1
- package/dist/server/server/element.js +1 -1
- package/dist/server/server/form-controls.js +2 -2
- package/dist/server/server/hydration-script.js +1 -1
- package/dist/server/server/portals.js +1 -1
- package/dist/server/server/raw-text.js +1 -1
- package/dist/server/server/render.js +1 -1
- package/dist/server/server/stream.js +1 -1
- package/dist/server/spread.js +1 -1
- package/dist/server/spread.js.map +1 -1
- package/dist/server/template.js +1 -1
- package/dist/server-dev/class-style.js +6 -1
- package/dist/server-dev/class-style.js.map +1 -1
- package/dist/server-dev/control-flow/dynamic.js +1 -1
- package/dist/server-dev/control-flow/portal.js +1 -1
- package/dist/server-dev/control-flow/suspense.js +2 -2
- package/dist/server-dev/element.js +1 -1
- package/dist/server-dev/extend.js +6 -6
- package/dist/server-dev/head/use-head.js +1 -1
- package/dist/server-dev/head/validate.js +1 -1
- package/dist/server-dev/hydration.js +21 -13
- package/dist/server-dev/hydration.js.map +1 -1
- package/dist/server-dev/index.js +6 -6
- package/dist/server-dev/insert.js +12 -1
- package/dist/server-dev/insert.js.map +1 -1
- package/dist/server-dev/render.js +22 -11
- package/dist/server-dev/render.js.map +1 -1
- package/dist/server-dev/select-value.js +11 -1
- package/dist/server-dev/select-value.js.map +1 -1
- package/dist/server-dev/server/class-style.js +1 -1
- package/dist/server-dev/server/element.js +3 -3
- package/dist/server-dev/server/form-controls.js +1 -1
- package/dist/server-dev/server/hydration-script.js +1 -1
- package/dist/server-dev/server/portals.js +1 -1
- package/dist/server-dev/server/raw-text.js +1 -1
- package/dist/server-dev/server/render.js +2 -2
- package/dist/server-dev/server/stream.js +3 -3
- package/dist/server-dev/spread.js +12 -4
- package/dist/server-dev/spread.js.map +1 -1
- package/dist/server-dev/template.js +3 -3
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createComponent } from "../component.js";
|
|
2
|
-
import { isTextOnlyElement } from "../server/raw-text.js";
|
|
3
2
|
import { ssrElement, ssrRaw } from "../server/element.js";
|
|
3
|
+
import { isTextOnlyElement } from "../server/raw-text.js";
|
|
4
4
|
import { mergeProps, splitProps, untrack, useMemo } from "@shadow-js/core";
|
|
5
5
|
// src/control-flow/dynamic.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { bindRegion, createRegion, moveRegion, removeRegion } from "../insert.js";
|
|
1
2
|
import { childScope, nextKey, withScope } from "../internal/hydration-scope.js";
|
|
2
3
|
import { claims } from "../internal/hydration-hooks.js";
|
|
3
|
-
import { bindRegion, createRegion, moveRegion, removeRegion } from "../insert.js";
|
|
4
4
|
import { PortalContext } from "../internal/portal-context.js";
|
|
5
5
|
import { createRoot, getOwner, isServer, onCleanup, runWithOwner, useContext, useRenderEffect } from "@shadow-js/core";
|
|
6
6
|
// src/control-flow/portal.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { childScope, nextKey, withScope } from "../internal/hydration-scope.js";
|
|
2
|
-
import { escape } from "../server/escape.js";
|
|
3
|
-
import { ssrRaw } from "../server/element.js";
|
|
4
2
|
import { StreamContext } from "../internal/stream-context.js";
|
|
3
|
+
import { ssrRaw } from "../server/element.js";
|
|
4
|
+
import { escape } from "../server/escape.js";
|
|
5
5
|
import { SuspenseContext, getOwner, runWithOwner, useContext } from "@shadow-js/core";
|
|
6
6
|
import { SignalNode, createOwner, readSignal, transitionHooks, writeSignal } from "@shadow-js/core/extend";
|
|
7
7
|
// src/control-flow/suspense.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { warnOnce } from "./internal/diagnostics.js";
|
|
2
1
|
import { isUnsafeUrlAttribute } from "./attributes.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { element } from "./element.js";
|
|
3
|
+
import { bindRegion, createRegion, moveRegion, removeRegion } from "./insert.js";
|
|
5
4
|
import { claimElement, claimPortal, isClaiming, takeRegion, withoutClaiming } from "./internal/claim.js";
|
|
5
|
+
import { warnOnce } from "./internal/diagnostics.js";
|
|
6
6
|
import { claims } from "./internal/hydration-hooks.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { element } from "./element.js";
|
|
7
|
+
import { childScope, createRootScope, currentScope, enterComponent, nextKey, resourceKey, withScope } from "./internal/hydration-scope.js";
|
|
8
|
+
import { HTML_NS, MATHML_NS, SVG_NS } from "./internal/names.js";
|
|
10
9
|
import { PortalContext } from "./internal/portal-context.js";
|
|
10
|
+
import { reconcileNodes } from "./internal/reconcile.js";
|
|
11
11
|
import { StreamContext } from "./internal/stream-context.js";
|
|
12
12
|
export { HTML_NS, MATHML_NS, PortalContext, SVG_NS, StreamContext, bindRegion, childScope, claimElement, claimPortal, claims, createRegion, createRootScope, currentScope, element, enterComponent, isClaiming, isUnsafeUrlAttribute, moveRegion, nextKey, reconcileNodes, removeRegion, resourceKey, takeRegion, warnOnce, withScope, withoutClaiming };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHeadRegistry } from "./registry.js";
|
|
2
|
-
import { normalizeTags } from "./validate.js";
|
|
3
2
|
import { ServerHeadContext } from "./server-head.js";
|
|
4
3
|
import { createDomHeadSink } from "./sink.js";
|
|
4
|
+
import { normalizeTags } from "./validate.js";
|
|
5
5
|
import { createRoot, getOwner, isServer, untrack, useContext, useEffect, useRenderEffect, useSignal } from "@shadow-js/core";
|
|
6
6
|
// src/head/use-head.ts
|
|
7
7
|
/** One registry per document, shared by every `useHead` call on it. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { warnOnce } from "../internal/diagnostics.js";
|
|
2
1
|
import { isUnsafeUrlAttribute } from "../attributes.js";
|
|
2
|
+
import { warnOnce } from "../internal/diagnostics.js";
|
|
3
3
|
// src/head/validate.ts
|
|
4
4
|
/** Marks every element the sink created or adopted. Callers may not supply it. @internal */
|
|
5
5
|
const HEAD_MARKER = "data-shadow-head";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createRootScope, resourceKey, withScope } from "./internal/hydration-scope.js";
|
|
2
|
-
import { beginClaiming, claimElement, claimPortal, endClaiming, isClaiming, liftedRegions, releaseUnclaimedPortals, takeRegion, withoutClaiming } from "./internal/claim.js";
|
|
3
|
-
import { claims } from "./internal/hydration-hooks.js";
|
|
4
|
-
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
5
1
|
import { attachRootErrors } from "./control-flow/root-errors.js";
|
|
2
|
+
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
3
|
+
import { beginClaiming, claimElement, claimPortal, endClaiming, isClaiming, liftedRegions, releaseUnclaimedPortals, takeRegion, withoutClaiming } from "./internal/claim.js";
|
|
6
4
|
import { replayEarlyEvents } from "./internal/early-events.js";
|
|
5
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
6
|
+
import { createRootScope, resourceKey, withScope } from "./internal/hydration-scope.js";
|
|
7
7
|
import { ResourceCacheContext, batch, createRoot, flushSync, runWithOwner, untrack } from "@shadow-js/core";
|
|
8
8
|
import { withHydration } from "@shadow-js/core/extend";
|
|
9
9
|
// src/hydration.ts
|
|
@@ -87,8 +87,16 @@ function hydrate(code, container, options = {}) {
|
|
|
87
87
|
const cache = dataCache(options.data ?? {});
|
|
88
88
|
const region = createRegion(container, null, Array.from(container.childNodes));
|
|
89
89
|
let stop;
|
|
90
|
+
let disposed = false;
|
|
91
|
+
const teardown = () => {
|
|
92
|
+
if (disposed) return;
|
|
93
|
+
disposed = true;
|
|
94
|
+
stop?.();
|
|
95
|
+
removeRegion(region);
|
|
96
|
+
};
|
|
90
97
|
try {
|
|
91
|
-
|
|
98
|
+
withHydration(() => batch(() => withScope(createRootScope(options.renderId), () => runWithOwner(options.owner ?? null, () => createRoot((dispose) => {
|
|
99
|
+
stop = dispose;
|
|
92
100
|
attachRootErrors(options);
|
|
93
101
|
ResourceCacheContext({
|
|
94
102
|
value: cache,
|
|
@@ -97,22 +105,22 @@ function hydrate(code, container, options = {}) {
|
|
|
97
105
|
return null;
|
|
98
106
|
}
|
|
99
107
|
});
|
|
100
|
-
return dispose;
|
|
101
108
|
})))));
|
|
102
109
|
flushSync();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
try {
|
|
112
|
+
stop?.();
|
|
113
|
+
} catch (cleanupError) {
|
|
114
|
+
throw new AggregateError([error, cleanupError], "hydrate() failed and so did its teardown.");
|
|
115
|
+
}
|
|
116
|
+
throw error;
|
|
103
117
|
} finally {
|
|
104
118
|
endClaiming();
|
|
105
119
|
claims.current = previousClaims;
|
|
106
120
|
}
|
|
107
121
|
replayEarlyEvents();
|
|
108
122
|
stripLeftovers(container);
|
|
109
|
-
|
|
110
|
-
return () => {
|
|
111
|
-
if (disposed) return;
|
|
112
|
-
disposed = true;
|
|
113
|
-
stop();
|
|
114
|
-
removeRegion(region);
|
|
115
|
-
};
|
|
123
|
+
return teardown;
|
|
116
124
|
}
|
|
117
125
|
export { hydrate };
|
|
118
126
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration.js","names":[],"sources":["../../src/hydration.ts"],"sourcesContent":["import {\n batch,\n createRoot,\n flushSync,\n type Owner,\n type ResourceCache,\n ResourceCacheContext,\n runWithOwner,\n untrack,\n} from \"@shadow-js/core\";\nimport { withHydration } from \"@shadow-js/core/extend\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport {\n beginClaiming,\n claimElement,\n claimPortal,\n endClaiming,\n isClaiming,\n liftedRegions,\n releaseUnclaimedPortals,\n takeRegion,\n withoutClaiming,\n} from \"./internal/claim\";\nimport { replayEarlyEvents } from \"./internal/early-events\";\nimport { type Claims, claims } from \"./internal/hydration-hooks\";\nimport { createRootScope, resourceKey, withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link hydrate}: the server render it continues, the root's owner, and the error\n * reporters it inherits from `RootErrorOptions` (`onUncaughtError`, `onCaughtError`,\n * `onRecoverableError`).\n * @since 1.0.0\n */\nexport interface HydrateOptions extends RootErrorOptions {\n /**\n * The id the server render used, so the client numbers its elements with the same keys. Must\n * equal the `renderId` given to the server render.\n * @default \"0\"\n */\n renderId?: string;\n /**\n * The resource values the server fetched: the `data` of `renderToStringAsync`. A resource whose\n * key is found here starts with that value instead of fetching it again. Each value is used once.\n * @default {} (no resource value is preloaded; resources fetch on the client)\n */\n data?: Record<string, unknown>;\n /**\n * The owner the hydrated root is created under, so its context (providers) is visible to the app.\n * @default null (the root has no parent owner)\n */\n owner?: Owner;\n}\n\nfunction dataCache(data: Record<string, unknown>): ResourceCache {\n const used = new Set<string>();\n return {\n key: resourceKey,\n read(key) {\n if (used.has(key) || !Object.hasOwn(data, key)) return undefined;\n used.add(key);\n return { value: data[key] };\n },\n track() {\n // Client fetches are not tracked: nothing waits for them.\n },\n };\n}\n\n/**\n * Removes marker comments the pass did not claim, so the live DOM never keeps any, and the server\n * blocks of portals the client did not render (they would show content the client does not have).\n */\nfunction stripLeftovers(container: Node): void {\n const doc = container instanceof Document ? container : container.ownerDocument;\n if (doc === null) return;\n if (doc.body !== null) releaseUnclaimedPortals(doc.body);\n const walker = doc.createTreeWalker(container, NodeFilter.SHOW_COMMENT);\n const stale: Comment[] = [];\n while (walker.nextNode()) {\n const comment = walker.currentNode as Comment;\n if (comment.data === \"[\" || comment.data === \"]\") stale.push(comment);\n }\n for (const comment of stale) comment.remove();\n}\n\n/**\n * Attaches the application to HTML the server already rendered into `container`. Elements are\n * claimed by their `data-hk` keys instead of created, so the DOM is not rebuilt and nodes keep\n * their identity. Event handlers and reactive bindings are attached; markers are removed. Parts the\n * server and client disagree on are repaired by reconciliation, never left half hydrated.\n *\n * @param code Runs once, untracked, and builds the same component tree the server rendered.\n * @param container Element or Document that holds the server markup.\n * @param options `renderId` (must match the server), the server's resource `data`, an `owner`, and\n * the error reporters. Undefined uses the defaults.\n * @returns A dispose function that stops the hydrated root and removes its nodes. Safe to call more\n * than once.\n * @throws Error (production message `SHADOW_HYDRATE_RUNNING`) when called while another hydration\n * pass is in progress.\n * @example\n * import { createComponent, hydrate } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const container = document.getElementById(\"app\") as Element;\n * const data = JSON.parse(document.getElementById(\"data\")?.textContent ?? \"{}\") as Record<\n * string,\n * unknown\n * >;\n * const dispose = hydrate(() => createComponent(App, {}), container, { data });\n * @see render\n * @since 1.0.0\n */\nexport function hydrate(\n code: () => unknown,\n container: Element | Document,\n options: HydrateOptions = {},\n): () => void {\n if (isClaiming())\n throw new Error(\n __DEV__ ? \"hydrate(): a hydration pass is already running.\" : \"SHADOW_HYDRATE_RUNNING\",\n );\n const registry = new Map<string, Element>();\n const roots: Element[] = container instanceof Element ? [container] : [];\n for (const element of [...roots, ...Array.from(container.querySelectorAll(\"[data-hk]\"))]) {\n const key = element.getAttribute(\"data-hk\");\n if (key !== null) registry.set(key, element);\n }\n beginClaiming(registry, options.onRecoverableError);\n // The renderer reaches the claiming code only through this hook, installed for this pass alone.\n const passClaims: Claims = {\n claimElement,\n takeRegion,\n liftedRegions,\n claimPortal,\n isClaiming,\n withoutClaiming,\n };\n const previousClaims = claims.current;\n claims.current = passClaims;\n const cache = dataCache(options.data ?? {});\n const region = createRegion(container, null, Array.from(container.childNodes));\n let stop: () => void;\n try {\n // The batch wraps the scope, not the other way round: its exit flushes the queued effects\n // (onMount, and the re-renders they cause) after the scope is restored. The scope numbers only\n // the templates the server rendered; an effect that builds new DOM must not draw keys from it\n // (that shifts the keys of later siblings and misses the ones the server never sent). Boundaries\n // rebuild from their own captured scope, so a reset inside the pass still claims its elements.\n
|
|
1
|
+
{"version":3,"file":"hydration.js","names":[],"sources":["../../src/hydration.ts"],"sourcesContent":["import {\n batch,\n createRoot,\n flushSync,\n type Owner,\n type ResourceCache,\n ResourceCacheContext,\n runWithOwner,\n untrack,\n} from \"@shadow-js/core\";\nimport { withHydration } from \"@shadow-js/core/extend\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport {\n beginClaiming,\n claimElement,\n claimPortal,\n endClaiming,\n isClaiming,\n liftedRegions,\n releaseUnclaimedPortals,\n takeRegion,\n withoutClaiming,\n} from \"./internal/claim\";\nimport { replayEarlyEvents } from \"./internal/early-events\";\nimport { type Claims, claims } from \"./internal/hydration-hooks\";\nimport { createRootScope, resourceKey, withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link hydrate}: the server render it continues, the root's owner, and the error\n * reporters it inherits from `RootErrorOptions` (`onUncaughtError`, `onCaughtError`,\n * `onRecoverableError`).\n * @since 1.0.0\n */\nexport interface HydrateOptions extends RootErrorOptions {\n /**\n * The id the server render used, so the client numbers its elements with the same keys. Must\n * equal the `renderId` given to the server render.\n * @default \"0\"\n */\n renderId?: string;\n /**\n * The resource values the server fetched: the `data` of `renderToStringAsync`. A resource whose\n * key is found here starts with that value instead of fetching it again. Each value is used once.\n * @default {} (no resource value is preloaded; resources fetch on the client)\n */\n data?: Record<string, unknown>;\n /**\n * The owner the hydrated root is created under, so its context (providers) is visible to the app.\n * @default null (the root has no parent owner)\n */\n owner?: Owner;\n}\n\nfunction dataCache(data: Record<string, unknown>): ResourceCache {\n const used = new Set<string>();\n return {\n key: resourceKey,\n read(key) {\n if (used.has(key) || !Object.hasOwn(data, key)) return undefined;\n used.add(key);\n return { value: data[key] };\n },\n track() {\n // Client fetches are not tracked: nothing waits for them.\n },\n };\n}\n\n/**\n * Removes marker comments the pass did not claim, so the live DOM never keeps any, and the server\n * blocks of portals the client did not render (they would show content the client does not have).\n */\nfunction stripLeftovers(container: Node): void {\n const doc = container instanceof Document ? container : container.ownerDocument;\n if (doc === null) return;\n if (doc.body !== null) releaseUnclaimedPortals(doc.body);\n const walker = doc.createTreeWalker(container, NodeFilter.SHOW_COMMENT);\n const stale: Comment[] = [];\n while (walker.nextNode()) {\n const comment = walker.currentNode as Comment;\n if (comment.data === \"[\" || comment.data === \"]\") stale.push(comment);\n }\n for (const comment of stale) comment.remove();\n}\n\n/**\n * Attaches the application to HTML the server already rendered into `container`. Elements are\n * claimed by their `data-hk` keys instead of created, so the DOM is not rebuilt and nodes keep\n * their identity. Event handlers and reactive bindings are attached; markers are removed. Parts the\n * server and client disagree on are repaired by reconciliation, never left half hydrated.\n *\n * @param code Runs once, untracked, and builds the same component tree the server rendered.\n * @param container Element or Document that holds the server markup.\n * @param options `renderId` (must match the server), the server's resource `data`, an `owner`, and\n * the error reporters. Undefined uses the defaults.\n * @returns A dispose function that stops the hydrated root and removes its nodes. Safe to call more\n * than once.\n * @throws Error (production message `SHADOW_HYDRATE_RUNNING`) when called while another hydration\n * pass is in progress.\n * @example\n * import { createComponent, hydrate } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const container = document.getElementById(\"app\") as Element;\n * const data = JSON.parse(document.getElementById(\"data\")?.textContent ?? \"{}\") as Record<\n * string,\n * unknown\n * >;\n * const dispose = hydrate(() => createComponent(App, {}), container, { data });\n * @see render\n * @since 1.0.0\n */\nexport function hydrate(\n code: () => unknown,\n container: Element | Document,\n options: HydrateOptions = {},\n): () => void {\n if (isClaiming())\n throw new Error(\n __DEV__ ? \"hydrate(): a hydration pass is already running.\" : \"SHADOW_HYDRATE_RUNNING\",\n );\n const registry = new Map<string, Element>();\n const roots: Element[] = container instanceof Element ? [container] : [];\n for (const element of [...roots, ...Array.from(container.querySelectorAll(\"[data-hk]\"))]) {\n const key = element.getAttribute(\"data-hk\");\n if (key !== null) registry.set(key, element);\n }\n beginClaiming(registry, options.onRecoverableError);\n // The renderer reaches the claiming code only through this hook, installed for this pass alone.\n const passClaims: Claims = {\n claimElement,\n takeRegion,\n liftedRegions,\n claimPortal,\n isClaiming,\n withoutClaiming,\n };\n const previousClaims = claims.current;\n claims.current = passClaims;\n const cache = dataCache(options.data ?? {});\n const region = createRegion(container, null, Array.from(container.childNodes));\n let stop: (() => void) | undefined;\n let disposed = false;\n const teardown = (): void => {\n if (disposed) return;\n disposed = true;\n stop?.();\n removeRegion(region);\n };\n try {\n // The batch wraps the scope, not the other way round: its exit flushes the queued effects\n // (onMount, and the re-renders they cause) after the scope is restored. The scope numbers only\n // the templates the server rendered; an effect that builds new DOM must not draw keys from it\n // (that shifts the keys of later siblings and misses the ones the server never sent). Boundaries\n // rebuild from their own captured scope, so a reset inside the pass still claims its elements.\n withHydration(() =>\n batch(() =>\n withScope(createRootScope(options.renderId), () =>\n runWithOwner(options.owner ?? null, () =>\n createRoot((dispose) => {\n stop = dispose;\n attachRootErrors(options);\n ResourceCacheContext({\n value: cache,\n get children() {\n bindRegion(region, untrack(code));\n return null;\n },\n });\n }),\n ),\n ),\n ),\n );\n flushSync();\n } catch (error) {\n // The caller gets no dispose function from a hydration that throws, so the root must not stay alive. Its\n // effects and listeners go; the server's markup stays, so the page keeps what the server rendered.\n try {\n stop?.();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n __DEV__ ? \"hydrate() failed and so did its teardown.\" : \"SHADOW_HYDRATE_ERRORS\",\n );\n }\n throw error;\n } finally {\n endClaiming();\n claims.current = previousClaims;\n }\n replayEarlyEvents();\n stripLeftovers(container);\n return teardown;\n}\n"],"mappings":";;;;;;;;;AAsDA,SAAS,UAAU,MAA8C;CAC/D,MAAM,uBAAO,IAAI,IAAY;CAC7B,OAAO;EACL,KAAK;EACL,KAAK,KAAK;GACR,IAAI,KAAK,IAAI,GAAG,KAAK,CAAC,OAAO,OAAO,MAAM,GAAG,GAAG,OAAO,KAAA;GACvD,KAAK,IAAI,GAAG;GACZ,OAAO,EAAE,OAAO,KAAK,KAAK;EAC5B;EACA,QAAQ,CAER;CACF;AACF;;;;;AAMA,SAAS,eAAe,WAAuB;CAC7C,MAAM,MAAM,qBAAqB,WAAW,YAAY,UAAU;CAClE,IAAI,QAAQ,MAAM;CAClB,IAAI,IAAI,SAAS,MAAM,wBAAwB,IAAI,IAAI;CACvD,MAAM,SAAS,IAAI,iBAAiB,WAAW,WAAW,YAAY;CACtE,MAAM,QAAmB,CAAC;CAC1B,OAAO,OAAO,SAAS,GAAG;EACxB,MAAM,UAAU,OAAO;EACvB,IAAI,QAAQ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AAM,IAAI,eACR,CAAC,OAAO,YAAY,GACV,2CACZ;EACF;EACA,MAAM;CACR,UAAU;EACR,YAAY;EACZ,OAAO,UAAU;CACnB;CACA,kBAAkB;CAClB,eAAe,SAAS;CACxB,OAAO;AACT"}
|
package/dist/server-dev/index.js
CHANGED
|
@@ -5,11 +5,11 @@ import { createComponent } from "./component.js";
|
|
|
5
5
|
import { Activity } from "./control-flow/activity.js";
|
|
6
6
|
import { Show } from "./control-flow/show.js";
|
|
7
7
|
import { ClientOnly } from "./control-flow/client-only.js";
|
|
8
|
-
import {
|
|
8
|
+
import { derived } from "./derived.js";
|
|
9
9
|
import { element } from "./element.js";
|
|
10
10
|
import { addEventListener, chainEvents, clearDelegatedEvents, delegateEvents } from "./events.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { hydrate } from "./hydration.js";
|
|
12
|
+
import { anchor, insert } from "./insert.js";
|
|
13
13
|
import { Dynamic, createDynamic } from "./control-flow/dynamic.js";
|
|
14
14
|
import { ErrorBoundary } from "./control-flow/error-boundary.js";
|
|
15
15
|
import { For } from "./control-flow/for.js";
|
|
@@ -21,13 +21,13 @@ import { Portal } from "./control-flow/portal.js";
|
|
|
21
21
|
import { SuspenseList } from "./control-flow/suspense-list.js";
|
|
22
22
|
import { Suspense } from "./control-flow/suspense.js";
|
|
23
23
|
import { Match, Switch } from "./control-flow/switch.js";
|
|
24
|
-
import {
|
|
24
|
+
import { effect, memo, refTo, use } from "./reactive.js";
|
|
25
25
|
import { useHead } from "./head/use-head.js";
|
|
26
26
|
import { Base, Link, Meta, Style, Title } from "./head/components.js";
|
|
27
|
-
import { hydrate } from "./hydration.js";
|
|
28
|
-
import { effect, memo, refTo, use } from "./reactive.js";
|
|
29
27
|
import { render } from "./render.js";
|
|
30
28
|
import { preconnect, prefetchDNS, preinit, preinitModule, preload, preloadModule } from "./resource-hints.js";
|
|
29
|
+
import { setSelectValue } from "./select-value.js";
|
|
30
|
+
import { spread } from "./spread.js";
|
|
31
31
|
import { template } from "./template.js";
|
|
32
32
|
import { ViewTransition, startViewTransition } from "./view-transition.js";
|
|
33
33
|
import { isDev, isServer, mergeProps } from "@shadow-js/core";
|
|
@@ -120,6 +120,14 @@ function watchCommits(parent, run) {
|
|
|
120
120
|
set.delete(run);
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Like {@link watchCommits}, for a watch that lives as long as `parent` does: it is not tied to the owner that is
|
|
125
|
+
* current, so a binding that runs again does not end it. The select's value (see `setSelectValue`) uses it.
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
function keepWatchingCommits(parent, run) {
|
|
129
|
+
commitWatchers.set(parent, (commitWatchers.get(parent) ?? /* @__PURE__ */ new Set()).add(run));
|
|
130
|
+
}
|
|
123
131
|
/** Applies a flattened value to a region. */
|
|
124
132
|
function commit(region, parts) {
|
|
125
133
|
if (region.claimed !== void 0) {
|
|
@@ -138,6 +146,9 @@ function commit(region, parts) {
|
|
|
138
146
|
commitWatchers.get(parent)?.forEach((run) => {
|
|
139
147
|
run();
|
|
140
148
|
});
|
|
149
|
+
if (parent.nodeName === "OPTGROUP" && parent.parentNode !== null) commitWatchers.get(parent.parentNode)?.forEach((run) => {
|
|
150
|
+
run();
|
|
151
|
+
});
|
|
141
152
|
}
|
|
142
153
|
/**
|
|
143
154
|
* Applies a resolved value to a region. A string or number is the common case (a dynamic text): when the region
|
|
@@ -372,6 +383,6 @@ function insert(parent, value, anchorNode, initial) {
|
|
|
372
383
|
const resolvedAnchor = anchorNode ?? null;
|
|
373
384
|
return bindRegion(createRegion(parent, resolvedAnchor, initial === void 0 ? claims.current.takeRegion(parent, resolvedAnchor) : initial), value, resolvedAnchor === null);
|
|
374
385
|
}
|
|
375
|
-
export { anchor, bindRegion, createRegion, insert, moveRegion, removeRegion, watchCommits };
|
|
386
|
+
export { anchor, bindRegion, createRegion, insert, keepWatchingCommits, moveRegion, removeRegion, watchCommits };
|
|
376
387
|
|
|
377
388
|
//# sourceMappingURL=insert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.js","names":[],"sources":["../../src/insert.ts"],"sourcesContent":["import { onCleanup, useRenderEffect } from \"@shadow-js/core\";\nimport {\n addCleanup,\n type ComputationNode,\n createComputation,\n currentOwner,\n disposeOwner,\n type Owner,\n readComputation,\n} from \"@shadow-js/core/extend\";\nimport { leaves } from \"./internal/accessor\";\nimport { checkClaimedText } from \"./internal/claim\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { keepFocus, reconcileNodes } from \"./internal/reconcile\";\n\n/** One piece of a value after flattening: a DOM node, or text to be turned into a Text node. */\ntype Part = Node | string;\n\n/**\n * State of one dynamic child region. `nodes` are the DOM nodes the region owns, in order. When\n * `anchor` is set, content goes before it. Without one, an empty region is placed after `marker`\n * (the node that preceded it), so it keeps its position while it is empty. A marker can be a node\n * another region owns and later replaces, so the region created right behind another one on the same parent\n * gives that one an anchor of its own (see `linkRegion`): the marker of every region is then either static\n * content or an anchor nobody replaces.\n * @internal\n */\nexport interface Region {\n readonly parent: Node;\n anchor: Node | null;\n marker: Node | null;\n /** The owner of the effect that keeps a reactive region up to date; unset until then (and for a static region). */\n owner?: Owner | null;\n nodes: Node[];\n /**\n * Text nodes this region created or adopted; only these may be reused by string updates. Null for none, the node\n * itself for one (the usual region: a single dynamic text), a Set for more, so most regions allocate no Set.\n */\n texts: Text | Set<Text> | null;\n /**\n * Development only: the server nodes a hydration pass handed this region, kept until its first\n * commit compares their text with the value (`checkClaimedText`).\n */\n claimed?: readonly Node[] | undefined;\n}\n\n/** The newest reactive unanchored region of each parent: the one the next such region may have to give an anchor. */\nconst tails = new WeakMap<Node, Region>();\n\n/** The document a node belongs to (a Document is its own document). */\nfunction documentOf(node: Node): Document {\n return node instanceof Document ? node : (node.ownerDocument ?? document);\n}\n\n/** True when the region created or adopted `node`. */\nfunction ownsText(region: Region, node: Node): boolean {\n const texts = region.texts;\n return texts === node || (texts instanceof Set && texts.has(node as Text));\n}\n\n/** Records that the region owns `text`. */\nfunction addText(region: Region, text: Text): void {\n const texts = region.texts;\n if (texts === null) region.texts = text;\n else if (texts instanceof Set) texts.add(text);\n else if (texts !== text) region.texts = new Set([texts, text]);\n}\n\n/** Forgets the Text nodes of the region that are not in `keep`. */\nfunction pruneTexts(region: Region, keep: readonly Node[]): void {\n const texts = region.texts;\n if (texts === null) return;\n if (texts instanceof Set) {\n const kept = new Set<Node>(keep);\n for (const text of texts) {\n if (!kept.has(text)) texts.delete(text);\n }\n } else if (!keep.includes(texts)) region.texts = null;\n}\n\n/**\n * The children a fragment held when it was first inserted. Inserting empties a fragment, and an effect\n * that runs again flattens the same fragment value once more: it must still give those nodes.\n */\nconst fragmentChildren = new WeakMap<DocumentFragment, Node[]>();\n\n/**\n * Flattens a value into parts without recursion. Functions are called (and their results unwrapped)\n * through `call`, which runs inside the render effect that owns the value, so reads are tracked.\n */\nfunction flatten(root: unknown, call?: (fn: () => unknown) => unknown): Part[] {\n const parts: Part[] = [];\n const cycle = __DEV__ ? \"insert(): a value contains itself.\" : \"SHADOW_INSERT_CYCLE\";\n for (const item of leaves(root, cycle, call)) {\n if (item === null || item === undefined || typeof item === \"boolean\") continue;\n if (item instanceof DocumentFragment) {\n const kids = fragmentChildren.get(item) ?? [...item.childNodes];\n fragmentChildren.set(item, kids);\n for (const child of kids) parts.push(child);\n } else parts.push(item instanceof Node ? item : String(item)); // strings, numbers and anything else that is text\n }\n return parts;\n}\n\n/** Text nodes the region currently owns, keyed by their data, for reuse by equal strings. */\nfunction reusablePool(region: Region): Map<string, Text[]> {\n const pool = new Map<string, Text[]>();\n for (const node of region.nodes) {\n if (!(node instanceof Text) || !ownsText(region, node)) continue;\n const list = pool.get(node.data);\n if (list === undefined) pool.set(node.data, [node]);\n else list.push(node);\n }\n return pool;\n}\n\n/** Turns parts into the nodes the region should hold, reusing its own Text nodes where possible. */\nfunction materialize(region: Region, parts: readonly Part[]): Node[] {\n const only = parts.length === 1 ? parts[0] : undefined;\n if (typeof only === \"string\") {\n const current = region.nodes.length === 1 ? region.nodes[0] : undefined;\n if (current instanceof Text && ownsText(region, current)) {\n if (current.data !== only) current.data = only;\n return [current];\n }\n }\n // Sized to the parts: `[]` and `push` would reserve room for sixteen nodes in every dynamic child (a row has two).\n const nodes: Node[] = new Array<Node>(parts.length);\n let count = 0;\n const seen = new Set<Node>();\n let pool: Map<string, Text[]> | undefined;\n for (const part of parts) {\n if (typeof part === \"string\") {\n pool ??= reusablePool(region);\n const reused = pool.get(part)?.pop();\n let text = reused;\n if (text === undefined) {\n text = documentOf(region.parent).createTextNode(part);\n addText(region, text);\n }\n seen.add(text);\n nodes[count] = text;\n count += 1;\n } else if (!seen.has(part)) {\n seen.add(part);\n nodes[count] = part;\n count += 1;\n }\n }\n nodes.length = count;\n return nodes;\n}\n\n/** The node after the region: its anchor, or the node after its last attached child (`last`), or its marker. */\nfunction endOf(region: Region, last: Node | undefined): Node | null {\n if (region.anchor !== null) return region.anchor;\n if (last !== undefined) return last.nextSibling;\n const marker = region.marker;\n if (marker === null) return region.parent.firstChild;\n if (marker.parentNode !== region.parent) return null;\n return marker.nextSibling;\n}\n\n/** Callbacks to run after a region of a parent has committed (see `watchCommits`). */\nconst commitWatchers = new WeakMap<Node, Set<() => void>>();\n\n/**\n * Runs `run` after every commit to a region of `parent`, so code that depends on which nodes the\n * parent holds (a name on the first element of a content region) can follow a change of content.\n * The watch ends with the owner that is current when this is called.\n * @internal\n */\nexport function watchCommits(parent: Node, run: () => void): void {\n const set = commitWatchers.get(parent) ?? new Set<() => void>();\n commitWatchers.set(parent, set.add(run));\n onCleanup(() => {\n set.delete(run);\n });\n}\n\n/** Applies a flattened value to a region. */\nfunction commit(region: Region, parts: readonly Part[]): void {\n if (__DEV__ && region.claimed !== undefined) {\n // Only the first commit of a claimed region is compared; later changes are ordinary updates.\n checkClaimedText(region.claimed, parts);\n region.claimed = undefined;\n }\n // Makes the DOM show the new nodes for this region.\n const next = materialize(region, parts);\n const parent = region.parent;\n const attached = region.nodes.filter((node) => node.parentNode === parent);\n const first = attached[0];\n const end = endOf(region, attached.at(-1));\n if (next.length === 0 && first !== undefined) region.marker = first.previousSibling;\n reconcileNodes(parent, attached, next, end);\n region.nodes = next;\n pruneTexts(region, next);\n commitWatchers.get(parent)?.forEach((run) => {\n run();\n });\n}\n\n/**\n * Applies a resolved value to a region. A string or number is the common case (a dynamic text): when the region\n * already shows its own Text node only the data is rewritten, and an empty region gets one new Text node, with none of\n * the flattening and reconciling a general value needs.\n */\nfunction commitValue(region: Region, raw: unknown): void {\n if ((typeof raw === \"string\" || typeof raw === \"number\") && !(__DEV__ && region.claimed)) {\n const nodes = region.nodes;\n const text = String(raw);\n if (nodes.length === 1) {\n const current = nodes[0];\n if (\n current instanceof Text &&\n current.parentNode === region.parent &&\n ownsText(region, current)\n ) {\n if (current.data !== text) current.data = text;\n return;\n }\n } else if (nodes.length === 0) {\n const created = documentOf(region.parent).createTextNode(text);\n addText(region, created);\n region.parent.insertBefore(created, endOf(region, undefined));\n region.nodes = [created];\n return;\n }\n }\n commit(region, flatten(raw));\n}\n\n/**\n * Creates the state of a region in `parent`. `anchorNode` (null to append) and `initial` (nodes\n * already in the DOM, from hydration or splitText) are both optional.\n * @internal\n */\nexport function createRegion(parent: Node, anchorNode: Node | null, initial: unknown): Region {\n // The nodes of `initial` (already in the parent) that the region adopts as its current content.\n const nodes: Node[] = [];\n if (initial !== undefined) {\n const seen = new Set<Node>();\n for (const part of flatten(initial)) {\n if (typeof part === \"string\" || seen.has(part) || part.parentNode !== parent) continue;\n seen.add(part);\n nodes.push(part);\n }\n }\n const marker = nodes.length > 0 ? (nodes[0] as Node).previousSibling : parent.lastChild;\n const region: Region = {\n parent,\n anchor: anchorNode,\n marker,\n nodes,\n texts: null,\n };\n for (const node of nodes) if (node instanceof Text) addText(region, node);\n // A region that adopts server nodes during a hydration pass is checked against its first commit.\n if (__DEV__ && initial !== undefined && claims.current.isClaiming()) region.claimed = nodes;\n return region;\n}\n\n/**\n * Called for a region that keeps changing and has no anchor. When the previous such region of the parent is alive\n * and ends exactly where this one starts, that region gets an empty Text node there as its anchor. Its content then\n * always goes before that node, and this region's marker is the node, so no region has a marker that a sibling\n * region can replace: the order of the calls holds however the regions change. A region with static content\n * between it and this one needs nothing, because its marker and its end are the static nodes. (A function of its\n * own, so the cleanup it registers holds nothing but the anchor: a closure made inside `bindRegion` would keep\n * the regions of that call alive as long as the parent's owner.)\n */\nfunction linkRegion(region: Region): void {\n const parent = region.parent;\n const tail = tails.get(parent);\n region.owner = currentOwner();\n tails.set(parent, region);\n const start = region.nodes[0] ?? null;\n if (tail === undefined || tail.owner?.disposed || endOf(tail, tail.nodes.at(-1)) !== start)\n return;\n const text = anchor(parent, start);\n tail.anchor = region.marker = text;\n // The anchor is the tail's alone and goes with it, so a region replaced by another one over and over adds\n // nothing to the parent. The region behind it, if empty, is then placed at the end like any region whose marker\n // is gone.\n if (tail.owner) addCleanup(tail.owner, () => text.remove());\n}\n\n/**\n * True when a function appears anywhere in `root`, at any array depth. Scans without calling\n * anything; `seen` stops it from looping on cyclic arrays (flatten reports those).\n */\nfunction containsFunction(root: unknown): boolean {\n if (typeof root === \"function\") return true;\n if (!Array.isArray(root)) return false;\n const stack: unknown[][] = [root];\n const seen = new Set<unknown[]>([root]);\n while (stack.length > 0) {\n const frame = stack.pop() as unknown[];\n for (const item of frame) {\n if (typeof item === \"function\") return true;\n if (Array.isArray(item) && !seen.has(item)) {\n seen.add(item);\n stack.push(item);\n }\n }\n }\n return false;\n}\n\n/**\n * Keeps a region in sync with `value`. A value that is or contains a function (an accessor, or an\n * array with accessor members) runs inside a render effect, so its reads are tracked. Anything\n * else is inserted once. `ordered` is for `insert()` without an anchor: a region that keeps changing then keeps\n * its place among the other such regions of its parent (see `linkRegion`).\n * @internal\n */\nexport function bindRegion(region: Region, value: unknown, ordered?: boolean): unknown {\n if (!containsFunction(value)) {\n commitValue(region, value);\n return value instanceof DocumentFragment ? [...region.nodes] : value;\n }\n let latest: unknown;\n if (ordered === true) linkRegion(region);\n const accessor = typeof value === \"function\" ? (value as () => unknown) : () => value;\n // Every accessor met while resolving the result is evaluated by a memo of its own, kept between\n // runs. An accessor that builds components (`() => show() ? <Late /> : null`) then runs again\n // only when what it reads changes, not whenever something it returned (the component's own\n // accessor, reading its own data) does.\n // Two stages. The outer effect runs the expression and tracks only what the expression itself\n // reads. When the result holds accessors (a component returned one, or `props.children` did),\n // a nested effect resolves them, so a change inside the result re-renders the result but never\n // re-runs the expression: re-running `() => props.children` would build the child components\n // again, discarding their state.\n useRenderEffect(accessor, (raw) => {\n latest = raw;\n if (containsFunction(raw)) {\n // One memo per accessor function, owned by this effect (the effect that evaluates the region's expression,\n // so a new result drops them all; the effect that resolves the result runs many times and must not own\n // them). The memos of accessors the last run did not meet are disposed, which bounds the cache by what the\n // region currently shows.\n const owner = currentOwner();\n const memos = new Map<() => unknown, ComputationNode>();\n let touched = new Set<() => unknown>();\n const call = (fn: () => unknown): unknown => {\n touched.add(fn);\n let node = memos.get(fn);\n if (node === undefined) {\n // Component setup runs inside these memos, which may write the state it owns.\n node = createComputation({ kind: \"memo\", fn: () => fn(), allowWrites: true, owner });\n memos.set(fn, node);\n }\n return readComputation(node);\n };\n useRenderEffect(\n () => {\n touched = new Set();\n const parts = flatten(raw, call);\n for (const [fn, node] of memos) {\n if (touched.has(fn)) continue;\n memos.delete(fn);\n disposeOwner(node);\n }\n return parts;\n },\n (parts) => {\n commit(region, parts);\n },\n );\n } else {\n commitValue(region, raw);\n }\n });\n return latest;\n}\n\n/**\n * Moves a region to a new parent: its nodes still in the old parent go through `move` (which puts\n * each at the end of `parent`), and later commits reconcile there. The region keeps its effects, so\n * what it shows is not built again. Only for a region without an anchor.\n * @param region The region to move.\n * @param parent The node that receives the region's nodes.\n * @param move Puts one node at the end of `parent` (`appendChild`, or `moveBefore` where it exists).\n * @since 1.0.3\n * @internal\n */\nexport function moveRegion(region: Region, parent: Node, move: (node: Node) => void): void {\n const attached = region.nodes.filter((node) => node.parentNode === region.parent);\n // A move that is not in place (appendChild) blurs a focused input: it gets the focus back.\n keepFocus(region.parent, () => {\n for (const node of attached) move(node);\n });\n // Read-only for everyone else: only a move changes where a region lives.\n (region as { parent: Node }).parent = parent;\n region.marker = attached[0]?.previousSibling ?? parent.lastChild;\n}\n\n/**\n * Removes a region's nodes from its parent. Anchors and nodes that were moved elsewhere are not\n * touched.\n * @internal\n */\nexport function removeRegion(region: Region): void {\n for (const node of region.nodes) {\n if (node.parentNode === region.parent) region.parent.removeChild(node);\n }\n region.nodes = [];\n region.texts = null;\n}\n\n/**\n * Creates a text anchor: an empty Text node placed before `before` (appended when null). Use it as\n * the stable insertion point between two dynamic regions; it is never removed by the runtime.\n *\n * @param parent Node that receives the anchor.\n * @param before Node the anchor goes before, or null to append.\n * @returns The new empty Text node.\n * @example\n * import { anchor, insert } from \"@shadow-js/web\";\n *\n * const list = document.createElement(\"ul\");\n * const slot = anchor(list, null);\n * insert(list, \"first\", slot); // goes before the anchor\n * @see insert\n * @since 1.0.0\n */\nexport function anchor(parent: Node, before: Node | null): Text {\n const text = documentOf(parent).createTextNode(\"\");\n parent.insertBefore(text, before);\n return text;\n}\n\n/**\n * Reactive child insertion: keeps the content of a region in sync with `value`.\n *\n * - A function is an accessor, wrapped in a render effect; it re-runs when its dependencies change.\n * - `null`, `undefined`, booleans render nothing. Strings and numbers become one Text node, reused\n * when the region already holds one. A Node is inserted itself. A DocumentFragment inserts a\n * snapshot of its children. Arrays are flattened, nested arrays included.\n * - Content goes before `anchorNode`, or at the end when it is null or omitted. Regions without an\n * anchor on one parent keep the order of the calls, whatever they show and however often a sibling\n * region replaces its nodes: when a reactive region is created right where the previous one ends, the\n * previous one gets an empty Text node as its anchor there (removed again when that region is disposed).\n * - Arrays are reconciled in place: nodes that remain are never removed and re-added.\n * - `initial` lists nodes already in the DOM (from hydration or splitText) so nothing is recreated.\n * - During `hydrate()`, a region that adopted server text is compared with its first commit: in\n * development, different text warns `HYDRATION_TEXT_MISMATCH` (on the console and in devtools) and\n * the region shows the value computed by the client.\n *\n * @param parent Node that holds the region.\n * @param value The value or an accessor returning it.\n * @param anchorNode Node the content goes before; null or omitted appends.\n * @param initial Nodes already in place for this region. Undefined adopts the server's nodes while\n * hydrating and starts empty otherwise.\n * @returns The value as accepted (a fragment yields the array of its nodes).\n * @throws TypeError (production message `SHADOW_INSERT_CYCLE`) when an array contains itself, and\n * (`SHADOW_INSERT_DEPTH`) when an accessor returns accessors more than 10,000 levels deep. When the\n * value is reactive, the error is raised inside its render effect and goes to the owner's error\n * handler, like any effect error.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { anchor, insert } from \"@shadow-js/web\";\n *\n * const list = document.createElement(\"ul\");\n * const end = anchor(list, null);\n * const [items] = useSignal([\"a\", \"b\"]);\n * insert(list, () => items().map((name) => document.createTextNode(name)), end);\n * @see anchor\n * @since 1.0.0\n */\nexport function insert(\n parent: Node,\n value: unknown,\n anchorNode?: Node | null,\n initial?: unknown,\n): unknown {\n const resolvedAnchor = anchorNode ?? null;\n const adopted =\n initial === undefined ? claims.current.takeRegion(parent, resolvedAnchor) : initial;\n const region = createRegion(parent, resolvedAnchor, adopted);\n return bindRegion(region, value, resolvedAnchor === null);\n}\n"],"mappings":";;;;;;;;AA+CA,MAAM,wBAAQ,IAAI,QAAsB;;AAGxC,SAAS,WAAW,MAAsB;CACxC,OAAO,gBAAgB,WAAW,OAAQ,KAAK,iBAAiB;AAClE;;AAGA,SAAS,SAAS,QAAgB,MAAqB;CACrD,MAAM,QAAQ,OAAO;CACrB,OAAO,UAAU,QAAS,iBAAiB,OAAO,MAAM,IAAI,IAAY;AAC1E;;AAGA,SAAS,QAAQ,QAAgB,MAAkB;CACjD,MAAM,QAAQ,OAAO;CACrB,IAAI,UAAU,MAAM,OAAO,QAAQ;MAC9B,IAAI,iBAAiB,KAAK,MAAM,IAAI,IAAI;MACxC,IAAI,UAAU,MAAM,OAAO,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CACF;EACF,OACE,YAAY,QAAQ,GAAG;CAE3B,CAAC;CACD,OAAO;AACT;;;;;;;;;;;AAYA,SAAgB,WAAW,QAAgB,QAAc,MAAkC;CACzF,MAAM,WAAW,OAAO,MAAM,QAAQ,SAAS,KAAK,eAAe,OAAO,MAAM;CAEhF,UAAU,OAAO,cAAc;EAC7B,KAAK,MAAM,QAAQ,UAAU,KAAK,IAAI;CACxC,CAAC;CAED,OAA6B,SAAS;CACtC,OAAO,SAAS,SAAS,EAAE,EAAE,mBAAmB,OAAO;AACzD;;;;;;AAOA,SAAgB,aAAa,QAAsB;CACjD,KAAK,MAAM,QAAQ,OAAO,OACxB,IAAI,KAAK,eAAe,OAAO,QAAQ,OAAO,OAAO,YAAY,IAAI;CAEvE,OAAO,QAAQ,CAAC;CAChB,OAAO,QAAQ;AACjB;;;;;;;;;;;;;;;;;AAkBA,SAAgB,OAAO,QAAc,QAA2B;CAC9D,MAAM,OAAO,WAAW,MAAM,CAAC,CAAC,eAAe,EAAE;CACjD,OAAO,aAAa,MAAM,MAAM;CAChC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,OACd,QACA,OACA,YACA,SACS;CACT,MAAM,iBAAiB,cAAc;CAIrC,OAAO,WADQ,aAAa,QAAQ,gBADlC,YAAY,KAAA,IAAY,OAAO,QAAQ,WAAW,QAAQ,cAAc,IAAI,OAEvD,GAAG,OAAO,mBAAmB,IAAI;AAC1D"}
|
|
1
|
+
{"version":3,"file":"insert.js","names":[],"sources":["../../src/insert.ts"],"sourcesContent":["import { onCleanup, useRenderEffect } from \"@shadow-js/core\";\nimport {\n addCleanup,\n type ComputationNode,\n createComputation,\n currentOwner,\n disposeOwner,\n type Owner,\n readComputation,\n} from \"@shadow-js/core/extend\";\nimport { leaves } from \"./internal/accessor\";\nimport { checkClaimedText } from \"./internal/claim\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { keepFocus, reconcileNodes } from \"./internal/reconcile\";\n\n/** One piece of a value after flattening: a DOM node, or text to be turned into a Text node. */\ntype Part = Node | string;\n\n/**\n * State of one dynamic child region. `nodes` are the DOM nodes the region owns, in order. When\n * `anchor` is set, content goes before it. Without one, an empty region is placed after `marker`\n * (the node that preceded it), so it keeps its position while it is empty. A marker can be a node\n * another region owns and later replaces, so the region created right behind another one on the same parent\n * gives that one an anchor of its own (see `linkRegion`): the marker of every region is then either static\n * content or an anchor nobody replaces.\n * @internal\n */\nexport interface Region {\n readonly parent: Node;\n anchor: Node | null;\n marker: Node | null;\n /** The owner of the effect that keeps a reactive region up to date; unset until then (and for a static region). */\n owner?: Owner | null;\n nodes: Node[];\n /**\n * Text nodes this region created or adopted; only these may be reused by string updates. Null for none, the node\n * itself for one (the usual region: a single dynamic text), a Set for more, so most regions allocate no Set.\n */\n texts: Text | Set<Text> | null;\n /**\n * Development only: the server nodes a hydration pass handed this region, kept until its first\n * commit compares their text with the value (`checkClaimedText`).\n */\n claimed?: readonly Node[] | undefined;\n}\n\n/** The newest reactive unanchored region of each parent: the one the next such region may have to give an anchor. */\nconst tails = new WeakMap<Node, Region>();\n\n/** The document a node belongs to (a Document is its own document). */\nfunction documentOf(node: Node): Document {\n return node instanceof Document ? node : (node.ownerDocument ?? document);\n}\n\n/** True when the region created or adopted `node`. */\nfunction ownsText(region: Region, node: Node): boolean {\n const texts = region.texts;\n return texts === node || (texts instanceof Set && texts.has(node as Text));\n}\n\n/** Records that the region owns `text`. */\nfunction addText(region: Region, text: Text): void {\n const texts = region.texts;\n if (texts === null) region.texts = text;\n else if (texts instanceof Set) texts.add(text);\n else if (texts !== text) region.texts = new Set([texts, text]);\n}\n\n/** Forgets the Text nodes of the region that are not in `keep`. */\nfunction pruneTexts(region: Region, keep: readonly Node[]): void {\n const texts = region.texts;\n if (texts === null) return;\n if (texts instanceof Set) {\n const kept = new Set<Node>(keep);\n for (const text of texts) {\n if (!kept.has(text)) texts.delete(text);\n }\n } else if (!keep.includes(texts)) region.texts = null;\n}\n\n/**\n * The children a fragment held when it was first inserted. Inserting empties a fragment, and an effect\n * that runs again flattens the same fragment value once more: it must still give those nodes.\n */\nconst fragmentChildren = new WeakMap<DocumentFragment, Node[]>();\n\n/**\n * Flattens a value into parts without recursion. Functions are called (and their results unwrapped)\n * through `call`, which runs inside the render effect that owns the value, so reads are tracked.\n */\nfunction flatten(root: unknown, call?: (fn: () => unknown) => unknown): Part[] {\n const parts: Part[] = [];\n const cycle = __DEV__ ? \"insert(): a value contains itself.\" : \"SHADOW_INSERT_CYCLE\";\n for (const item of leaves(root, cycle, call)) {\n if (item === null || item === undefined || typeof item === \"boolean\") continue;\n if (item instanceof DocumentFragment) {\n const kids = fragmentChildren.get(item) ?? [...item.childNodes];\n fragmentChildren.set(item, kids);\n for (const child of kids) parts.push(child);\n } else parts.push(item instanceof Node ? item : String(item)); // strings, numbers and anything else that is text\n }\n return parts;\n}\n\n/** Text nodes the region currently owns, keyed by their data, for reuse by equal strings. */\nfunction reusablePool(region: Region): Map<string, Text[]> {\n const pool = new Map<string, Text[]>();\n for (const node of region.nodes) {\n if (!(node instanceof Text) || !ownsText(region, node)) continue;\n const list = pool.get(node.data);\n if (list === undefined) pool.set(node.data, [node]);\n else list.push(node);\n }\n return pool;\n}\n\n/** Turns parts into the nodes the region should hold, reusing its own Text nodes where possible. */\nfunction materialize(region: Region, parts: readonly Part[]): Node[] {\n const only = parts.length === 1 ? parts[0] : undefined;\n if (typeof only === \"string\") {\n const current = region.nodes.length === 1 ? region.nodes[0] : undefined;\n if (current instanceof Text && ownsText(region, current)) {\n if (current.data !== only) current.data = only;\n return [current];\n }\n }\n // Sized to the parts: `[]` and `push` would reserve room for sixteen nodes in every dynamic child (a row has two).\n const nodes: Node[] = new Array<Node>(parts.length);\n let count = 0;\n const seen = new Set<Node>();\n let pool: Map<string, Text[]> | undefined;\n for (const part of parts) {\n if (typeof part === \"string\") {\n pool ??= reusablePool(region);\n const reused = pool.get(part)?.pop();\n let text = reused;\n if (text === undefined) {\n text = documentOf(region.parent).createTextNode(part);\n addText(region, text);\n }\n seen.add(text);\n nodes[count] = text;\n count += 1;\n } else if (!seen.has(part)) {\n seen.add(part);\n nodes[count] = part;\n count += 1;\n }\n }\n nodes.length = count;\n return nodes;\n}\n\n/** The node after the region: its anchor, or the node after its last attached child (`last`), or its marker. */\nfunction endOf(region: Region, last: Node | undefined): Node | null {\n if (region.anchor !== null) return region.anchor;\n if (last !== undefined) return last.nextSibling;\n const marker = region.marker;\n if (marker === null) return region.parent.firstChild;\n if (marker.parentNode !== region.parent) return null;\n return marker.nextSibling;\n}\n\n/** Callbacks to run after a region of a parent has committed (see `watchCommits`). */\nconst commitWatchers = new WeakMap<Node, Set<() => void>>();\n\n/**\n * Runs `run` after every commit to a region of `parent`, so code that depends on which nodes the\n * parent holds (a name on the first element of a content region) can follow a change of content.\n * The watch ends with the owner that is current when this is called.\n * @internal\n */\nexport function watchCommits(parent: Node, run: () => void): void {\n const set = commitWatchers.get(parent) ?? new Set<() => void>();\n commitWatchers.set(parent, set.add(run));\n onCleanup(() => {\n set.delete(run);\n });\n}\n\n/**\n * Like {@link watchCommits}, for a watch that lives as long as `parent` does: it is not tied to the owner that is\n * current, so a binding that runs again does not end it. The select's value (see `setSelectValue`) uses it.\n * @internal\n */\nexport function keepWatchingCommits(parent: Node, run: () => void): void {\n commitWatchers.set(parent, (commitWatchers.get(parent) ?? new Set<() => void>()).add(run));\n}\n\n/** Applies a flattened value to a region. */\nfunction commit(region: Region, parts: readonly Part[]): void {\n if (__DEV__ && region.claimed !== undefined) {\n // Only the first commit of a claimed region is compared; later changes are ordinary updates.\n checkClaimedText(region.claimed, parts);\n region.claimed = undefined;\n }\n // Makes the DOM show the new nodes for this region.\n const next = materialize(region, parts);\n const parent = region.parent;\n const attached = region.nodes.filter((node) => node.parentNode === parent);\n const first = attached[0];\n const end = endOf(region, attached.at(-1));\n if (next.length === 0 && first !== undefined) region.marker = first.previousSibling;\n reconcileNodes(parent, attached, next, end);\n region.nodes = next;\n pruneTexts(region, next);\n commitWatchers.get(parent)?.forEach((run) => {\n run();\n });\n // The options of an optgroup are the select's options.\n if (parent.nodeName === \"OPTGROUP\" && parent.parentNode !== null) {\n commitWatchers.get(parent.parentNode)?.forEach((run) => {\n run();\n });\n }\n}\n\n/**\n * Applies a resolved value to a region. A string or number is the common case (a dynamic text): when the region\n * already shows its own Text node only the data is rewritten, and an empty region gets one new Text node, with none of\n * the flattening and reconciling a general value needs.\n */\nfunction commitValue(region: Region, raw: unknown): void {\n if ((typeof raw === \"string\" || typeof raw === \"number\") && !(__DEV__ && region.claimed)) {\n const nodes = region.nodes;\n const text = String(raw);\n if (nodes.length === 1) {\n const current = nodes[0];\n if (\n current instanceof Text &&\n current.parentNode === region.parent &&\n ownsText(region, current)\n ) {\n if (current.data !== text) current.data = text;\n return;\n }\n } else if (nodes.length === 0) {\n const created = documentOf(region.parent).createTextNode(text);\n addText(region, created);\n region.parent.insertBefore(created, endOf(region, undefined));\n region.nodes = [created];\n return;\n }\n }\n commit(region, flatten(raw));\n}\n\n/**\n * Creates the state of a region in `parent`. `anchorNode` (null to append) and `initial` (nodes\n * already in the DOM, from hydration or splitText) are both optional.\n * @internal\n */\nexport function createRegion(parent: Node, anchorNode: Node | null, initial: unknown): Region {\n // The nodes of `initial` (already in the parent) that the region adopts as its current content.\n const nodes: Node[] = [];\n if (initial !== undefined) {\n const seen = new Set<Node>();\n for (const part of flatten(initial)) {\n if (typeof part === \"string\" || seen.has(part) || part.parentNode !== parent) continue;\n seen.add(part);\n nodes.push(part);\n }\n }\n const marker = nodes.length > 0 ? (nodes[0] as Node).previousSibling : parent.lastChild;\n const region: Region = {\n parent,\n anchor: anchorNode,\n marker,\n nodes,\n texts: null,\n };\n for (const node of nodes) if (node instanceof Text) addText(region, node);\n // A region that adopts server nodes during a hydration pass is checked against its first commit.\n if (__DEV__ && initial !== undefined && claims.current.isClaiming()) region.claimed = nodes;\n return region;\n}\n\n/**\n * Called for a region that keeps changing and has no anchor. When the previous such region of the parent is alive\n * and ends exactly where this one starts, that region gets an empty Text node there as its anchor. Its content then\n * always goes before that node, and this region's marker is the node, so no region has a marker that a sibling\n * region can replace: the order of the calls holds however the regions change. A region with static content\n * between it and this one needs nothing, because its marker and its end are the static nodes. (A function of its\n * own, so the cleanup it registers holds nothing but the anchor: a closure made inside `bindRegion` would keep\n * the regions of that call alive as long as the parent's owner.)\n */\nfunction linkRegion(region: Region): void {\n const parent = region.parent;\n const tail = tails.get(parent);\n region.owner = currentOwner();\n tails.set(parent, region);\n const start = region.nodes[0] ?? null;\n if (tail === undefined || tail.owner?.disposed || endOf(tail, tail.nodes.at(-1)) !== start)\n return;\n const text = anchor(parent, start);\n tail.anchor = region.marker = text;\n // The anchor is the tail's alone and goes with it, so a region replaced by another one over and over adds\n // nothing to the parent. The region behind it, if empty, is then placed at the end like any region whose marker\n // is gone.\n if (tail.owner) addCleanup(tail.owner, () => text.remove());\n}\n\n/**\n * True when a function appears anywhere in `root`, at any array depth. Scans without calling\n * anything; `seen` stops it from looping on cyclic arrays (flatten reports those).\n */\nfunction containsFunction(root: unknown): boolean {\n if (typeof root === \"function\") return true;\n if (!Array.isArray(root)) return false;\n const stack: unknown[][] = [root];\n const seen = new Set<unknown[]>([root]);\n while (stack.length > 0) {\n const frame = stack.pop() as unknown[];\n for (const item of frame) {\n if (typeof item === \"function\") return true;\n if (Array.isArray(item) && !seen.has(item)) {\n seen.add(item);\n stack.push(item);\n }\n }\n }\n return false;\n}\n\n/**\n * Keeps a region in sync with `value`. A value that is or contains a function (an accessor, or an\n * array with accessor members) runs inside a render effect, so its reads are tracked. Anything\n * else is inserted once. `ordered` is for `insert()` without an anchor: a region that keeps changing then keeps\n * its place among the other such regions of its parent (see `linkRegion`).\n * @internal\n */\nexport function bindRegion(region: Region, value: unknown, ordered?: boolean): unknown {\n if (!containsFunction(value)) {\n commitValue(region, value);\n return value instanceof DocumentFragment ? [...region.nodes] : value;\n }\n let latest: unknown;\n if (ordered === true) linkRegion(region);\n const accessor = typeof value === \"function\" ? (value as () => unknown) : () => value;\n // Every accessor met while resolving the result is evaluated by a memo of its own, kept between\n // runs. An accessor that builds components (`() => show() ? <Late /> : null`) then runs again\n // only when what it reads changes, not whenever something it returned (the component's own\n // accessor, reading its own data) does.\n // Two stages. The outer effect runs the expression and tracks only what the expression itself\n // reads. When the result holds accessors (a component returned one, or `props.children` did),\n // a nested effect resolves them, so a change inside the result re-renders the result but never\n // re-runs the expression: re-running `() => props.children` would build the child components\n // again, discarding their state.\n useRenderEffect(accessor, (raw) => {\n latest = raw;\n if (containsFunction(raw)) {\n // One memo per accessor function, owned by this effect (the effect that evaluates the region's expression,\n // so a new result drops them all; the effect that resolves the result runs many times and must not own\n // them). The memos of accessors the last run did not meet are disposed, which bounds the cache by what the\n // region currently shows.\n const owner = currentOwner();\n const memos = new Map<() => unknown, ComputationNode>();\n let touched = new Set<() => unknown>();\n const call = (fn: () => unknown): unknown => {\n touched.add(fn);\n let node = memos.get(fn);\n if (node === undefined) {\n // Component setup runs inside these memos, which may write the state it owns.\n node = createComputation({ kind: \"memo\", fn: () => fn(), allowWrites: true, owner });\n memos.set(fn, node);\n }\n return readComputation(node);\n };\n useRenderEffect(\n () => {\n touched = new Set();\n const parts = flatten(raw, call);\n for (const [fn, node] of memos) {\n if (touched.has(fn)) continue;\n memos.delete(fn);\n disposeOwner(node);\n }\n return parts;\n },\n (parts) => {\n commit(region, parts);\n },\n );\n } else {\n commitValue(region, raw);\n }\n });\n return latest;\n}\n\n/**\n * Moves a region to a new parent: its nodes still in the old parent go through `move` (which puts\n * each at the end of `parent`), and later commits reconcile there. The region keeps its effects, so\n * what it shows is not built again. Only for a region without an anchor.\n * @param region The region to move.\n * @param parent The node that receives the region's nodes.\n * @param move Puts one node at the end of `parent` (`appendChild`, or `moveBefore` where it exists).\n * @since 1.0.3\n * @internal\n */\nexport function moveRegion(region: Region, parent: Node, move: (node: Node) => void): void {\n const attached = region.nodes.filter((node) => node.parentNode === region.parent);\n // A move that is not in place (appendChild) blurs a focused input: it gets the focus back.\n keepFocus(region.parent, () => {\n for (const node of attached) move(node);\n });\n // Read-only for everyone else: only a move changes where a region lives.\n (region as { parent: Node }).parent = parent;\n region.marker = attached[0]?.previousSibling ?? parent.lastChild;\n}\n\n/**\n * Removes a region's nodes from its parent. Anchors and nodes that were moved elsewhere are not\n * touched.\n * @internal\n */\nexport function removeRegion(region: Region): void {\n for (const node of region.nodes) {\n if (node.parentNode === region.parent) region.parent.removeChild(node);\n }\n region.nodes = [];\n region.texts = null;\n}\n\n/**\n * Creates a text anchor: an empty Text node placed before `before` (appended when null). Use it as\n * the stable insertion point between two dynamic regions; it is never removed by the runtime.\n *\n * @param parent Node that receives the anchor.\n * @param before Node the anchor goes before, or null to append.\n * @returns The new empty Text node.\n * @example\n * import { anchor, insert } from \"@shadow-js/web\";\n *\n * const list = document.createElement(\"ul\");\n * const slot = anchor(list, null);\n * insert(list, \"first\", slot); // goes before the anchor\n * @see insert\n * @since 1.0.0\n */\nexport function anchor(parent: Node, before: Node | null): Text {\n const text = documentOf(parent).createTextNode(\"\");\n parent.insertBefore(text, before);\n return text;\n}\n\n/**\n * Reactive child insertion: keeps the content of a region in sync with `value`.\n *\n * - A function is an accessor, wrapped in a render effect; it re-runs when its dependencies change.\n * - `null`, `undefined`, booleans render nothing. Strings and numbers become one Text node, reused\n * when the region already holds one. A Node is inserted itself. A DocumentFragment inserts a\n * snapshot of its children. Arrays are flattened, nested arrays included.\n * - Content goes before `anchorNode`, or at the end when it is null or omitted. Regions without an\n * anchor on one parent keep the order of the calls, whatever they show and however often a sibling\n * region replaces its nodes: when a reactive region is created right where the previous one ends, the\n * previous one gets an empty Text node as its anchor there (removed again when that region is disposed).\n * - Arrays are reconciled in place: nodes that remain are never removed and re-added.\n * - `initial` lists nodes already in the DOM (from hydration or splitText) so nothing is recreated.\n * - During `hydrate()`, a region that adopted server text is compared with its first commit: in\n * development, different text warns `HYDRATION_TEXT_MISMATCH` (on the console and in devtools) and\n * the region shows the value computed by the client.\n *\n * @param parent Node that holds the region.\n * @param value The value or an accessor returning it.\n * @param anchorNode Node the content goes before; null or omitted appends.\n * @param initial Nodes already in place for this region. Undefined adopts the server's nodes while\n * hydrating and starts empty otherwise.\n * @returns The value as accepted (a fragment yields the array of its nodes).\n * @throws TypeError (production message `SHADOW_INSERT_CYCLE`) when an array contains itself, and\n * (`SHADOW_INSERT_DEPTH`) when an accessor returns accessors more than 10,000 levels deep. When the\n * value is reactive, the error is raised inside its render effect and goes to the owner's error\n * handler, like any effect error.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { anchor, insert } from \"@shadow-js/web\";\n *\n * const list = document.createElement(\"ul\");\n * const end = anchor(list, null);\n * const [items] = useSignal([\"a\", \"b\"]);\n * insert(list, () => items().map((name) => document.createTextNode(name)), end);\n * @see anchor\n * @since 1.0.0\n */\nexport function insert(\n parent: Node,\n value: unknown,\n anchorNode?: Node | null,\n initial?: unknown,\n): unknown {\n const resolvedAnchor = anchorNode ?? null;\n const adopted =\n initial === undefined ? claims.current.takeRegion(parent, resolvedAnchor) : initial;\n const region = createRegion(parent, resolvedAnchor, adopted);\n return bindRegion(region, value, resolvedAnchor === null);\n}\n"],"mappings":";;;;;;;;AA+CA,MAAM,wBAAQ,IAAI,QAAsB;;AAGxC,SAAS,WAAW,MAAsB;CACxC,OAAO,gBAAgB,WAAW,OAAQ,KAAK,iBAAiB;AAClE;;AAGA,SAAS,SAAS,QAAgB,MAAqB;CACrD,MAAM,QAAQ,OAAO;CACrB,OAAO,UAAU,QAAS,iBAAiB,OAAO,MAAM,IAAI,IAAY;AAC1E;;AAGA,SAAS,QAAQ,QAAgB,MAAkB;CACjD,MAAM,QAAQ,OAAO;CACrB,IAAI,UAAU,MAAM,OAAO,QAAQ;MAC9B,IAAI,iBAAiB,KAAK,MAAM,IAAI,IAAI;MACxC,IAAI,UAAU,MAAM,OAAO,wBAAQ,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC;AAC/D;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
|
|
3
|
-
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
4
1
|
import { attachRootErrors } from "./control-flow/root-errors.js";
|
|
2
|
+
import { bindRegion, createRegion, removeRegion } from "./insert.js";
|
|
3
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
4
|
+
import { withScope } from "./internal/hydration-scope.js";
|
|
5
5
|
import { batch, createRoot, flushSync, untrack } from "@shadow-js/core";
|
|
6
6
|
// src/render.ts
|
|
7
7
|
/**
|
|
@@ -32,19 +32,30 @@ import { batch, createRoot, flushSync, untrack } from "@shadow-js/core";
|
|
|
32
32
|
*/
|
|
33
33
|
function render(code, container, options) {
|
|
34
34
|
const region = createRegion(container, null, void 0);
|
|
35
|
-
|
|
36
|
-
if (options !== void 0) attachRootErrors(options);
|
|
37
|
-
bindRegion(region, untrack(code));
|
|
38
|
-
return dispose;
|
|
39
|
-
}))));
|
|
40
|
-
flushSync();
|
|
35
|
+
let stop;
|
|
41
36
|
let disposed = false;
|
|
42
|
-
|
|
37
|
+
const teardown = () => {
|
|
43
38
|
if (disposed) return;
|
|
44
39
|
disposed = true;
|
|
45
|
-
stop();
|
|
40
|
+
stop?.();
|
|
46
41
|
removeRegion(region);
|
|
47
42
|
};
|
|
43
|
+
try {
|
|
44
|
+
claims.current.withoutClaiming(() => withScope(null, () => batch(() => createRoot((dispose) => {
|
|
45
|
+
stop = dispose;
|
|
46
|
+
if (options !== void 0) attachRootErrors(options);
|
|
47
|
+
bindRegion(region, untrack(code));
|
|
48
|
+
}))));
|
|
49
|
+
flushSync();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
try {
|
|
52
|
+
teardown();
|
|
53
|
+
} catch (cleanupError) {
|
|
54
|
+
throw new AggregateError([error, cleanupError], "render() failed and so did its teardown.");
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
return teardown;
|
|
48
59
|
}
|
|
49
60
|
export { render };
|
|
50
61
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":[],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../../src/render.ts"],"sourcesContent":["import { batch, createRoot, flushSync, untrack } from \"@shadow-js/core\";\nimport { attachRootErrors, type RootErrorOptions } from \"./control-flow/root-errors\";\nimport { bindRegion, createRegion, removeRegion } from \"./insert\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { withScope } from \"./internal/hydration-scope\";\n\n/**\n * Options of {@link render}: the error reporters of the root.\n * @since 1.0.0\n */\nexport type RenderOptions = RootErrorOptions;\n\n/**\n * Mounts `code` into `container`. Creates an owner, inserts the output, flushes the effects, and\n * returns a dispose function that stops the owner and removes the nodes this call inserted. A\n * second render into the same container appends after the first.\n *\n * @param code Runs once, untracked, to build the tree (a component call, a node, text or an array).\n * Return an accessor (for example `() => count`) from it to make the root content reactive.\n * @param container Element, Document or DocumentFragment that receives the output.\n * @param options The root's error reporters (`onUncaughtError`, `onCaughtError`). Undefined sets\n * no reporter.\n * @returns A dispose function, safe to call more than once.\n * @example\n * import { createComponent, render } from \"@shadow-js/web\";\n *\n * function App() {\n * return \"Hello\";\n * }\n *\n * const dispose = render(\n * () => createComponent(App, {}),\n * document.getElementById(\"root\") as Element,\n * );\n * dispose(); // stops the root and removes the text it inserted\n * @see hydrate\n * @since 1.0.0\n */\nexport function render(\n code: () => unknown,\n container: Element | Document | DocumentFragment,\n options?: RenderOptions,\n): () => void {\n const region = createRegion(container, null, undefined);\n let stop: (() => void) | undefined;\n let disposed = false;\n const teardown = (): void => {\n if (disposed) return;\n disposed = true;\n stop?.();\n removeRegion(region);\n };\n // One batch around the build: effects (and anything a resource's batch would flush mid-build)\n // wait until the whole tree exists, so a Suspense boundary knows what is pending before its\n // content's effects are considered.\n // A fresh root never consumes the enclosing hydration pass's nodes or key sequence.\n try {\n claims.current.withoutClaiming(() =>\n withScope(null, () =>\n batch(() =>\n createRoot((dispose) => {\n stop = dispose;\n // An error nothing else took ends here; with onUncaughtError it is reported instead of thrown.\n if (options !== undefined) attachRootErrors(options);\n // The component tree is built once; only accessors inside the result stay reactive.\n bindRegion(region, untrack(code));\n }),\n ),\n ),\n );\n flushSync();\n } catch (error) {\n // The caller gets no dispose function from a render that throws (an effect of the first flush failed),\n // so the root must not stay alive with its DOM and effects.\n try {\n teardown();\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n __DEV__ ? \"render() failed and so did its teardown.\" : \"SHADOW_RENDER_ERRORS\",\n );\n }\n throw error;\n }\n return teardown;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,OACd,MACA,WACA,SACY;CACZ,MAAM,SAAS,aAAa,WAAW,MAAM,KAAA,CAAS;CACtD,IAAI;CACJ,IAAI,WAAW;CACf,MAAM,iBAAuB;EAC3B,IAAI,UAAU;EACd,WAAW;EACX,OAAO;EACP,aAAa,MAAM;CACrB;CAKA,IAAI;EACF,OAAO,QAAQ,sBACb,UAAU,YACR,YACE,YAAY,YAAY;GACtB,OAAO;GAEP,IAAI,YAAY,KAAA,GAAW,iBAAiB,OAAO;GAEnD,WAAW,QAAQ,QAAQ,IAAI,CAAC;EAClC,CAAC,CACH,CACF,CACF;EACA,UAAU;CACZ,SAAS,OAAO;EAGd,IAAI;GACF,SAAS;EACX,SAAS,cAAc;GACrB,MAAM,IAAI,eACR,CAAC,OAAO,YAAY,GACV,0CACZ;EACF;EACA,MAAM;CACR;CACA,OAAO;AACT"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { keepWatchingCommits } from "./insert.js";
|
|
1
2
|
// src/select-value.ts
|
|
3
|
+
/** The value each select was last given, which it takes again when its options change (see {@link setSelectValue}). */
|
|
4
|
+
const bound = /* @__PURE__ */ new WeakMap();
|
|
2
5
|
/** The values an array stands for, as strings; null and undefined entries are skipped. */
|
|
3
6
|
function listed(value) {
|
|
4
7
|
return new Set(value.filter((item) => item !== null && item !== void 0).map(String));
|
|
@@ -11,7 +14,9 @@ function plainText(value) {
|
|
|
11
14
|
* Selects the options a `value` stands for. The compiler calls it for `<select value={...}>`. A
|
|
12
15
|
* single value behaves like `select.value = value` (`null` and `undefined` are the empty string).
|
|
13
16
|
* On a `<select multiple>` an array selects exactly the options whose value it lists and clears
|
|
14
|
-
* the others. The server writes the same state as `selected` on the options (`ssrSelectValue`).
|
|
17
|
+
* the others. The server writes the same state as `selected` on the options (`ssrSelectValue`). The select
|
|
18
|
+
* takes the value again whenever the nodes inside it change (the options of a `<For>`, a `<Show>` or an optgroup), so
|
|
19
|
+
* options that arrive or are replaced after the value keep it selected.
|
|
15
20
|
*
|
|
16
21
|
* @param select The select element; its options must already be in it.
|
|
17
22
|
* @param value A string or number (written as `String(value)`), or `null`/`undefined` (written as
|
|
@@ -28,6 +33,11 @@ function plainText(value) {
|
|
|
28
33
|
* @since 1.0.0
|
|
29
34
|
*/
|
|
30
35
|
function setSelectValue(select, value) {
|
|
36
|
+
if (!bound.has(select)) keepWatchingCommits(select, () => apply(select, bound.get(select)));
|
|
37
|
+
bound.set(select, value);
|
|
38
|
+
apply(select, value);
|
|
39
|
+
}
|
|
40
|
+
function apply(select, value) {
|
|
31
41
|
if (select.multiple && Array.isArray(value)) {
|
|
32
42
|
const wanted = listed(value);
|
|
33
43
|
for (const option of Array.from(select.options)) option.selected = wanted.has(option.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-value.js","names":[],"sources":["../../src/select-value.ts"],"sourcesContent":["/** The values an array stands for, as strings; null and undefined entries are skipped. */\nfunction listed(value: readonly unknown[]): Set<string> {\n return new Set(value.filter((item) => item !== null && item !== undefined).map(String));\n}\n\n/** The string a value assigns to `select.value`, `innerHTML` or `textContent`; null and undefined are empty. @internal */\nexport function plainText(value: unknown): string {\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Selects the options a `value` stands for. The compiler calls it for `<select value={...}>`. A\n * single value behaves like `select.value = value` (`null` and `undefined` are the empty string).\n * On a `<select multiple>` an array selects exactly the options whose value it lists and clears\n * the others. The server writes the same state as `selected` on the options (`ssrSelectValue`).\n *\n * @param select The select element; its options must already be in it.\n * @param value A string or number (written as `String(value)`), or `null`/`undefined` (written as\n * `\"\"`: an option with an empty value is selected, otherwise none). For a `multiple` select, an array of them: `null` and `undefined`\n * entries are skipped. An array on a single select is written as `String(array)`.\n * @example\n * import { setSelectValue } from \"@shadow-js/web\";\n *\n * const select = document.createElement(\"select\");\n * select.multiple = true;\n * select.append(new Option(\"A\", \"a\"), new Option(\"B\", \"b\"), new Option(\"C\", \"c\"));\n * setSelectValue(select, [\"a\", \"c\"]); // A and C selected, B cleared\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function setSelectValue(select: HTMLSelectElement, value: unknown): void {\n if (select.multiple && Array.isArray(value)) {\n const wanted = listed(value);\n for (const option of Array.from(select.options)) option.selected = wanted.has(option.value);\n return;\n }\n select.value = plainText(value);\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"select-value.js","names":[],"sources":["../../src/select-value.ts"],"sourcesContent":["import { keepWatchingCommits } from \"./insert\";\n\n/** The value each select was last given, which it takes again when its options change (see {@link setSelectValue}). */\nconst bound = new WeakMap<HTMLSelectElement, unknown>();\n\n/** The values an array stands for, as strings; null and undefined entries are skipped. */\nfunction listed(value: readonly unknown[]): Set<string> {\n return new Set(value.filter((item) => item !== null && item !== undefined).map(String));\n}\n\n/** The string a value assigns to `select.value`, `innerHTML` or `textContent`; null and undefined are empty. @internal */\nexport function plainText(value: unknown): string {\n return value === null || value === undefined ? \"\" : String(value);\n}\n\n/**\n * Selects the options a `value` stands for. The compiler calls it for `<select value={...}>`. A\n * single value behaves like `select.value = value` (`null` and `undefined` are the empty string).\n * On a `<select multiple>` an array selects exactly the options whose value it lists and clears\n * the others. The server writes the same state as `selected` on the options (`ssrSelectValue`). The select\n * takes the value again whenever the nodes inside it change (the options of a `<For>`, a `<Show>` or an optgroup), so\n * options that arrive or are replaced after the value keep it selected.\n *\n * @param select The select element; its options must already be in it.\n * @param value A string or number (written as `String(value)`), or `null`/`undefined` (written as\n * `\"\"`: an option with an empty value is selected, otherwise none). For a `multiple` select, an array of them: `null` and `undefined`\n * entries are skipped. An array on a single select is written as `String(array)`.\n * @example\n * import { setSelectValue } from \"@shadow-js/web\";\n *\n * const select = document.createElement(\"select\");\n * select.multiple = true;\n * select.append(new Option(\"A\", \"a\"), new Option(\"B\", \"b\"), new Option(\"C\", \"c\"));\n * setSelectValue(select, [\"a\", \"c\"]); // A and C selected, B cleared\n * @see ssrSelectValue\n * @since 1.0.0\n */\nexport function setSelectValue(select: HTMLSelectElement, value: unknown): void {\n // Options that arrive or are replaced after this call (a `<For>` inside the select) leave the browser's own pick, the\n // first option: the select takes its value again after each commit to its children, as React's does.\n if (!bound.has(select)) keepWatchingCommits(select, () => apply(select, bound.get(select)));\n bound.set(select, value);\n apply(select, value);\n}\n\nfunction apply(select: HTMLSelectElement, value: unknown): void {\n if (select.multiple && Array.isArray(value)) {\n const wanted = listed(value);\n for (const option of Array.from(select.options)) option.selected = wanted.has(option.value);\n return;\n }\n select.value = plainText(value);\n}\n"],"mappings":";;;AAGA,MAAM,wBAAQ,IAAI,QAAoC;;AAGtD,SAAS,OAAO,OAAwC;CACtD,OAAO,IAAI,IAAI,MAAM,QAAQ,SAAS,SAAS,QAAQ,SAAS,KAAA,CAAS,CAAC,CAAC,IAAI,MAAM,CAAC;AACxF;;AAGA,SAAgB,UAAU,OAAwB;CAChD,OAAO,UAAU,QAAQ,UAAU,KAAA,IAAY,KAAK,OAAO,KAAK;AAClE;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,eAAe,QAA2B,OAAsB;CAG9E,IAAI,CAAC,MAAM,IAAI,MAAM,GAAG,oBAAoB,cAAc,MAAM,QAAQ,MAAM,IAAI,MAAM,CAAC,CAAC;CAC1F,MAAM,IAAI,QAAQ,KAAK;CACvB,MAAM,QAAQ,KAAK;AACrB;AAEA,SAAS,MAAM,QAA2B,OAAsB;CAC9D,IAAI,OAAO,YAAY,MAAM,QAAQ,KAAK,GAAG;EAC3C,MAAM,SAAS,OAAO,KAAK;EAC3B,KAAK,MAAM,UAAU,MAAM,KAAK,OAAO,OAAO,GAAG,OAAO,WAAW,OAAO,IAAI,OAAO,KAAK;EAC1F;CACF;CACA,OAAO,QAAQ,UAAU,KAAK;AAChC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cssValueText } from "../internal/css-units.js";
|
|
2
2
|
import { invalid } from "./errors.js";
|
|
3
|
-
import { isSsrNode } from "./node.js";
|
|
4
3
|
import { escapeHtml, resolveValue } from "./escape.js";
|
|
4
|
+
import { isSsrNode } from "./node.js";
|
|
5
5
|
// src/server/class-style.ts
|
|
6
6
|
/** A CSS property name: a custom property, or a lower-case name with an optional vendor dash. */
|
|
7
7
|
const CSS_PROPERTY = /^(--[A-Za-z0-9_-]+|-?[a-z][a-z0-9-]*)$/;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { nextKey } from "../internal/hydration-scope.js";
|
|
2
2
|
import { IGNORED_KEYS, attributeName, isFlagAttribute } from "../internal/react-names.js";
|
|
3
|
-
import { invalid } from "./errors.js";
|
|
4
|
-
import { SsrNode, isSsrNode } from "./node.js";
|
|
5
|
-
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
6
3
|
import { isEventName, ssrAttribute } from "./attributes.js";
|
|
7
4
|
import { classText, ssrStyle, styleText } from "./class-style.js";
|
|
5
|
+
import { invalid } from "./errors.js";
|
|
6
|
+
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
8
7
|
import { keepLeadingNewline, markSelectedOptions, textareaContent } from "./form-controls.js";
|
|
8
|
+
import { SsrNode, isSsrNode } from "./node.js";
|
|
9
9
|
import { rawElementContent } from "./raw-text.js";
|
|
10
10
|
// src/server/element.ts
|
|
11
11
|
/** A tag name: letters, digits and dashes, starting with a letter. Anything else could break out. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { invalid } from "./errors.js";
|
|
2
|
-
import { SsrNode } from "./node.js";
|
|
3
2
|
import { escape, escapeHtml, resolveValue } from "./escape.js";
|
|
3
|
+
import { SsrNode } from "./node.js";
|
|
4
4
|
// src/server/form-controls.ts
|
|
5
5
|
/**
|
|
6
6
|
* Server markup for the controls whose state is not an attribute. A browser ignores `value` on a
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { childScope, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { PortalContext } from "../internal/portal-context.js";
|
|
2
3
|
import { SsrError } from "./errors.js";
|
|
3
4
|
import { escape } from "./escape.js";
|
|
4
|
-
import { PortalContext } from "../internal/portal-context.js";
|
|
5
5
|
/** The collector behind a {@link ServerPortals}: what a renderer writes into while it renders. @internal */
|
|
6
6
|
var PortalCollector = class {
|
|
7
7
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { invalid } from "./errors.js";
|
|
2
|
-
import { SsrNode, isSsrNode } from "./node.js";
|
|
3
2
|
import { render, resolveValue } from "./escape.js";
|
|
3
|
+
import { SsrNode, isSsrNode } from "./node.js";
|
|
4
4
|
// src/server/raw-text.ts
|
|
5
5
|
/**
|
|
6
6
|
* Elements whose content the HTML parser reads as text and nothing else: `script` and `style` (raw text, no
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
2
|
+
import { runWithServerHead } from "../head/server-head.js";
|
|
1
3
|
import { createRootScope, resourceKey, withScope } from "../internal/hydration-scope.js";
|
|
2
4
|
import { MAX_TIMER_MS, SsrError } from "./errors.js";
|
|
3
5
|
import { escape } from "./escape.js";
|
|
4
|
-
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
5
|
-
import { runWithServerHead } from "../head/server-head.js";
|
|
6
6
|
import { portalCollectorFor, withPortalSink } from "./portals.js";
|
|
7
7
|
import { ResourceCacheContext, createRoot } from "@shadow-js/core";
|
|
8
8
|
// src/server/render.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
2
|
+
import { runWithServerHead } from "../head/server-head.js";
|
|
1
3
|
import { createRootScope, resourceKey, withScope } from "../internal/hydration-scope.js";
|
|
4
|
+
import { StreamContext } from "../internal/stream-context.js";
|
|
2
5
|
import { MAX_TIMER_MS, SsrError } from "./errors.js";
|
|
3
6
|
import { escape } from "./escape.js";
|
|
4
|
-
import { StreamContext } from "../internal/stream-context.js";
|
|
5
|
-
import { attachRootErrors } from "../control-flow/root-errors.js";
|
|
6
|
-
import { runWithServerHead } from "../head/server-head.js";
|
|
7
7
|
import { portalCollectorFor, withPortalSink } from "./portals.js";
|
|
8
8
|
import { serialize } from "./serialize.js";
|
|
9
9
|
import { ResourceCacheContext, createRoot, untrack } from "@shadow-js/core";
|