@bleedingdev/tanstack-redact 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/dist/cloudflare/index.d.ts +6 -0
- package/dist/cloudflare/index.js +39 -0
- package/dist/cloudflare/index.js.map +7 -0
- package/dist/core/attributes.d.ts +4 -0
- package/dist/core/attributes.js +30 -0
- package/dist/core/attributes.js.map +7 -0
- package/dist/core/browser.d.ts +9 -0
- package/dist/core/browser.js +32 -0
- package/dist/core/browser.js.map +7 -0
- package/dist/core/class-props.d.ts +1 -0
- package/dist/core/class-props.js +15 -0
- package/dist/core/class-props.js.map +7 -0
- package/dist/core/devtools.d.ts +26 -0
- package/dist/core/devtools.js +70 -0
- package/dist/core/devtools.js.map +7 -0
- package/dist/core/functions.d.ts +6 -0
- package/dist/core/functions.js +14 -0
- package/dist/core/functions.js.map +7 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +7 -0
- package/dist/core/internal.d.ts +103 -0
- package/dist/core/internal.js +43 -0
- package/dist/core/internal.js.map +7 -0
- package/dist/core/resource-hints.d.ts +7 -0
- package/dist/core/resource-hints.js +20 -0
- package/dist/core/resource-hints.js.map +7 -0
- package/dist/core/types.d.ts +23 -0
- package/dist/core/types.js +8 -0
- package/dist/core/types.js.map +7 -0
- package/dist/core/unitless-style.d.ts +1 -0
- package/dist/core/unitless-style.js +5 -0
- package/dist/core/unitless-style.js.map +7 -0
- package/dist/dom/_all.d.ts +27 -0
- package/dist/dom/_all.js +51 -0
- package/dist/dom/_all.js.map +7 -0
- package/dist/dom/client.d.ts +9 -0
- package/dist/dom/client.js +13 -0
- package/dist/dom/client.js.map +7 -0
- package/dist/dom/commit.d.ts +27 -0
- package/dist/dom/commit.js +237 -0
- package/dist/dom/commit.js.map +7 -0
- package/dist/dom/devtools-effects.d.ts +8 -0
- package/dist/dom/devtools-effects.js +80 -0
- package/dist/dom/devtools-effects.js.map +7 -0
- package/dist/dom/devtools.d.ts +33 -0
- package/dist/dom/devtools.js +635 -0
- package/dist/dom/devtools.js.map +7 -0
- package/dist/dom/dispatcher.d.ts +4 -0
- package/dist/dom/dispatcher.js +437 -0
- package/dist/dom/dispatcher.js.map +7 -0
- package/dist/dom/document-metadata.d.ts +7 -0
- package/dist/dom/document-metadata.js +44 -0
- package/dist/dom/document-metadata.js.map +7 -0
- package/dist/dom/dom.d.ts +11 -0
- package/dist/dom/dom.js +165 -0
- package/dist/dom/dom.js.map +7 -0
- package/dist/dom/error-info.d.ts +2 -0
- package/dist/dom/error-info.js +19 -0
- package/dist/dom/error-info.js.map +7 -0
- package/dist/dom/event-replay.d.ts +13 -0
- package/dist/dom/event-replay.js +24 -0
- package/dist/dom/event-replay.js.map +7 -0
- package/dist/dom/features/activity/full.d.ts +1 -0
- package/dist/dom/features/activity/full.js +140 -0
- package/dist/dom/features/activity/full.js.map +7 -0
- package/dist/dom/features/activity/index.d.ts +1 -0
- package/dist/dom/features/activity/index.js +2 -0
- package/dist/dom/features/activity/index.js.map +7 -0
- package/dist/dom/features/activity/stub.d.ts +1 -0
- package/dist/dom/features/activity/stub.js +10 -0
- package/dist/dom/features/activity/stub.js.map +7 -0
- package/dist/dom/features/class/full.d.ts +1 -0
- package/dist/dom/features/class/full.js +208 -0
- package/dist/dom/features/class/full.js.map +7 -0
- package/dist/dom/features/class/index.d.ts +1 -0
- package/dist/dom/features/class/index.js +2 -0
- package/dist/dom/features/class/index.js.map +7 -0
- package/dist/dom/features/class/stub.d.ts +1 -0
- package/dist/dom/features/class/stub.js +46 -0
- package/dist/dom/features/class/stub.js.map +7 -0
- package/dist/dom/features/context/full.d.ts +4 -0
- package/dist/dom/features/context/full.js +103 -0
- package/dist/dom/features/context/full.js.map +7 -0
- package/dist/dom/features/context/index.d.ts +1 -0
- package/dist/dom/features/context/index.js +2 -0
- package/dist/dom/features/context/index.js.map +7 -0
- package/dist/dom/features/context/stub.d.ts +4 -0
- package/dist/dom/features/context/stub.js +21 -0
- package/dist/dom/features/context/stub.js.map +7 -0
- package/dist/dom/features/forward-ref/full.d.ts +1 -0
- package/dist/dom/features/forward-ref/full.js +9 -0
- package/dist/dom/features/forward-ref/full.js.map +7 -0
- package/dist/dom/features/forward-ref/index.d.ts +1 -0
- package/dist/dom/features/forward-ref/index.js +2 -0
- package/dist/dom/features/forward-ref/index.js.map +7 -0
- package/dist/dom/features/forward-ref/stub.d.ts +1 -0
- package/dist/dom/features/forward-ref/stub.js +9 -0
- package/dist/dom/features/forward-ref/stub.js.map +7 -0
- package/dist/dom/features/fragment-refs/index.d.ts +1 -0
- package/dist/dom/features/fragment-refs/index.js +9 -0
- package/dist/dom/features/fragment-refs/index.js.map +7 -0
- package/dist/dom/features/fragment-refs/stub.d.ts +5 -0
- package/dist/dom/features/fragment-refs/stub.js +17 -0
- package/dist/dom/features/fragment-refs/stub.js.map +7 -0
- package/dist/dom/features/hydration/full.d.ts +68 -0
- package/dist/dom/features/hydration/full.js +493 -0
- package/dist/dom/features/hydration/full.js.map +7 -0
- package/dist/dom/features/hydration/index.d.ts +1 -0
- package/dist/dom/features/hydration/index.js +2 -0
- package/dist/dom/features/hydration/index.js.map +7 -0
- package/dist/dom/features/hydration/stub.d.ts +36 -0
- package/dist/dom/features/hydration/stub.js +80 -0
- package/dist/dom/features/hydration/stub.js.map +7 -0
- package/dist/dom/features/index.d.ts +8 -0
- package/dist/dom/features/index.js +9 -0
- package/dist/dom/features/index.js.map +7 -0
- package/dist/dom/features/lazy/full.d.ts +1 -0
- package/dist/dom/features/lazy/full.js +23 -0
- package/dist/dom/features/lazy/full.js.map +7 -0
- package/dist/dom/features/lazy/index.d.ts +1 -0
- package/dist/dom/features/lazy/index.js +2 -0
- package/dist/dom/features/lazy/index.js.map +7 -0
- package/dist/dom/features/lazy/stub.d.ts +1 -0
- package/dist/dom/features/lazy/stub.js +19 -0
- package/dist/dom/features/lazy/stub.js.map +7 -0
- package/dist/dom/features/memo/full.d.ts +1 -0
- package/dist/dom/features/memo/full.js +34 -0
- package/dist/dom/features/memo/full.js.map +7 -0
- package/dist/dom/features/memo/index.d.ts +1 -0
- package/dist/dom/features/memo/index.js +2 -0
- package/dist/dom/features/memo/index.js.map +7 -0
- package/dist/dom/features/memo/stub.d.ts +1 -0
- package/dist/dom/features/memo/stub.js +9 -0
- package/dist/dom/features/memo/stub.js.map +7 -0
- package/dist/dom/features/portal/full.d.ts +1 -0
- package/dist/dom/features/portal/full.js +11 -0
- package/dist/dom/features/portal/full.js.map +7 -0
- package/dist/dom/features/portal/index.d.ts +1 -0
- package/dist/dom/features/portal/index.js +2 -0
- package/dist/dom/features/portal/index.js.map +7 -0
- package/dist/dom/features/portal/stub.d.ts +1 -0
- package/dist/dom/features/portal/stub.js +5 -0
- package/dist/dom/features/portal/stub.js.map +7 -0
- package/dist/dom/features/suspense/full.d.ts +1 -0
- package/dist/dom/features/suspense/full.js +389 -0
- package/dist/dom/features/suspense/full.js.map +7 -0
- package/dist/dom/features/suspense/index.d.ts +1 -0
- package/dist/dom/features/suspense/index.js +2 -0
- package/dist/dom/features/suspense/index.js.map +7 -0
- package/dist/dom/features/suspense/stub.d.ts +1 -0
- package/dist/dom/features/suspense/stub.js +4 -0
- package/dist/dom/features/suspense/stub.js.map +7 -0
- package/dist/dom/features/suspense-runtime/index.d.ts +1 -0
- package/dist/dom/features/suspense-runtime/index.js +2 -0
- package/dist/dom/features/suspense-runtime/index.js.map +7 -0
- package/dist/dom/features/suspense-runtime/stub.d.ts +1 -0
- package/dist/dom/features/suspense-runtime/stub.js +11 -0
- package/dist/dom/features/suspense-runtime/stub.js.map +7 -0
- package/dist/dom/features/view-transition/full.d.ts +7 -0
- package/dist/dom/features/view-transition/full.js +324 -0
- package/dist/dom/features/view-transition/full.js.map +7 -0
- package/dist/dom/features/view-transition/index.d.ts +1 -0
- package/dist/dom/features/view-transition/index.js +2 -0
- package/dist/dom/features/view-transition/index.js.map +7 -0
- package/dist/dom/features/view-transition/resources.d.ts +11 -0
- package/dist/dom/features/view-transition/resources.js +117 -0
- package/dist/dom/features/view-transition/resources.js.map +7 -0
- package/dist/dom/features/view-transition/stub.d.ts +7 -0
- package/dist/dom/features/view-transition/stub.js +21 -0
- package/dist/dom/features/view-transition/stub.js.map +7 -0
- package/dist/dom/features/view-transition/visual.d.ts +14 -0
- package/dist/dom/features/view-transition/visual.js +404 -0
- package/dist/dom/features/view-transition/visual.js.map +7 -0
- package/dist/dom/form-actions.d.ts +4 -0
- package/dist/dom/form-actions.js +74 -0
- package/dist/dom/form-actions.js.map +7 -0
- package/dist/dom/form-controls.d.ts +3 -0
- package/dist/dom/form-controls.js +91 -0
- package/dist/dom/form-controls.js.map +7 -0
- package/dist/dom/fragment-instance.d.ts +33 -0
- package/dist/dom/fragment-instance.js +449 -0
- package/dist/dom/fragment-instance.js.map +7 -0
- package/dist/dom/index.d.ts +61 -0
- package/dist/dom/index.js +71 -0
- package/dist/dom/index.js.map +7 -0
- package/dist/dom/portal.d.ts +2 -0
- package/dist/dom/portal.js +14 -0
- package/dist/dom/portal.js.map +7 -0
- package/dist/dom/react-ids.d.ts +6 -0
- package/dist/dom/react-ids.js +38 -0
- package/dist/dom/react-ids.js.map +7 -0
- package/dist/dom/reconcile.d.ts +86 -0
- package/dist/dom/reconcile.js +1305 -0
- package/dist/dom/reconcile.js.map +7 -0
- package/dist/dom/refresh.d.ts +12 -0
- package/dist/dom/refresh.js +174 -0
- package/dist/dom/refresh.js.map +7 -0
- package/dist/dom/resource-hints.d.ts +6 -0
- package/dist/dom/resource-hints.js +107 -0
- package/dist/dom/resource-hints.js.map +7 -0
- package/dist/dom/resource-store.d.ts +13 -0
- package/dist/dom/resource-store.js +47 -0
- package/dist/dom/resource-store.js.map +7 -0
- package/dist/dom/resources.d.ts +1 -0
- package/dist/dom/resources.js +46 -0
- package/dist/dom/resources.js.map +7 -0
- package/dist/dom/retained-effects.d.ts +6 -0
- package/dist/dom/retained-effects.js +67 -0
- package/dist/dom/retained-effects.js.map +7 -0
- package/dist/dom/root-internal.d.ts +11 -0
- package/dist/dom/root-internal.js +35 -0
- package/dist/dom/root-internal.js.map +7 -0
- package/dist/dom/root.d.ts +17 -0
- package/dist/dom/root.js +38 -0
- package/dist/dom/root.js.map +7 -0
- package/dist/dom/synthetic-event.d.ts +1 -0
- package/dist/dom/synthetic-event.js +35 -0
- package/dist/dom/synthetic-event.js.map +7 -0
- package/dist/dom/test-utils.d.ts +1 -0
- package/dist/dom/test-utils.js +5 -0
- package/dist/dom/test-utils.js.map +7 -0
- package/dist/dom/transitions.d.ts +9 -0
- package/dist/dom/transitions.js +147 -0
- package/dist/dom/transitions.js.map +7 -0
- package/dist/dom/tree.d.ts +5 -0
- package/dist/dom/tree.js +62 -0
- package/dist/dom/tree.js.map +7 -0
- package/dist/dom/walk.d.ts +2 -0
- package/dist/dom/walk.js +14 -0
- package/dist/dom/walk.js.map +7 -0
- package/dist/next/client.d.ts +9 -0
- package/dist/next/client.js +14 -0
- package/dist/next/client.js.map +7 -0
- package/dist/next/dev-cache-loader.cjs +13 -0
- package/dist/next/index.d.ts +2 -0
- package/dist/next/index.js +97 -0
- package/dist/next/index.js.map +7 -0
- package/dist/next/loader.cjs +10 -0
- package/dist/next/react.d.ts +71 -0
- package/dist/next/react.js +9 -0
- package/dist/next/react.js.map +7 -0
- package/dist/react/act.d.ts +3 -0
- package/dist/react/act.js +124 -0
- package/dist/react/act.js.map +7 -0
- package/dist/react/action-scope.d.ts +17 -0
- package/dist/react/action-scope.js +60 -0
- package/dist/react/action-scope.js.map +7 -0
- package/dist/react/activity.d.ts +7 -0
- package/dist/react/activity.js +7 -0
- package/dist/react/activity.js.map +7 -0
- package/dist/react/children.d.ts +8 -0
- package/dist/react/children.js +76 -0
- package/dist/react/children.js.map +7 -0
- package/dist/react/class.d.ts +36 -0
- package/dist/react/class.js +39 -0
- package/dist/react/class.js.map +7 -0
- package/dist/react/compiler-runtime.d.ts +1 -0
- package/dist/react/compiler-runtime.js +9 -0
- package/dist/react/compiler-runtime.js.map +7 -0
- package/dist/react/context.d.ts +32 -0
- package/dist/react/context.js +25 -0
- package/dist/react/context.js.map +7 -0
- package/dist/react/element.d.ts +13 -0
- package/dist/react/element.js +70 -0
- package/dist/react/element.js.map +7 -0
- package/dist/react/form-state.d.ts +26 -0
- package/dist/react/form-state.js +30 -0
- package/dist/react/form-state.js.map +7 -0
- package/dist/react/hooks.d.ts +67 -0
- package/dist/react/hooks.js +165 -0
- package/dist/react/hooks.js.map +7 -0
- package/dist/react/index.d.ts +99 -0
- package/dist/react/index.js +143 -0
- package/dist/react/index.js.map +7 -0
- package/dist/react/jsx-runtime.d.ts +24 -0
- package/dist/react/jsx-runtime.js +37 -0
- package/dist/react/jsx-runtime.js.map +7 -0
- package/dist/react/memo.d.ts +20 -0
- package/dist/react/memo.js +27 -0
- package/dist/react/memo.js.map +7 -0
- package/dist/react/portal.d.ts +1 -0
- package/dist/react/portal.js +5 -0
- package/dist/react/portal.js.map +7 -0
- package/dist/react/shared-internals.d.ts +52 -0
- package/dist/react/shared-internals.js +22 -0
- package/dist/react/shared-internals.js.map +7 -0
- package/dist/react/suspense.d.ts +15 -0
- package/dist/react/suspense.js +15 -0
- package/dist/react/suspense.js.map +7 -0
- package/dist/react/thenable.d.ts +1 -0
- package/dist/react/thenable.js +25 -0
- package/dist/react/thenable.js.map +7 -0
- package/dist/react/view-transition.d.ts +32 -0
- package/dist/react/view-transition.js +12 -0
- package/dist/react/view-transition.js.map +7 -0
- package/dist/scheduler/index.d.ts +44 -0
- package/dist/scheduler/index.js +109 -0
- package/dist/scheduler/index.js.map +7 -0
- package/dist/server/bootstrap-script.d.ts +3 -0
- package/dist/server/bootstrap-script.js +17 -0
- package/dist/server/bootstrap-script.js.map +7 -0
- package/dist/server/dispatcher.d.ts +57 -0
- package/dist/server/dispatcher.js +157 -0
- package/dist/server/dispatcher.js.map +7 -0
- package/dist/server/escape.d.ts +6 -0
- package/dist/server/escape.js +75 -0
- package/dist/server/escape.js.map +7 -0
- package/dist/server/index.d.ts +16 -0
- package/dist/server/index.js +25 -0
- package/dist/server/index.js.map +7 -0
- package/dist/server/insertion-context.d.ts +3 -0
- package/dist/server/insertion-context.js +32 -0
- package/dist/server/renderToString.d.ts +7 -0
- package/dist/server/renderToString.js +33 -0
- package/dist/server/renderToString.js.map +7 -0
- package/dist/server/resource-hints.d.ts +22 -0
- package/dist/server/resource-hints.js +168 -0
- package/dist/server/resource-hints.js.map +7 -0
- package/dist/server/stream-ids.d.ts +3 -0
- package/dist/server/stream-ids.js +8 -0
- package/dist/server/stream.d.ts +61 -0
- package/dist/server/stream.js +418 -0
- package/dist/server/stream.js.map +7 -0
- package/dist/server/walk.d.ts +58 -0
- package/dist/server/walk.js +378 -0
- package/dist/server/walk.js.map +7 -0
- package/dist/vinext/compatibility.d.ts +23 -0
- package/dist/vinext/compatibility.js +127 -0
- package/dist/vinext/compatibility.js.map +7 -0
- package/dist/vinext/flight-timing.d.ts +1 -0
- package/dist/vinext/flight-timing.js +46 -0
- package/dist/vinext/flight-timing.js.map +7 -0
- package/dist/vinext/index.d.ts +5 -0
- package/dist/vinext/index.js +50 -0
- package/dist/vinext/index.js.map +7 -0
- package/dist/vite/index.d.ts +102 -0
- package/dist/vite/index.js +291 -0
- package/dist/vite/index.js.map +7 -0
- package/dist/vite/react18.d.ts +4 -0
- package/dist/vite/react18.js +74 -0
- package/dist/vite/react18.js.map +7 -0
- package/package.json +121 -4
- package/src/cloudflare/index.ts +44 -0
- package/src/core/attributes.ts +20 -0
- package/src/core/browser.ts +34 -0
- package/src/core/class-props.ts +12 -0
- package/src/core/devtools.ts +69 -0
- package/src/core/functions.ts +11 -0
- package/src/core/index.ts +2 -0
- package/src/core/internal.ts +123 -0
- package/src/core/resource-hints.ts +39 -0
- package/src/core/types.ts +39 -0
- package/src/core/unitless-style.ts +1 -0
- package/src/dom/_all.ts +46 -0
- package/src/dom/client.ts +17 -0
- package/src/dom/commit.ts +223 -0
- package/src/dom/devtools-effects.ts +78 -0
- package/src/dom/devtools.ts +527 -0
- package/src/dom/dispatcher.ts +476 -0
- package/src/dom/document-metadata.ts +41 -0
- package/src/dom/dom.ts +181 -0
- package/src/dom/error-info.ts +20 -0
- package/src/dom/event-replay.ts +39 -0
- package/src/dom/features/activity/full.ts +150 -0
- package/src/dom/features/activity/index.ts +1 -0
- package/src/dom/features/activity/stub.ts +12 -0
- package/src/dom/features/class/full.ts +202 -0
- package/src/dom/features/class/index.ts +1 -0
- package/src/dom/features/class/stub.ts +58 -0
- package/src/dom/features/context/full.ts +107 -0
- package/src/dom/features/context/index.ts +1 -0
- package/src/dom/features/context/stub.ts +26 -0
- package/src/dom/features/forward-ref/full.ts +9 -0
- package/src/dom/features/forward-ref/index.ts +1 -0
- package/src/dom/features/forward-ref/stub.ts +15 -0
- package/src/dom/features/fragment-refs/index.ts +1 -0
- package/src/dom/features/fragment-refs/stub.ts +6 -0
- package/src/dom/features/hydration/full.ts +563 -0
- package/src/dom/features/hydration/index.ts +1 -0
- package/src/dom/features/hydration/stub.ts +86 -0
- package/src/dom/features/index.ts +12 -0
- package/src/dom/features/lazy/full.ts +27 -0
- package/src/dom/features/lazy/index.ts +1 -0
- package/src/dom/features/lazy/stub.ts +24 -0
- package/src/dom/features/memo/full.ts +39 -0
- package/src/dom/features/memo/index.ts +1 -0
- package/src/dom/features/memo/stub.ts +13 -0
- package/src/dom/features/portal/full.ts +14 -0
- package/src/dom/features/portal/index.ts +1 -0
- package/src/dom/features/portal/stub.ts +11 -0
- package/src/dom/features/suspense/full.ts +469 -0
- package/src/dom/features/suspense/index.ts +1 -0
- package/src/dom/features/suspense/stub.ts +13 -0
- package/src/dom/features/suspense-runtime/index.ts +1 -0
- package/src/dom/features/suspense-runtime/stub.ts +1 -0
- package/src/dom/features/view-transition/full.ts +292 -0
- package/src/dom/features/view-transition/index.ts +1 -0
- package/src/dom/features/view-transition/resources.ts +123 -0
- package/src/dom/features/view-transition/stub.ts +8 -0
- package/src/dom/features/view-transition/visual.ts +454 -0
- package/src/dom/form-actions.ts +69 -0
- package/src/dom/form-controls.ts +91 -0
- package/src/dom/fragment-instance.ts +462 -0
- package/src/dom/index.ts +49 -0
- package/src/dom/portal.ts +16 -0
- package/src/dom/react-ids.ts +36 -0
- package/src/dom/reconcile.ts +1423 -0
- package/src/dom/refresh.ts +171 -0
- package/src/dom/resource-hints.ts +104 -0
- package/src/dom/resource-store.ts +50 -0
- package/src/dom/resources.ts +47 -0
- package/src/dom/retained-effects.ts +57 -0
- package/src/dom/root-internal.ts +37 -0
- package/src/dom/root.ts +59 -0
- package/src/dom/synthetic-event.ts +22 -0
- package/src/dom/test-utils.ts +1 -0
- package/src/dom/transitions.ts +141 -0
- package/src/dom/tree.ts +56 -0
- package/src/dom/walk.ts +8 -0
- package/src/next/client.ts +10 -0
- package/src/next/dev-cache-loader.cjs +13 -0
- package/src/next/index.ts +95 -0
- package/src/next/loader.cjs +10 -0
- package/src/next/react.ts +7 -0
- package/src/react/act.ts +105 -0
- package/src/react/action-scope.ts +57 -0
- package/src/react/activity.ts +10 -0
- package/src/react/children.ts +86 -0
- package/src/react/class.ts +66 -0
- package/src/react/compiler-runtime.ts +8 -0
- package/src/react/context.ts +46 -0
- package/src/react/element.ts +82 -0
- package/src/react/form-state.ts +35 -0
- package/src/react/hooks.ts +214 -0
- package/src/react/index.ts +91 -0
- package/src/react/jsx-runtime.ts +50 -0
- package/src/react/memo.ts +42 -0
- package/src/react/portal.ts +1 -0
- package/src/react/shared-internals.ts +80 -0
- package/src/react/suspense.ts +18 -0
- package/src/react/thenable.ts +21 -0
- package/src/react/view-transition.ts +41 -0
- package/src/scheduler/index.ts +124 -0
- package/src/server/bootstrap-script.ts +92 -0
- package/src/server/dispatcher.ts +168 -0
- package/src/server/escape.ts +102 -0
- package/src/server/index.ts +26 -0
- package/src/server/insertion-context.ts +28 -0
- package/src/server/renderToString.ts +35 -0
- package/src/server/resource-hints.ts +166 -0
- package/src/server/stream-ids.ts +5 -0
- package/src/server/stream.ts +525 -0
- package/src/server/walk.ts +555 -0
- package/src/vinext/compatibility.ts +122 -0
- package/src/vinext/flight-timing.ts +37 -0
- package/src/vinext/index.ts +47 -0
- package/src/vite/index.ts +476 -0
- package/src/vite/react18.ts +74 -0
- package/vendor/cloudflare-vite-plugin/LICENSE +25 -0
- package/vendor/cloudflare-vite-plugin/README.md +9 -0
- package/vendor/cloudflare-vite-plugin/dist/chunk-U6NEESU5-BmLHqeIt.mjs +43 -0
- package/vendor/cloudflare-vite-plugin/dist/index.d.mts +155 -0
- package/vendor/cloudflare-vite-plugin/dist/index.mjs +94700 -0
- package/vendor/cloudflare-vite-plugin/dist/open-PCXX3ZDZ-DYH87NhH.mjs +530 -0
- package/vendor/cloudflare-vite-plugin/dist/package-4cnqy5mM.mjs +84 -0
- package/vendor/cloudflare-vite-plugin/dist/workers/asset-worker/index.js +5996 -0
- package/vendor/cloudflare-vite-plugin/dist/workers/router-worker/index.js +6414 -0
- package/vendor/cloudflare-vite-plugin/dist/workers/runner-worker/index.js +457 -0
- package/vendor/cloudflare-vite-plugin/dist/workers/runner-worker/module-runner-legacy.js +1129 -0
- package/vendor/cloudflare-vite-plugin/dist/workers/runner-worker/module-runner.js +1259 -0
- package/vendor/cloudflare-vite-plugin/dist/workers/vite-proxy-worker/index.js +31 -0
- package/vendor/cloudflare-vite-plugin/package.json +90 -0
- package/vendor/cloudflare-vite-plugin/provenance.json +26 -0
- package/README.md +0 -3
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isFunction } from '../core/functions'
|
|
2
|
+
import { resourceKind, resourceURL, type ResourceHintKind, type ResourceHintOptions } from '../core/resource-hints'
|
|
3
|
+
import { attrToHtml, escapeAttr } from './escape'
|
|
4
|
+
import { attributeName } from '../core/attributes'
|
|
5
|
+
|
|
6
|
+
interface Resource {
|
|
7
|
+
kind: ResourceHintKind | 'style'
|
|
8
|
+
href: string
|
|
9
|
+
options: Record<string, any>
|
|
10
|
+
sent?: boolean
|
|
11
|
+
cancelled?: boolean
|
|
12
|
+
preloaded?: boolean
|
|
13
|
+
css?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ResourceScope {
|
|
17
|
+
stylesheets?: Map<string, string[]>
|
|
18
|
+
inline?: Set<string>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function styleText(props: any): string {
|
|
22
|
+
const html = props.dangerouslySetInnerHTML
|
|
23
|
+
if (html != null) {
|
|
24
|
+
if (typeof html !== 'object' || !('__html' in html)) throw new Error('dangerouslySetInnerHTML must be an object with an __html field.')
|
|
25
|
+
if (props.children != null) throw new Error('Can only set one of children or dangerouslySetInnerHTML.')
|
|
26
|
+
return html.__html == null ? '' : '' + html.__html
|
|
27
|
+
}
|
|
28
|
+
const child = Array.isArray(props.children) ? props.children.length < 2 ? props.children[0] : null : props.children
|
|
29
|
+
return child == null || isFunction(child) || typeof child === 'symbol' ? ''
|
|
30
|
+
: ('' + child).replace(/(<\/?)(s)(tyle)/gi, (_, prefix: string, s: string, suffix: string) => prefix + '\\' + s.charCodeAt(0).toString(16) + ' ' + suffix)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function markup(resource: Resource, late: boolean): string {
|
|
34
|
+
const { kind, href, options } = resource
|
|
35
|
+
const script = kind === 'script' || kind === 'module-script'
|
|
36
|
+
const style = kind === 'stylesheet'
|
|
37
|
+
const props: Record<string, any> = script
|
|
38
|
+
? { src: href, ...(kind === 'module-script' ? { type: 'module' } : {}), async: true, ...options }
|
|
39
|
+
: style
|
|
40
|
+
? late
|
|
41
|
+
? { rel: 'preload', as: 'style', href, crossOrigin: options.crossOrigin, fetchPriority: options.fetchPriority, integrity: options.integrity, media: options.media, hrefLang: options.hrefLang, referrerPolicy: options.referrerPolicy }
|
|
42
|
+
: { rel: 'stylesheet', href, 'data-precedence': options.precedence!, ...options }
|
|
43
|
+
: { rel: kind, ...(options.as === 'image' && options.imageSrcSet ? {} : { href }), ...options }
|
|
44
|
+
let output = script ? '<script' : '<link'
|
|
45
|
+
for (const name in props) {
|
|
46
|
+
if (name === 'precedence' || late && name === 'data-precedence') continue
|
|
47
|
+
const value = name === 'href' || name === 'src' ? resourceURL(props[name]!) : props[name]!
|
|
48
|
+
output += attrToHtml(name, value).replace(/'/g, ''')
|
|
49
|
+
}
|
|
50
|
+
return output + (script ? '></script>' : '/>')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createResourceHints(shellFlushed = false, styleNonce?: string) {
|
|
54
|
+
const resources = new Map<string, Resource>()
|
|
55
|
+
const groups: Resource[][] = [[], [], [], [], []]
|
|
56
|
+
const styles = new Map<string, Resource[]>()
|
|
57
|
+
const dependencies = new Map<string, string[]>()
|
|
58
|
+
const visibleInline = new Set<string>()
|
|
59
|
+
const collector = {
|
|
60
|
+
add(kind: ResourceHintKind | 'style', href: string, options: ResourceHintOptions): Resource {
|
|
61
|
+
let type: string = kind
|
|
62
|
+
let source = href
|
|
63
|
+
const init = kind === 'style' || kind === 'stylesheet' || kind === 'script' || kind === 'module-script'
|
|
64
|
+
if (kind === 'preload') {
|
|
65
|
+
type = options.as!
|
|
66
|
+
if (type === 'image' && options.imageSrcSet) source = options.imageSrcSet + '\n' + (options.imageSizes || '')
|
|
67
|
+
} else if (kind === 'modulepreload') type = 'module-' + (options.as || 'script')
|
|
68
|
+
else if (kind === 'stylesheet') type = 'style'
|
|
69
|
+
else if (kind === 'preconnect') type += ':' + (options.crossOrigin ?? 'default')
|
|
70
|
+
const key = JSON.stringify([type, source])
|
|
71
|
+
const prior = resources.get(key)
|
|
72
|
+
if (prior && (!init || prior.kind !== 'preload' && prior.kind !== 'modulepreload')) return prior
|
|
73
|
+
|
|
74
|
+
const resource: Resource = { kind, href, options: { ...options } }
|
|
75
|
+
if (kind === 'style' && (!styleNonce || options.nonce === styleNonce)) resource.css = styleText(options)
|
|
76
|
+
if (prior) {
|
|
77
|
+
prior.cancelled = true
|
|
78
|
+
resource.preloaded = !!prior.sent
|
|
79
|
+
for (const name of ['crossOrigin', 'integrity']) {
|
|
80
|
+
if (resource.options[name] == null && prior.options[name] != null) resource.options[name] = prior.options[name]!
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
resources.set(key, resource)
|
|
84
|
+
if (kind === 'stylesheet' || kind === 'style') {
|
|
85
|
+
const precedence = options.precedence!
|
|
86
|
+
let group = styles.get(precedence)
|
|
87
|
+
if (!group) styles.set(precedence, group = [])
|
|
88
|
+
group.push(resource)
|
|
89
|
+
} else {
|
|
90
|
+
const group = kind === 'dns-prefetch' || kind === 'preconnect' ? 0
|
|
91
|
+
: kind === 'preload' && options.as === 'font' ? 1
|
|
92
|
+
: kind === 'preload' && options.as === 'image' && options.fetchPriority === 'high' ? 2
|
|
93
|
+
: init ? 3 : 4
|
|
94
|
+
groups[group]!.push(resource)
|
|
95
|
+
}
|
|
96
|
+
return resource
|
|
97
|
+
},
|
|
98
|
+
addHost(type: string, props: any, scope?: ResourceScope): boolean {
|
|
99
|
+
const kind = resourceKind(type, props)
|
|
100
|
+
if (!kind) return false
|
|
101
|
+
const resource = collector.add(kind === 'script' && props.type === 'module' ? 'module-script' : kind, kind === 'script' ? props.src : props.href, props)
|
|
102
|
+
if (shellFlushed && kind === 'stylesheet') {
|
|
103
|
+
const descriptor = [resourceURL(resource.href), resource.options.precedence]
|
|
104
|
+
for (const name in resource.options) {
|
|
105
|
+
if (name === 'href' || name === 'rel' || name === 'precedence' || name === 'data-precedence' || name === 'children' || name === 'dangerouslySetInnerHTML' || name === 'innerHTML' || name === 'style' || name === 'suppressHydrationWarning' || name === 'suppressContentEditableWarning' || name === 'ref' || name === 'key' || /^on/i.test(name) || !/^[a-zA-Z_:][a-zA-Z0-9:_.-]*$/.test(name)) continue
|
|
106
|
+
const value = resource.options[name]
|
|
107
|
+
if (value == null || isFunction(value) || typeof value === 'symbol' || name === 'hidden' && value === false) continue
|
|
108
|
+
descriptor.push(attributeName(name), name === 'hidden' ? '' : name === 'src' ? resourceURL('' + value) : '' + value)
|
|
109
|
+
}
|
|
110
|
+
;(scope ? scope.stylesheets ||= new Map() : dependencies).set(resource.href, descriptor)
|
|
111
|
+
} else if (shellFlushed && kind === 'style') {
|
|
112
|
+
;(scope ? scope.inline ||= new Set() : visibleInline).add(resource.options.precedence)
|
|
113
|
+
}
|
|
114
|
+
return true
|
|
115
|
+
},
|
|
116
|
+
mergeScope(scope: ResourceScope, parent?: ResourceScope): void {
|
|
117
|
+
if (scope.stylesheets) for (const [href, descriptor] of scope.stylesheets) {
|
|
118
|
+
;(parent ? parent.stylesheets ||= new Map() : dependencies).set(href, descriptor)
|
|
119
|
+
}
|
|
120
|
+
if (scope.inline) for (const precedence of scope.inline) {
|
|
121
|
+
;(parent ? parent.inline ||= new Set() : visibleInline).add(precedence)
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
takeStylesheets(): string[][] {
|
|
125
|
+
const result = Array.from(dependencies.values())
|
|
126
|
+
dependencies.clear()
|
|
127
|
+
return result
|
|
128
|
+
},
|
|
129
|
+
drain(): string {
|
|
130
|
+
let output = ''
|
|
131
|
+
function flush(group: Resource[], precedence?: string) {
|
|
132
|
+
let remaining = 0
|
|
133
|
+
let inline = false, hasStylesheets = false
|
|
134
|
+
let hrefs = '', rules = ''
|
|
135
|
+
for (const resource of group) {
|
|
136
|
+
if (!resource.sent && !resource.cancelled) {
|
|
137
|
+
if (resource.kind === 'style') {
|
|
138
|
+
if (shellFlushed && !visibleInline.has(precedence!)) { group[remaining++] = resource; continue }
|
|
139
|
+
inline = true
|
|
140
|
+
if (resource.css !== undefined) {
|
|
141
|
+
hrefs += (hrefs ? ' ' : '') + resource.href
|
|
142
|
+
rules += resource.css
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
if (resource.kind === 'stylesheet') hasStylesheets = true
|
|
146
|
+
if (!(shellFlushed && resource.kind === 'stylesheet' && resource.preloaded)) output += markup(resource, shellFlushed)
|
|
147
|
+
}
|
|
148
|
+
resource.sent = true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
group.length = remaining
|
|
152
|
+
if (hrefs || inline && !shellFlushed && !hasStylesheets) {
|
|
153
|
+
output += `<style${styleNonce !== undefined ? ` nonce="${escapeAttr(styleNonce)}"` : ''}${shellFlushed ? ' media="not all"' : ''} data-precedence="${escapeAttr(precedence!)}"${hrefs ? ` data-href="${escapeAttr(hrefs)}"` : ''}>${rules}</style>`
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
for (let index = 0; index < groups.length; index++) {
|
|
157
|
+
if (index === 3) for (const [precedence, group] of styles) flush(group, precedence)
|
|
158
|
+
flush(groups[index]!)
|
|
159
|
+
}
|
|
160
|
+
shellFlushed = true
|
|
161
|
+
visibleInline.clear()
|
|
162
|
+
return output
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
return collector
|
|
166
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Match Fizz's transport identifiers. Hook IDs and boundary comment numbers are
|
|
2
|
+
// separate namespaces; only the DOM transport IDs use this prefixed hex scheme.
|
|
3
|
+
export const boundaryId = (id: number, prefix = ''): string => prefix + 'B:' + id.toString(16)
|
|
4
|
+
export const segmentId = (id: number, prefix = ''): string => prefix + 'S:' + id.toString(16)
|
|
5
|
+
export const scriptId = (id: string): string => JSON.stringify(id).replace(/</g, '\\u003c')
|
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { boundaryId, segmentId, scriptId } from './stream-ids'
|
|
2
|
+
import { segmentHtml } from './insertion-context'
|
|
3
|
+
import { isFunction, isThenable } from '../core/functions'
|
|
4
|
+
import type { ReactNode } from '../core'
|
|
5
|
+
import {
|
|
6
|
+
beginSSR,
|
|
7
|
+
endSSR,
|
|
8
|
+
applyContextSnapshot,
|
|
9
|
+
currentSSRFrame,
|
|
10
|
+
type SSRFrame,
|
|
11
|
+
} from './dispatcher'
|
|
12
|
+
import { walk, boundaryEdges, type HtmlPart, type SuspendedBoundary, type BrowserBailoutCallback } from './walk'
|
|
13
|
+
import { browserError, isBrowserToken, isBrowserError } from '../core/browser'
|
|
14
|
+
import { BOUNDARY_REVEAL_RUNTIME, revealScript } from './bootstrap-script'
|
|
15
|
+
import { escapeAttr, escapeScript } from './escape'
|
|
16
|
+
import { resourceURL } from '../core/resource-hints'
|
|
17
|
+
import type { ResourceScope } from './resource-hints'
|
|
18
|
+
|
|
19
|
+
export interface StreamOptions {
|
|
20
|
+
identifierPrefix?: string
|
|
21
|
+
nonce?: string | { script?: string; style?: string }
|
|
22
|
+
bootstrapScriptContent?: string | ReadonlyArray<string>
|
|
23
|
+
bootstrapScripts?: ReadonlyArray<string | { src: string; async?: boolean; nonce?: string }>
|
|
24
|
+
bootstrapModules?: ReadonlyArray<string | { src: string; nonce?: string }>
|
|
25
|
+
onError?: (error: unknown) => string | void
|
|
26
|
+
onBrowserBailout?: BrowserBailoutCallback
|
|
27
|
+
signal?: AbortSignal
|
|
28
|
+
progressiveChunkSize?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ReadableStreamResult extends ReadableStream<Uint8Array> {
|
|
32
|
+
allReady: Promise<void>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PipeableWritable {
|
|
36
|
+
write(chunk: string): unknown
|
|
37
|
+
end(): unknown
|
|
38
|
+
destroy?(error?: unknown): unknown
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface OrchestratorState {
|
|
42
|
+
nextId: number
|
|
43
|
+
pending: Set<Promise<void>>
|
|
44
|
+
closed: boolean
|
|
45
|
+
errored: unknown | null
|
|
46
|
+
aborted: boolean
|
|
47
|
+
reason: unknown
|
|
48
|
+
abort: (reason?: unknown) => void
|
|
49
|
+
cancelled: Promise<void>
|
|
50
|
+
onShellReady?: () => void
|
|
51
|
+
frame?: SSRFrame
|
|
52
|
+
// Output is written once the destination starts reading. Until then,
|
|
53
|
+
// completed boundaries stay inline, as React does before its first flush.
|
|
54
|
+
flowing?: boolean
|
|
55
|
+
flush?: () => void
|
|
56
|
+
outlined?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function createState(): OrchestratorState {
|
|
60
|
+
let wake!: () => void
|
|
61
|
+
const state: OrchestratorState = {
|
|
62
|
+
nextId: 0, pending: new Set(), closed: false, errored: null,
|
|
63
|
+
aborted: false, reason: undefined,
|
|
64
|
+
cancelled: new Promise<void>((resolve) => { wake = resolve }),
|
|
65
|
+
abort(reason) {
|
|
66
|
+
if (state.closed || state.aborted) return
|
|
67
|
+
state.aborted = true
|
|
68
|
+
state.reason = isBrowserToken(reason) ? browserError(reason) : reason ?? new Error('The render was aborted by the server without a reason.')
|
|
69
|
+
wake()
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
return state
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type Emit = (chunk: string) => void
|
|
76
|
+
|
|
77
|
+
export async function streamHtml(
|
|
78
|
+
children: ReactNode,
|
|
79
|
+
emit: Emit,
|
|
80
|
+
options: StreamOptions,
|
|
81
|
+
state: OrchestratorState,
|
|
82
|
+
): Promise<void> {
|
|
83
|
+
const nonce = scriptNonce(options)
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const boundaries: SuspendedBoundary[] = []
|
|
87
|
+
|
|
88
|
+
// Buffer shell + bootstrap into a string[] and flush as a single emit.
|
|
89
|
+
// Per-emit overhead in renderToReadableStream is TextEncoder.encode +
|
|
90
|
+
// controller.enqueue — each walkHost normally fires 3+ emits (opening
|
|
91
|
+
// tag, per-attribute, closing bracket), which for a ~30-component tree
|
|
92
|
+
// is ~100 stream-controller round-trips. Batching collapses those into
|
|
93
|
+
// one encode and one enqueue per shell — measured ~2-4% of total SSR
|
|
94
|
+
// time on CPU profiles.
|
|
95
|
+
const shellChunks: HtmlPart[] = []
|
|
96
|
+
let head = 0
|
|
97
|
+
const bufferedEmit = (chunk: HtmlPart) => {
|
|
98
|
+
shellChunks.push(chunk)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 1. Render the shell. A root-level `use(promise)` has no Suspense
|
|
102
|
+
// boundary to capture it, but App Router SSR commonly suspends at this
|
|
103
|
+
// level while resolving the RSC stream. Wait and retry without leaking
|
|
104
|
+
// partial shell chunks or boundary ids from the aborted attempt.
|
|
105
|
+
let shellRendered = false
|
|
106
|
+
let rootRetries = 0
|
|
107
|
+
let resources: SSRFrame['resources']
|
|
108
|
+
while (!shellRendered) {
|
|
109
|
+
const shellErrors: unknown[] = []
|
|
110
|
+
const chunkCount = shellChunks.length
|
|
111
|
+
const boundaryCount = boundaries.length
|
|
112
|
+
const nextId = state.nextId
|
|
113
|
+
head = 0
|
|
114
|
+
const previous = beginSSR(options.identifierPrefix)
|
|
115
|
+
currentSSRFrame().styleNonce = typeof options.nonce === 'object' ? options.nonce?.style : undefined
|
|
116
|
+
if (resources) currentSSRFrame().resources = resources
|
|
117
|
+
let suspended: Promise<unknown> | undefined
|
|
118
|
+
try {
|
|
119
|
+
if (state.aborted) throw state.reason
|
|
120
|
+
walk(children, {
|
|
121
|
+
emit: bufferedEmit,
|
|
122
|
+
onSuspend: (b) => boundaries.push(b),
|
|
123
|
+
nextBoundaryId: () => state.nextId++,
|
|
124
|
+
onBrowserBailout: options.onBrowserBailout,
|
|
125
|
+
onError: error => { shellErrors.push(error) },
|
|
126
|
+
onHead: () => { head = shellChunks.length },
|
|
127
|
+
})
|
|
128
|
+
shellRendered = true
|
|
129
|
+
state.frame = currentSSRFrame()
|
|
130
|
+
} catch (err) {
|
|
131
|
+
shellChunks.length = chunkCount
|
|
132
|
+
boundaries.length = boundaryCount
|
|
133
|
+
state.nextId = nextId
|
|
134
|
+
if (!isThenable(err)) throw err
|
|
135
|
+
if (++rootRetries > 50) {
|
|
136
|
+
throw new Error('renderToReadableStream exceeded 50 root suspension retries.')
|
|
137
|
+
}
|
|
138
|
+
suspended = err
|
|
139
|
+
} finally {
|
|
140
|
+
resources = currentSSRFrame().resources
|
|
141
|
+
endSSR(previous)
|
|
142
|
+
}
|
|
143
|
+
if (shellRendered) for (const error of shellErrors) options.onError?.(error)
|
|
144
|
+
if (suspended) await Promise.race([suspended, state.cancelled])
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 2. Write the shell when the destination starts reading. Boundaries that
|
|
148
|
+
// completed by then are inlined, and their resources join the shell's.
|
|
149
|
+
let written = false
|
|
150
|
+
state.flush = () => {
|
|
151
|
+
if (written) return
|
|
152
|
+
written = true
|
|
153
|
+
const hints = state.frame?.resources?.drain()
|
|
154
|
+
if (hints) shellChunks.splice(head, 0, hints)
|
|
155
|
+
if (state.frame) state.frame.shellFlushed = true
|
|
156
|
+
let html = partsHtml(shellChunks, state, options)
|
|
157
|
+
|
|
158
|
+
// Inject runtime + bootstrap scripts (once, after shell). Skip the
|
|
159
|
+
// reveal/event-replay runtime when nothing needs it — no pending
|
|
160
|
+
// boundaries to reveal and no bootstrap scripts to guard against early
|
|
161
|
+
// user input. That keeps fully-static SSR responses byte-equivalent to
|
|
162
|
+
// a plain walk and matches React's behavior where
|
|
163
|
+
// `renderToReadableStream` of a static tree emits only the markup.
|
|
164
|
+
const hasBootstrap =
|
|
165
|
+
bootstrapScriptContentToArray(options.bootstrapScriptContent).length > 0 ||
|
|
166
|
+
(options.bootstrapScripts?.length ?? 0) > 0 ||
|
|
167
|
+
(options.bootstrapModules?.length ?? 0) > 0
|
|
168
|
+
if (state.outlined || hasBootstrap) {
|
|
169
|
+
html += `<script${nonce ? ` nonce="${escapeAttr(nonce)}"` : ''}>${BOUNDARY_REVEAL_RUNTIME}</script>`
|
|
170
|
+
for (const content of bootstrapScriptContentToArray(options.bootstrapScriptContent)) {
|
|
171
|
+
html += inlineBootstrapTag(content, nonce)
|
|
172
|
+
}
|
|
173
|
+
for (const s of options.bootstrapScripts ?? []) {
|
|
174
|
+
html += bootstrapTag(s, 'script', nonce)
|
|
175
|
+
}
|
|
176
|
+
for (const m of options.bootstrapModules ?? []) {
|
|
177
|
+
html += bootstrapTag(m, 'module', nonce)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (html) emit(normalizeDocumentShell(html))
|
|
181
|
+
}
|
|
182
|
+
if (state.flowing) state.flush()
|
|
183
|
+
state.onShellReady?.()
|
|
184
|
+
|
|
185
|
+
// 3. Stream suspended boundaries as they resolve
|
|
186
|
+
for (const b of boundaries) streamBoundary(b, emit, options, state)
|
|
187
|
+
await drain(state)
|
|
188
|
+
} catch (err) {
|
|
189
|
+
if (isBrowserError(err)) {
|
|
190
|
+
err = new Error('The server render could not complete because client rendering was requested outside a Suspense boundary.',
|
|
191
|
+
Object.hasOwn(err, 'cause') ? { cause: err.cause } : undefined)
|
|
192
|
+
}
|
|
193
|
+
state.errored = err
|
|
194
|
+
if (options.onError) options.onError(err)
|
|
195
|
+
throw err
|
|
196
|
+
} finally {
|
|
197
|
+
state.closed = true
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function streamBoundary(
|
|
202
|
+
b: SuspendedBoundary,
|
|
203
|
+
emit: Emit,
|
|
204
|
+
options: StreamOptions,
|
|
205
|
+
state: OrchestratorState,
|
|
206
|
+
): void {
|
|
207
|
+
const nonce = scriptNonce(options)
|
|
208
|
+
const task = (async () => {
|
|
209
|
+
try {
|
|
210
|
+
await Promise.race([b.thenable, state.cancelled])
|
|
211
|
+
} catch {}
|
|
212
|
+
if (state.closed) return
|
|
213
|
+
|
|
214
|
+
const defer = (error: unknown) => {
|
|
215
|
+
if (isBrowserError(error)) options.onBrowserBailout?.(error, { componentStack: (error as any).componentStack || b.componentStack })
|
|
216
|
+
else options.onError?.(error)
|
|
217
|
+
if (b.written) emit(`<script${nonce ? ` nonce="${escapeAttr(nonce)}"` : ''}>$RB(${scriptId(boundaryId(b.id, options.identifierPrefix))}${isBrowserError(error) ? '' : ',1'})</script>`)
|
|
218
|
+
else b.marker = isBrowserError(error) ? '$!' : '$E'
|
|
219
|
+
}
|
|
220
|
+
if (state.aborted) { defer(state.reason); return }
|
|
221
|
+
|
|
222
|
+
// Re-render the boundary's children into a string, restoring the
|
|
223
|
+
// provider stack from when the boundary first suspended.
|
|
224
|
+
// A boundary not yet written keeps its content for an inline write; its
|
|
225
|
+
// resources stay with the unwritten shell or segment that will contain it.
|
|
226
|
+
const written = b.written
|
|
227
|
+
const parts: HtmlPart[] = []
|
|
228
|
+
const sub: SuspendedBoundary[] = []
|
|
229
|
+
const resourceScope: ResourceScope = {}
|
|
230
|
+
let styles: string[][] | undefined
|
|
231
|
+
const previous = beginSSR(options.identifierPrefix, state.frame)
|
|
232
|
+
if (written) state.frame?.resources?.takeStylesheets()
|
|
233
|
+
const restore = applyContextSnapshot(b.contextSnapshot)
|
|
234
|
+
try {
|
|
235
|
+
walk(b.children, {
|
|
236
|
+
insertionContext: b.insertionContext,
|
|
237
|
+
treeId: b.treeId,
|
|
238
|
+
emit: (s) => parts.push(s),
|
|
239
|
+
onSuspend: (n) => sub.push(n),
|
|
240
|
+
nextBoundaryId: () => state.nextId++,
|
|
241
|
+
onBrowserBailout: options.onBrowserBailout,
|
|
242
|
+
onError: options.onError,
|
|
243
|
+
componentStack: b.componentStack,
|
|
244
|
+
resourceScope,
|
|
245
|
+
})
|
|
246
|
+
state.frame?.resources?.mergeScope(resourceScope)
|
|
247
|
+
} catch (err) {
|
|
248
|
+
if (isThenable(err)) {
|
|
249
|
+
b.thenable = err
|
|
250
|
+
streamBoundary(b, emit, options, state)
|
|
251
|
+
} else defer(err)
|
|
252
|
+
return
|
|
253
|
+
} finally {
|
|
254
|
+
restore()
|
|
255
|
+
endSSR(previous)
|
|
256
|
+
if (written) {
|
|
257
|
+
const hints = state.frame?.resources?.drain()
|
|
258
|
+
styles = state.frame?.resources?.takeStylesheets()
|
|
259
|
+
if (hints) emit(hints)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (written) emit(segmentHtml(partsHtml(parts, state, options), segmentId(b.id, options.identifierPrefix), b.insertionContext) + revealScript(b.id, nonce, styles, options.identifierPrefix))
|
|
264
|
+
else b.content = parts
|
|
265
|
+
|
|
266
|
+
// Recurse: any nested suspensions inside the now-revealed content
|
|
267
|
+
for (const s of sub) streamBoundary(s, emit, options, state)
|
|
268
|
+
})()
|
|
269
|
+
state.pending.add(task)
|
|
270
|
+
task.then(() => state.pending.delete(task), () => state.pending.delete(task))
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Serialize buffered output. Boundaries that completed or failed before this
|
|
274
|
+
// write are inlined; pending ones keep their fallback and are marked written,
|
|
275
|
+
// so their later completion streams a hidden segment and reveal script.
|
|
276
|
+
function partsHtml(parts: HtmlPart[], state: OrchestratorState, options: StreamOptions): string {
|
|
277
|
+
let html = ''
|
|
278
|
+
for (const part of parts) {
|
|
279
|
+
if (typeof part === 'string') {
|
|
280
|
+
html += part
|
|
281
|
+
continue
|
|
282
|
+
}
|
|
283
|
+
const marker = part.content ? '$' : part.marker ?? '$?'
|
|
284
|
+
if (marker === '$?') part.written = state.outlined = true
|
|
285
|
+
const [open, close] = boundaryEdges(part.id, marker, part.insertionContext, options.identifierPrefix ?? '')
|
|
286
|
+
html += open + partsHtml(part.content ?? part.fallback, state, options) + close
|
|
287
|
+
}
|
|
288
|
+
return html
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function drain(state: OrchestratorState): Promise<void> {
|
|
292
|
+
while (state.pending.size > 0) {
|
|
293
|
+
await Promise.race(state.pending)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function scriptNonce(options: StreamOptions): string | undefined {
|
|
298
|
+
return typeof options.nonce === 'string' ? options.nonce : options.nonce?.script
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function bootstrapScriptContentToArray(
|
|
302
|
+
content: StreamOptions['bootstrapScriptContent'],
|
|
303
|
+
): string[] {
|
|
304
|
+
if (content === undefined) return []
|
|
305
|
+
return typeof content === 'string' ? [content] : [...content]
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function inlineBootstrapTag(content: string, defaultNonce: string | undefined): string {
|
|
309
|
+
const nAttr = defaultNonce ? ` nonce="${escapeAttr(defaultNonce)}"` : ''
|
|
310
|
+
return `<script${nAttr}>${escapeScript(content)}</script>`
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function normalizeDocumentShell(html: string): string {
|
|
314
|
+
const doctypeIndex = html.indexOf('<!DOCTYPE html><html')
|
|
315
|
+
if (doctypeIndex <= 0) return html
|
|
316
|
+
|
|
317
|
+
const headPrefix = html.slice(0, doctypeIndex)
|
|
318
|
+
if (!isHeadPrefix(headPrefix)) return html
|
|
319
|
+
|
|
320
|
+
const documentHtml = html.slice(doctypeIndex)
|
|
321
|
+
const headOpen = documentHtml.match(/<head(?:\s[^>]*)?>/)
|
|
322
|
+
if (!headOpen || headOpen.index === undefined) return html
|
|
323
|
+
|
|
324
|
+
const insertAt = headOpen.index + headOpen[0].length
|
|
325
|
+
return documentHtml.slice(0, insertAt) + headPrefix + documentHtml.slice(insertAt)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function isHeadPrefix(value: string): boolean {
|
|
329
|
+
if (!value) return false
|
|
330
|
+
return stripLeadingHeadTags(value).trim() === ''
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function stripLeadingHeadTags(value: string): string {
|
|
334
|
+
let rest = value
|
|
335
|
+
let changed = true
|
|
336
|
+
while (changed) {
|
|
337
|
+
changed = false
|
|
338
|
+
const next = rest.replace(
|
|
339
|
+
/^\s*(?:<meta\b[^>]*>|<link\b[^>]*>|<base\b[^>]*>|<title\b[^>]*>[\s\S]*?<\/title>|<style\b[^>]*>[\s\S]*?<\/style>|<script\b[^>]*>[\s\S]*?<\/script>)/i,
|
|
340
|
+
'',
|
|
341
|
+
)
|
|
342
|
+
if (next !== rest) {
|
|
343
|
+
rest = next
|
|
344
|
+
changed = true
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return rest
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function bootstrapTag(
|
|
351
|
+
entry: string | { src: string; async?: boolean; nonce?: string },
|
|
352
|
+
kind: 'script' | 'module',
|
|
353
|
+
defaultNonce: string | undefined,
|
|
354
|
+
): string {
|
|
355
|
+
const src = escapeAttr(resourceURL(typeof entry === 'string' ? entry : entry.src))
|
|
356
|
+
const nonce = typeof entry === 'string' ? defaultNonce : entry.nonce ?? defaultNonce
|
|
357
|
+
const nAttr = nonce ? ` nonce="${escapeAttr(nonce)}"` : ''
|
|
358
|
+
if (kind === 'module') return `<script type="module"${nAttr} src="${src}"></script>`
|
|
359
|
+
return `<script async${nAttr} src="${src}"></script>`
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
// Web Streams: renderToReadableStream
|
|
364
|
+
// ---------------------------------------------------------------------------
|
|
365
|
+
|
|
366
|
+
export function renderToReadableStream(
|
|
367
|
+
children: ReactNode,
|
|
368
|
+
options: StreamOptions = {},
|
|
369
|
+
): Promise<ReadableStreamResult> {
|
|
370
|
+
const state = createState()
|
|
371
|
+
const encoder = new TextEncoder()
|
|
372
|
+
let abortListener: (() => void) | undefined
|
|
373
|
+
const detachAbortListener = () => {
|
|
374
|
+
if (abortListener) {
|
|
375
|
+
options.signal?.removeEventListener('abort', abortListener)
|
|
376
|
+
abortListener = undefined
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
let allReadyResolve!: () => void
|
|
381
|
+
let allReadyReject!: (e: unknown) => void
|
|
382
|
+
const allReady = new Promise<void>((r, rej) => {
|
|
383
|
+
allReadyResolve = r
|
|
384
|
+
allReadyReject = rej
|
|
385
|
+
})
|
|
386
|
+
// Shell failures reject the outer promise before callers receive allReady.
|
|
387
|
+
allReady.catch(() => {})
|
|
388
|
+
let shellResolve!: (stream: ReadableStreamResult) => void
|
|
389
|
+
let shellReject!: (error: unknown) => void
|
|
390
|
+
const shell = new Promise<ReadableStreamResult>((resolve, reject) => {
|
|
391
|
+
shellResolve = resolve
|
|
392
|
+
shellReject = reject
|
|
393
|
+
})
|
|
394
|
+
state.onShellReady = () => queueMicrotask(() => shellResolve(Object.assign(stream, { allReady })))
|
|
395
|
+
|
|
396
|
+
const close = (controller: ReadableStreamDefaultController<Uint8Array>) => {
|
|
397
|
+
try {
|
|
398
|
+
controller.close()
|
|
399
|
+
} catch {}
|
|
400
|
+
}
|
|
401
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
402
|
+
start(controller) {
|
|
403
|
+
const emit = (chunk: string) => {
|
|
404
|
+
try {
|
|
405
|
+
controller.enqueue(encoder.encode(chunk))
|
|
406
|
+
} catch {}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (options.signal) {
|
|
410
|
+
abortListener = () => {
|
|
411
|
+
detachAbortListener()
|
|
412
|
+
state.abort(options.signal!.reason)
|
|
413
|
+
}
|
|
414
|
+
options.signal.addEventListener('abort', abortListener)
|
|
415
|
+
if (options.signal.aborted) abortListener()
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
streamHtml(children, emit, options, state).then(
|
|
419
|
+
() => {
|
|
420
|
+
detachAbortListener()
|
|
421
|
+
if (state.flowing) close(controller)
|
|
422
|
+
allReadyResolve()
|
|
423
|
+
},
|
|
424
|
+
(err) => {
|
|
425
|
+
detachAbortListener()
|
|
426
|
+
try {
|
|
427
|
+
controller.error(err)
|
|
428
|
+
} catch {}
|
|
429
|
+
allReadyReject(err)
|
|
430
|
+
shellReject(err)
|
|
431
|
+
},
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
},
|
|
435
|
+
pull(controller) {
|
|
436
|
+
state.flowing = true
|
|
437
|
+
state.flush?.()
|
|
438
|
+
if (state.closed && !state.errored) close(controller)
|
|
439
|
+
},
|
|
440
|
+
cancel(reason) {
|
|
441
|
+
state.abort(reason)
|
|
442
|
+
detachAbortListener()
|
|
443
|
+
},
|
|
444
|
+
}, { highWaterMark: 0 })
|
|
445
|
+
|
|
446
|
+
return shell
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// ---------------------------------------------------------------------------
|
|
450
|
+
// Node Streams: renderToPipeableStream
|
|
451
|
+
// ---------------------------------------------------------------------------
|
|
452
|
+
|
|
453
|
+
export interface PipeableHandle {
|
|
454
|
+
pipe<T extends PipeableWritable>(dest: T): T
|
|
455
|
+
abort(reason?: unknown): void
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export interface PipeableOptions extends StreamOptions {
|
|
459
|
+
onShellReady?: () => void
|
|
460
|
+
onShellError?: (err: unknown) => void
|
|
461
|
+
onAllReady?: () => void
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export function renderToPipeableStream(
|
|
465
|
+
children: ReactNode,
|
|
466
|
+
options: PipeableOptions = {},
|
|
467
|
+
): PipeableHandle {
|
|
468
|
+
const state = createState()
|
|
469
|
+
|
|
470
|
+
let dest: PipeableWritable | null = null
|
|
471
|
+
let shellReady = false
|
|
472
|
+
let shellFailed = false
|
|
473
|
+
let finished = false
|
|
474
|
+
let failed = false
|
|
475
|
+
let failure: unknown
|
|
476
|
+
|
|
477
|
+
const finishDestination = (target: PipeableWritable) => {
|
|
478
|
+
if (failed && target.destroy) target.destroy(failure)
|
|
479
|
+
else target.end()
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// Nothing is emitted before pipe() starts the flow.
|
|
483
|
+
const emit: Emit = (chunk) => {
|
|
484
|
+
if (!failed) dest!.write(chunk)
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
state.onShellReady = () => queueMicrotask(() => {
|
|
488
|
+
if (shellFailed) return
|
|
489
|
+
shellReady = true
|
|
490
|
+
options.onShellReady?.()
|
|
491
|
+
})
|
|
492
|
+
|
|
493
|
+
// Kick off rendering
|
|
494
|
+
streamHtml(children, emit, options, state).then(
|
|
495
|
+
() => {
|
|
496
|
+
finished = true
|
|
497
|
+
if (dest) dest.end()
|
|
498
|
+
options.onAllReady?.()
|
|
499
|
+
},
|
|
500
|
+
(err) => {
|
|
501
|
+
finished = true
|
|
502
|
+
failed = true
|
|
503
|
+
failure = err
|
|
504
|
+
if (!shellReady) {
|
|
505
|
+
shellFailed = true
|
|
506
|
+
options.onShellError?.(err)
|
|
507
|
+
} else {
|
|
508
|
+
if (dest) finishDestination(dest)
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
pipe<T extends PipeableWritable>(target: T): T {
|
|
515
|
+
dest = target
|
|
516
|
+
state.flowing = true
|
|
517
|
+
if (!failed) state.flush?.()
|
|
518
|
+
if (finished) finishDestination(target)
|
|
519
|
+
return target
|
|
520
|
+
},
|
|
521
|
+
abort(reason?: unknown) {
|
|
522
|
+
state.abort(reason)
|
|
523
|
+
},
|
|
524
|
+
}
|
|
525
|
+
}
|