@askrjs/askr 0.0.28 → 0.0.29
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/README.md +44 -172
- package/dist/_virtual/_rolldown/runtime.js +7 -0
- package/dist/bench/components/benchmark-row.d.ts +20 -0
- package/dist/bench/components/benchmark-row.d.ts.map +1 -0
- package/dist/bench/components/benchmark-row.js +42 -0
- package/dist/bench/components/benchmark-row.js.map +1 -0
- package/dist/bench/components/benchmark-table.js +25 -0
- package/dist/bench/components/benchmark-table.js.map +1 -0
- package/dist/benchmark.d.ts +22 -0
- package/dist/benchmark.d.ts.map +1 -0
- package/dist/benchmark.js +64 -1
- package/dist/benchmark.js.map +1 -0
- package/dist/bin/askr-ssg.d.ts +22 -26
- package/dist/bin/askr-ssg.d.ts.map +1 -1
- package/dist/bin/askr-ssg.js +149 -2
- package/dist/bin/askr-ssg.js.map +1 -0
- package/dist/boot/index.d.ts +64 -42
- package/dist/boot/index.d.ts.map +1 -1
- package/dist/boot/index.js +416 -2
- package/dist/boot/index.js.map +1 -0
- package/dist/common/component.d.ts +14 -13
- package/dist/common/component.d.ts.map +1 -1
- package/dist/common/control.d.ts +13 -0
- package/dist/common/control.d.ts.map +1 -0
- package/dist/common/control.js +14 -0
- package/dist/common/control.js.map +1 -0
- package/dist/common/env.js +47 -0
- package/dist/common/env.js.map +1 -0
- package/dist/common/jsx.d.ts +17 -15
- package/dist/common/jsx.d.ts.map +1 -1
- package/dist/common/jsx.js +8 -1
- package/dist/common/jsx.js.map +1 -0
- package/dist/common/props.d.ts +14 -11
- package/dist/common/props.d.ts.map +1 -1
- package/dist/common/router.d.ts +190 -32
- package/dist/common/router.d.ts.map +1 -1
- package/dist/common/ssr-errors.d.ts +6 -3
- package/dist/common/ssr-errors.d.ts.map +1 -1
- package/dist/common/ssr-errors.js +16 -1
- package/dist/common/ssr-errors.js.map +1 -0
- package/dist/common/ssr.d.ts +12 -9
- package/dist/common/ssr.d.ts.map +1 -1
- package/dist/common/vnode.d.ts +17 -15
- package/dist/common/vnode.d.ts.map +1 -1
- package/dist/common/vnode.js +10 -1
- package/dist/common/vnode.js.map +1 -0
- package/dist/components/link.d.ts +37 -25
- package/dist/components/link.d.ts.map +1 -1
- package/dist/components/link.js +64 -1
- package/dist/components/link.js.map +1 -0
- package/dist/control/case.d.ts +17 -0
- package/dist/control/case.d.ts.map +1 -0
- package/dist/control/case.js +69 -0
- package/dist/control/case.js.map +1 -0
- package/dist/control/for.d.ts +23 -0
- package/dist/control/for.d.ts.map +1 -0
- package/dist/control/for.js +62 -0
- package/dist/control/for.js.map +1 -0
- package/dist/control/index.d.ts +4 -0
- package/dist/control/index.js +4 -0
- package/dist/control/shared.js +20 -0
- package/dist/control/shared.js.map +1 -0
- package/dist/control/show.d.ts +14 -0
- package/dist/control/show.d.ts.map +1 -0
- package/dist/control/show.js +33 -0
- package/dist/control/show.js.map +1 -0
- package/dist/dev/invariant.js +29 -2
- package/dist/dev/invariant.js.map +1 -0
- package/dist/dev/logger.js +37 -1
- package/dist/dev/logger.js.map +1 -0
- package/dist/foundations/icon/icon.d.ts +53 -0
- package/dist/foundations/icon/icon.d.ts.map +1 -0
- package/dist/foundations/icon/icon.js +88 -0
- package/dist/foundations/icon/icon.js.map +1 -0
- package/dist/foundations/icon/icon.types.d.ts +21 -0
- package/dist/foundations/icon/icon.types.d.ts.map +1 -0
- package/dist/foundations/index.d.ts +10 -3
- package/dist/foundations/index.js +9 -1
- package/dist/foundations/interactions/interaction-policy.js +93 -1
- package/dist/foundations/interactions/interaction-policy.js.map +1 -0
- package/dist/foundations/interactions/pressable.js +51 -1
- package/dist/foundations/interactions/pressable.js.map +1 -0
- package/dist/foundations/structures/collection.d.ts +25 -40
- package/dist/foundations/structures/collection.d.ts.map +1 -1
- package/dist/foundations/structures/collection.js +51 -1
- package/dist/foundations/structures/collection.js.map +1 -0
- package/dist/foundations/structures/layer.d.ts +47 -68
- package/dist/foundations/structures/layer.d.ts.map +1 -1
- package/dist/foundations/structures/layer.js +81 -1
- package/dist/foundations/structures/layer.js.map +1 -0
- package/dist/foundations/structures/layout.d.ts +6 -3
- package/dist/foundations/structures/layout.d.ts.map +1 -1
- package/dist/foundations/structures/layout.js +13 -1
- package/dist/foundations/structures/layout.js.map +1 -0
- package/dist/foundations/structures/portal.d.ts +17 -10
- package/dist/foundations/structures/portal.d.ts.map +1 -1
- package/dist/foundations/structures/portal.js +105 -1
- package/dist/foundations/structures/portal.js.map +1 -0
- package/dist/foundations/structures/presence.d.ts +11 -5
- package/dist/foundations/structures/presence.d.ts.map +1 -1
- package/dist/foundations/structures/presence.js +39 -1
- package/dist/foundations/structures/presence.js.map +1 -0
- package/dist/foundations/structures/slot.d.ts +11 -8
- package/dist/foundations/structures/slot.d.ts.map +1 -1
- package/dist/foundations/structures/slot.js +41 -1
- package/dist/foundations/structures/slot.js.map +1 -0
- package/dist/foundations/structures.d.ts +7 -14
- package/dist/foundations/structures.js +6 -1
- package/dist/foundations/utilities/aria.js +11 -1
- package/dist/foundations/utilities/aria.js.map +1 -0
- package/dist/foundations/utilities/compose-handlers.js +20 -1
- package/dist/foundations/utilities/compose-handlers.js.map +1 -0
- package/dist/foundations/utilities/compose-ref.d.ts +7 -4
- package/dist/foundations/utilities/compose-ref.d.ts.map +1 -1
- package/dist/foundations/utilities/compose-ref.js +18 -1
- package/dist/foundations/utilities/compose-ref.js.map +1 -0
- package/dist/foundations/utilities/merge-props.js +49 -1
- package/dist/foundations/utilities/merge-props.js.map +1 -0
- package/dist/fx/fx.d.ts +24 -21
- package/dist/fx/fx.d.ts.map +1 -1
- package/dist/fx/fx.js +212 -1
- package/dist/fx/fx.js.map +1 -0
- package/dist/fx/index.d.ts +4 -7
- package/dist/fx/index.js +4 -1
- package/dist/fx/noop.js +9 -1
- package/dist/fx/noop.js.map +1 -0
- package/dist/fx/timing.d.ts +24 -21
- package/dist/fx/timing.d.ts.map +1 -1
- package/dist/fx/timing.js +236 -1
- package/dist/fx/timing.js.map +1 -0
- package/dist/index.d.ts +21 -23
- package/dist/index.js +34 -1
- package/dist/index.js.map +1 -0
- package/dist/jsx/index.d.ts +1 -4
- package/dist/jsx/index.js +3 -1
- package/dist/jsx/types.d.ts +18 -25
- package/dist/jsx/types.d.ts.map +1 -1
- package/dist/jsx/types.js +1 -1
- package/dist/jsx/utils.d.ts +4 -3
- package/dist/jsx/utils.d.ts.map +1 -1
- package/dist/jsx/utils.js +19 -1
- package/dist/jsx/utils.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +8 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +32 -1
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +12 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +45 -1
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/jsx-runtime2.d.ts +2 -0
- package/dist/jsx-runtime2.js +3 -0
- package/dist/renderer/children.js +293 -0
- package/dist/renderer/children.js.map +1 -0
- package/dist/renderer/cleanup.js +150 -1
- package/dist/renderer/cleanup.js.map +1 -0
- package/dist/renderer/dom.js +2439 -1
- package/dist/renderer/dom.js.map +1 -0
- package/dist/renderer/env.js +1 -0
- package/dist/renderer/evaluate.js +450 -1
- package/dist/renderer/evaluate.js.map +1 -0
- package/dist/renderer/fastpath.js +145 -1
- package/dist/renderer/fastpath.js.map +1 -0
- package/dist/renderer/index.js +24 -1
- package/dist/renderer/index.js.map +1 -0
- package/dist/renderer/keyed.js +119 -1
- package/dist/renderer/keyed.js.map +1 -0
- package/dist/renderer/reconcile.js +359 -1
- package/dist/renderer/reconcile.js.map +1 -0
- package/dist/renderer/types.js +1 -1
- package/dist/renderer/utils.js +220 -1
- package/dist/renderer/utils.js.map +1 -0
- package/dist/resources/index.d.ts +3 -9
- package/dist/resources/index.js +3 -1
- package/dist/router/index.d.ts +6 -10
- package/dist/router/index.js +5 -1
- package/dist/router/match.js +83 -1
- package/dist/router/match.js.map +1 -0
- package/dist/router/navigate.d.ts +20 -8
- package/dist/router/navigate.d.ts.map +1 -1
- package/dist/router/navigate.js +288 -1
- package/dist/router/navigate.js.map +1 -0
- package/dist/router/policy.d.ts +22 -0
- package/dist/router/policy.d.ts.map +1 -0
- package/dist/router/policy.js +116 -0
- package/dist/router/policy.js.map +1 -0
- package/dist/router/route-context.js +79 -0
- package/dist/router/route-context.js.map +1 -0
- package/dist/router/route.d.ts +101 -34
- package/dist/router/route.d.ts.map +1 -1
- package/dist/router/route.js +599 -1
- package/dist/router/route.js.map +1 -0
- package/dist/runtime/child-scope.d.ts +21 -0
- package/dist/runtime/child-scope.d.ts.map +1 -0
- package/dist/runtime/child-scope.js +77 -0
- package/dist/runtime/child-scope.js.map +1 -0
- package/dist/runtime/component.d.ts +67 -56
- package/dist/runtime/component.d.ts.map +1 -1
- package/dist/runtime/component.js +462 -1
- package/dist/runtime/component.js.map +1 -0
- package/dist/runtime/context.d.ts +28 -42
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/context.js +205 -1
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/control.d.ts +43 -0
- package/dist/runtime/control.d.ts.map +1 -0
- package/dist/runtime/control.js +125 -0
- package/dist/runtime/control.js.map +1 -0
- package/dist/runtime/derive.d.ts +12 -9
- package/dist/runtime/derive.d.ts.map +1 -1
- package/dist/runtime/derive.js +134 -1
- package/dist/runtime/derive.js.map +1 -0
- package/dist/runtime/dev-namespace.js +57 -1
- package/dist/runtime/dev-namespace.js.map +1 -0
- package/dist/runtime/effect.d.ts +32 -0
- package/dist/runtime/effect.d.ts.map +1 -0
- package/dist/runtime/effect.js +146 -0
- package/dist/runtime/effect.js.map +1 -0
- package/dist/runtime/events.js +162 -1
- package/dist/runtime/events.js.map +1 -0
- package/dist/runtime/execution-model.js +15 -1
- package/dist/runtime/execution-model.js.map +1 -0
- package/dist/runtime/fastlane.js +204 -1
- package/dist/runtime/fastlane.js.map +1 -0
- package/dist/runtime/for-bench.d.ts +41 -0
- package/dist/runtime/for-bench.d.ts.map +1 -0
- package/dist/runtime/for-bench.js +173 -0
- package/dist/runtime/for-bench.js.map +1 -0
- package/dist/runtime/for.d.ts +62 -49
- package/dist/runtime/for.d.ts.map +1 -1
- package/dist/runtime/for.js +668 -1
- package/dist/runtime/for.js.map +1 -0
- package/dist/runtime/operations.d.ts +18 -15
- package/dist/runtime/operations.d.ts.map +1 -1
- package/dist/runtime/operations.js +209 -1
- package/dist/runtime/operations.js.map +1 -0
- package/dist/runtime/perf-metrics.js +64 -1
- package/dist/runtime/perf-metrics.js.map +1 -0
- package/dist/runtime/readable.d.ts +24 -18
- package/dist/runtime/readable.d.ts.map +1 -1
- package/dist/runtime/readable.js +118 -1
- package/dist/runtime/readable.js.map +1 -0
- package/dist/runtime/resource-cell.js +102 -1
- package/dist/runtime/resource-cell.js.map +1 -0
- package/dist/runtime/scheduler.d.ts +51 -50
- package/dist/runtime/scheduler.d.ts.map +1 -1
- package/dist/runtime/scheduler.js +328 -1
- package/dist/runtime/scheduler.js.map +1 -0
- package/dist/runtime/selector.d.ts +7 -5
- package/dist/runtime/selector.d.ts.map +1 -1
- package/dist/runtime/selector.js +188 -1
- package/dist/runtime/selector.js.map +1 -0
- package/dist/runtime/ssr-bridge.js +24 -1
- package/dist/runtime/ssr-bridge.js.map +1 -0
- package/dist/runtime/state.d.ts +11 -19
- package/dist/runtime/state.d.ts.map +1 -1
- package/dist/runtime/state.js +99 -1
- package/dist/runtime/state.js.map +1 -0
- package/dist/ssg/batch-render.d.ts +10 -10
- package/dist/ssg/batch-render.d.ts.map +1 -1
- package/dist/ssg/batch-render.js +84 -1
- package/dist/ssg/batch-render.js.map +1 -0
- package/dist/ssg/create-static-gen.d.ts +28 -29
- package/dist/ssg/create-static-gen.d.ts.map +1 -1
- package/dist/ssg/create-static-gen.js +282 -1
- package/dist/ssg/create-static-gen.js.map +1 -0
- package/dist/ssg/generate-metadata.d.ts +12 -15
- package/dist/ssg/generate-metadata.d.ts.map +1 -1
- package/dist/ssg/generate-metadata.js +94 -1
- package/dist/ssg/generate-metadata.js.map +1 -0
- package/dist/ssg/incremental-manifest.js +56 -1
- package/dist/ssg/incremental-manifest.js.map +1 -0
- package/dist/ssg/index.d.ts +8 -28
- package/dist/ssg/index.js +7 -1
- package/dist/ssg/resolve-ssg-data.d.ts +10 -13
- package/dist/ssg/resolve-ssg-data.d.ts.map +1 -1
- package/dist/ssg/resolve-ssg-data.js +46 -1
- package/dist/ssg/resolve-ssg-data.js.map +1 -0
- package/dist/ssg/route-utils.d.ts +14 -10
- package/dist/ssg/route-utils.d.ts.map +1 -1
- package/dist/ssg/route-utils.js +24 -1
- package/dist/ssg/route-utils.js.map +1 -0
- package/dist/ssg/types.d.ts +157 -144
- package/dist/ssg/types.d.ts.map +1 -1
- package/dist/ssg/write-static-files.d.ts +8 -14
- package/dist/ssg/write-static-files.d.ts.map +1 -1
- package/dist/ssg/write-static-files.js +73 -1
- package/dist/ssg/write-static-files.js.map +1 -0
- package/dist/ssr/attrs.js +93 -1
- package/dist/ssr/attrs.js.map +1 -0
- package/dist/ssr/context.d.ts +31 -35
- package/dist/ssr/context.d.ts.map +1 -1
- package/dist/ssr/context.js +63 -1
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/errors.d.ts +6 -4
- package/dist/ssr/errors.d.ts.map +1 -1
- package/dist/ssr/errors.js +4 -1
- package/dist/ssr/errors.js.map +1 -0
- package/dist/ssr/escape.js +153 -1
- package/dist/ssr/escape.js.map +1 -0
- package/dist/ssr/index.d.ts +74 -72
- package/dist/ssr/index.d.ts.map +1 -1
- package/dist/ssr/index.js +543 -1
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/render-keys.d.ts +27 -29
- package/dist/ssr/render-keys.d.ts.map +1 -1
- package/dist/ssr/render-keys.js +39 -1
- package/dist/ssr/render-keys.js.map +1 -0
- package/dist/ssr/sink.js +86 -1
- package/dist/ssr/sink.js.map +1 -0
- package/dist/ssr/stream-render.js +76 -1
- package/dist/ssr/stream-render.js.map +1 -0
- package/dist/ssr/types.d.ts +14 -13
- package/dist/ssr/types.d.ts.map +1 -1
- package/package.json +49 -69
- package/dist/_virtual/___vite-browser-external.js +0 -1
- package/dist/_virtual/__vite-browser-external.js +0 -1
- package/dist/_virtual/_commonjsHelpers.js +0 -1
- package/dist/_virtual/_fs.js +0 -1
- package/dist/_virtual/_path.js +0 -1
- package/dist/_virtual/main.js +0 -1
- package/dist/_virtual/preload-helper.js +0 -1
- package/dist/bench/benchmark-entry.d.ts +0 -14
- package/dist/bench/benchmark-entry.d.ts.map +0 -1
- package/dist/common/errors.d.ts +0 -53
- package/dist/common/errors.d.ts.map +0 -1
- package/dist/common/index.d.ts +0 -14
- package/dist/common/index.d.ts.map +0 -1
- package/dist/dev/invariant.d.ts +0 -83
- package/dist/dev/invariant.d.ts.map +0 -1
- package/dist/dev/logger.d.ts +0 -13
- package/dist/dev/logger.d.ts.map +0 -1
- package/dist/dev/vite-plugin-askr.d.ts +0 -25
- package/dist/dev/vite-plugin-askr.d.ts.map +0 -1
- package/dist/dev/warnings.d.ts +0 -5
- package/dist/dev/warnings.d.ts.map +0 -1
- package/dist/for/for.d.ts +0 -16
- package/dist/for/for.d.ts.map +0 -1
- package/dist/for/for.js +0 -1
- package/dist/for/index.d.ts +0 -2
- package/dist/for/index.d.ts.map +0 -1
- package/dist/for/index.js +0 -1
- package/dist/foundations/core.d.ts +0 -23
- package/dist/foundations/core.d.ts.map +0 -1
- package/dist/foundations/core.js +0 -1
- package/dist/foundations/index.d.ts.map +0 -1
- package/dist/foundations/interactions/dismissable.d.ts +0 -58
- package/dist/foundations/interactions/dismissable.d.ts.map +0 -1
- package/dist/foundations/interactions/dismissable.js +0 -1
- package/dist/foundations/interactions/focusable.d.ts +0 -16
- package/dist/foundations/interactions/focusable.d.ts.map +0 -1
- package/dist/foundations/interactions/focusable.js +0 -1
- package/dist/foundations/interactions/hoverable.d.ts +0 -19
- package/dist/foundations/interactions/hoverable.d.ts.map +0 -1
- package/dist/foundations/interactions/hoverable.js +0 -1
- package/dist/foundations/interactions/index.d.ts +0 -5
- package/dist/foundations/interactions/index.d.ts.map +0 -1
- package/dist/foundations/interactions/interaction-policy.d.ts +0 -96
- package/dist/foundations/interactions/interaction-policy.d.ts.map +0 -1
- package/dist/foundations/interactions/pressable.d.ts +0 -54
- package/dist/foundations/interactions/pressable.d.ts.map +0 -1
- package/dist/foundations/interactions/roving-focus.d.ts +0 -117
- package/dist/foundations/interactions/roving-focus.d.ts.map +0 -1
- package/dist/foundations/interactions/roving-focus.js +0 -1
- package/dist/foundations/state/controllable.d.ts +0 -53
- package/dist/foundations/state/controllable.d.ts.map +0 -1
- package/dist/foundations/state/controllable.js +0 -1
- package/dist/foundations/state/index.d.ts +0 -2
- package/dist/foundations/state/index.d.ts.map +0 -1
- package/dist/foundations/structures/index.d.ts +0 -5
- package/dist/foundations/structures/index.d.ts.map +0 -1
- package/dist/foundations/structures.d.ts.map +0 -1
- package/dist/foundations/utilities/aria.d.ts +0 -13
- package/dist/foundations/utilities/aria.d.ts.map +0 -1
- package/dist/foundations/utilities/compose-handlers.d.ts +0 -34
- package/dist/foundations/utilities/compose-handlers.d.ts.map +0 -1
- package/dist/foundations/utilities/event-types.d.ts +0 -17
- package/dist/foundations/utilities/event-types.d.ts.map +0 -1
- package/dist/foundations/utilities/index.d.ts +0 -7
- package/dist/foundations/utilities/index.d.ts.map +0 -1
- package/dist/foundations/utilities/merge-props.d.ts +0 -2
- package/dist/foundations/utilities/merge-props.d.ts.map +0 -1
- package/dist/foundations/utilities/use-id.d.ts +0 -29
- package/dist/foundations/utilities/use-id.d.ts.map +0 -1
- package/dist/foundations/utilities/use-id.js +0 -1
- package/dist/fx/index.d.ts.map +0 -1
- package/dist/fx/noop.d.ts +0 -12
- package/dist/fx/noop.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/jsx/index.d.ts.map +0 -1
- package/dist/jsx/jsx-dev-runtime.d.ts +0 -4
- package/dist/jsx/jsx-dev-runtime.d.ts.map +0 -1
- package/dist/jsx/jsx-runtime.d.ts +0 -10
- package/dist/jsx/jsx-runtime.d.ts.map +0 -1
- package/dist/node_modules/esbuild/lib/main.js +0 -65
- package/dist/renderer/cleanup.d.ts +0 -28
- package/dist/renderer/cleanup.d.ts.map +0 -1
- package/dist/renderer/dom.d.ts +0 -64
- package/dist/renderer/dom.d.ts.map +0 -1
- package/dist/renderer/evaluate.d.ts +0 -4
- package/dist/renderer/evaluate.d.ts.map +0 -1
- package/dist/renderer/fastpath.d.ts +0 -7
- package/dist/renderer/fastpath.d.ts.map +0 -1
- package/dist/renderer/index.d.ts +0 -6
- package/dist/renderer/index.d.ts.map +0 -1
- package/dist/renderer/keyed.d.ts +0 -23
- package/dist/renderer/keyed.d.ts.map +0 -1
- package/dist/renderer/reconcile.d.ts +0 -88
- package/dist/renderer/reconcile.d.ts.map +0 -1
- package/dist/renderer/types.d.ts +0 -3
- package/dist/renderer/types.d.ts.map +0 -1
- package/dist/renderer/utils.d.ts +0 -63
- package/dist/renderer/utils.d.ts.map +0 -1
- package/dist/resources/index.d.ts.map +0 -1
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/match.d.ts +0 -22
- package/dist/router/match.d.ts.map +0 -1
- package/dist/runtime/dev-namespace.d.ts +0 -31
- package/dist/runtime/dev-namespace.d.ts.map +0 -1
- package/dist/runtime/events.d.ts +0 -53
- package/dist/runtime/events.d.ts.map +0 -1
- package/dist/runtime/execution-model.d.ts +0 -4
- package/dist/runtime/execution-model.d.ts.map +0 -1
- package/dist/runtime/fastlane.d.ts +0 -27
- package/dist/runtime/fastlane.d.ts.map +0 -1
- package/dist/runtime/hydration.d.ts +0 -25
- package/dist/runtime/hydration.d.ts.map +0 -1
- package/dist/runtime/perf-metrics.d.ts +0 -25
- package/dist/runtime/perf-metrics.d.ts.map +0 -1
- package/dist/runtime/resource-cell.d.ts +0 -35
- package/dist/runtime/resource-cell.d.ts.map +0 -1
- package/dist/runtime/snapshot.d.ts +0 -25
- package/dist/runtime/snapshot.d.ts.map +0 -1
- package/dist/runtime/ssr-bridge.d.ts +0 -10
- package/dist/runtime/ssr-bridge.d.ts.map +0 -1
- package/dist/ssg/discover-resources.d.ts +0 -15
- package/dist/ssg/discover-resources.d.ts.map +0 -1
- package/dist/ssg/incremental-manifest.d.ts +0 -23
- package/dist/ssg/incremental-manifest.d.ts.map +0 -1
- package/dist/ssg/index.d.ts.map +0 -1
- package/dist/ssr/attrs.d.ts +0 -26
- package/dist/ssr/attrs.d.ts.map +0 -1
- package/dist/ssr/create-ssr.d.ts +0 -19
- package/dist/ssr/create-ssr.d.ts.map +0 -1
- package/dist/ssr/escape.d.ts +0 -38
- package/dist/ssr/escape.d.ts.map +0 -1
- package/dist/ssr/sink.d.ts +0 -23
- package/dist/ssr/sink.d.ts.map +0 -1
- package/dist/ssr/stream-render.d.ts +0 -7
- package/dist/ssr/stream-render.d.ts.map +0 -1
- package/dist/vite/index.js +0 -4
|
@@ -1 +1,462 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isDevelopmentEnvironment, isProductionEnvironment } from "../common/env.js";
|
|
2
|
+
import { logger } from "../dev/logger.js";
|
|
3
|
+
import { globalScheduler } from "./scheduler.js";
|
|
4
|
+
import { withContext } from "./context.js";
|
|
5
|
+
import { cleanupReadableSubscriptions, finalizeReadableSubscriptions } from "./readable.js";
|
|
6
|
+
import { incDevCounter, setDevValue } from "./dev-namespace.js";
|
|
7
|
+
import { isBulkCommitActive } from "./fastlane.js";
|
|
8
|
+
import { cleanupInstancesUnder } from "../renderer/cleanup.js";
|
|
9
|
+
import { evaluate } from "../renderer/evaluate.js";
|
|
10
|
+
import "../renderer/index.js";
|
|
11
|
+
//#region src/runtime/component.ts
|
|
12
|
+
/**
|
|
13
|
+
* Register a mount operation that will run after the component is mounted
|
|
14
|
+
* Used by operations (task, on, timer, etc) to execute after render completes
|
|
15
|
+
*/
|
|
16
|
+
function createComponentInstance(id, fn, props, target) {
|
|
17
|
+
const instance = {
|
|
18
|
+
id,
|
|
19
|
+
fn,
|
|
20
|
+
props,
|
|
21
|
+
target,
|
|
22
|
+
mounted: false,
|
|
23
|
+
abortController: null,
|
|
24
|
+
stateValues: [],
|
|
25
|
+
evaluationGeneration: 0,
|
|
26
|
+
notifyUpdate: null,
|
|
27
|
+
_pendingFlushTask: void 0,
|
|
28
|
+
_pendingRunTask: void 0,
|
|
29
|
+
_enqueueRun: void 0,
|
|
30
|
+
stateIndexCheck: -1,
|
|
31
|
+
expectedStateIndices: [],
|
|
32
|
+
firstRenderComplete: false,
|
|
33
|
+
mountOperations: [],
|
|
34
|
+
cleanupFns: [],
|
|
35
|
+
hasPendingUpdate: false,
|
|
36
|
+
ownerFrame: null,
|
|
37
|
+
ssr: false,
|
|
38
|
+
cleanupStrict: false,
|
|
39
|
+
isRoot: false,
|
|
40
|
+
_currentRenderToken: void 0,
|
|
41
|
+
lastRenderToken: 0,
|
|
42
|
+
_pendingReadSources: void 0,
|
|
43
|
+
_lastReadSources: void 0,
|
|
44
|
+
devWarningsEmitted: void 0
|
|
45
|
+
};
|
|
46
|
+
instance._pendingRunTask = () => {
|
|
47
|
+
instance.hasPendingUpdate = false;
|
|
48
|
+
runComponent(instance);
|
|
49
|
+
};
|
|
50
|
+
instance._enqueueRun = () => {
|
|
51
|
+
if (!instance.hasPendingUpdate) {
|
|
52
|
+
instance.hasPendingUpdate = true;
|
|
53
|
+
globalScheduler.enqueue(instance._pendingRunTask);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
instance._pendingFlushTask = instance._pendingRunTask;
|
|
57
|
+
return instance;
|
|
58
|
+
}
|
|
59
|
+
let currentInstance = null;
|
|
60
|
+
let stateIndex = 0;
|
|
61
|
+
function ensureAbortController(instance) {
|
|
62
|
+
let controller = instance.abortController;
|
|
63
|
+
if (!controller || controller.signal.aborted) {
|
|
64
|
+
controller = new AbortController();
|
|
65
|
+
instance.abortController = controller;
|
|
66
|
+
}
|
|
67
|
+
return controller;
|
|
68
|
+
}
|
|
69
|
+
function getCurrentComponentInstance() {
|
|
70
|
+
return currentInstance;
|
|
71
|
+
}
|
|
72
|
+
function setCurrentComponentInstance(instance) {
|
|
73
|
+
currentInstance = instance;
|
|
74
|
+
}
|
|
75
|
+
function registerMountOperation(operation) {
|
|
76
|
+
const instance = getCurrentComponentInstance();
|
|
77
|
+
if (instance) {
|
|
78
|
+
if (isBulkCommitActive()) {
|
|
79
|
+
if (isDevelopmentEnvironment()) throw new Error("registerMountOperation called during bulk commit fast-lane");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
instance.mountOperations.push(operation);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Execute all mount operations for a component
|
|
87
|
+
* These run after the component is rendered and mounted to the DOM
|
|
88
|
+
*/
|
|
89
|
+
function executeMountOperations(instance) {
|
|
90
|
+
if (!instance.isRoot) return;
|
|
91
|
+
const mountOperations = instance.mountOperations;
|
|
92
|
+
if (mountOperations.length === 0) return;
|
|
93
|
+
for (const operation of mountOperations) {
|
|
94
|
+
const result = operation();
|
|
95
|
+
if (result instanceof Promise) result.then((cleanup) => {
|
|
96
|
+
if (typeof cleanup === "function") instance.cleanupFns.push(cleanup);
|
|
97
|
+
});
|
|
98
|
+
else if (typeof result === "function") instance.cleanupFns.push(result);
|
|
99
|
+
}
|
|
100
|
+
instance.mountOperations = [];
|
|
101
|
+
}
|
|
102
|
+
function mountInstanceInline(instance, target) {
|
|
103
|
+
instance.target = target;
|
|
104
|
+
try {
|
|
105
|
+
if (target instanceof Element) {
|
|
106
|
+
const host = target;
|
|
107
|
+
const nextInstances = (host.__ASKR_INSTANCES ?? []).filter((entry) => entry !== instance);
|
|
108
|
+
nextInstances.push(instance);
|
|
109
|
+
host.__ASKR_INSTANCES = nextInstances;
|
|
110
|
+
host.__ASKR_INSTANCE = nextInstances[0] ?? instance;
|
|
111
|
+
}
|
|
112
|
+
} catch (err) {}
|
|
113
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
114
|
+
const wasFirstMount = !instance.mounted;
|
|
115
|
+
instance.mounted = true;
|
|
116
|
+
if (wasFirstMount && instance.mountOperations.length > 0) executeMountOperations(instance);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Run a component synchronously: execute function, handle result
|
|
120
|
+
* This is the internal workhorse that manages async continuations and generation tracking.
|
|
121
|
+
* Must always be called through the scheduler.
|
|
122
|
+
*
|
|
123
|
+
* ACTOR INVARIANT: This function is enqueued as a task, never called directly.
|
|
124
|
+
*/
|
|
125
|
+
let _globalRenderCounter = 0;
|
|
126
|
+
function resetRenderState(instance) {
|
|
127
|
+
instance.stateIndexCheck = -1;
|
|
128
|
+
for (const state of instance.stateValues) if (state) state._hasBeenRead = false;
|
|
129
|
+
instance._pendingReadSources = void 0;
|
|
130
|
+
}
|
|
131
|
+
function nextRenderToken() {
|
|
132
|
+
return ++_globalRenderCounter;
|
|
133
|
+
}
|
|
134
|
+
function renderScopedComponent(instance, startStateIndex, render) {
|
|
135
|
+
const savedInstance = currentInstance;
|
|
136
|
+
const savedStateIndex = stateIndex;
|
|
137
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
138
|
+
resetRenderState(instance);
|
|
139
|
+
instance._currentRenderToken = nextRenderToken();
|
|
140
|
+
currentInstance = instance;
|
|
141
|
+
stateIndex = startStateIndex;
|
|
142
|
+
let didComplete = false;
|
|
143
|
+
try {
|
|
144
|
+
const result = withContext({
|
|
145
|
+
parent: instance.ownerFrame,
|
|
146
|
+
values: null
|
|
147
|
+
}, render);
|
|
148
|
+
didComplete = true;
|
|
149
|
+
return result;
|
|
150
|
+
} finally {
|
|
151
|
+
if (!didComplete) {
|
|
152
|
+
instance._pendingReadSources = void 0;
|
|
153
|
+
instance._currentRenderToken = void 0;
|
|
154
|
+
}
|
|
155
|
+
currentInstance = savedInstance;
|
|
156
|
+
stateIndex = savedStateIndex;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function runComponent(instance) {
|
|
160
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
161
|
+
instance._currentRenderToken = nextRenderToken();
|
|
162
|
+
instance._pendingReadSources = void 0;
|
|
163
|
+
const domSnapshot = instance.target ? instance.target.innerHTML : "";
|
|
164
|
+
const result = executeComponentSync(instance);
|
|
165
|
+
if (result instanceof Promise) throw new Error("Async components are not supported. Components must be synchronous.");
|
|
166
|
+
else {
|
|
167
|
+
const fastlaneBridge = globalThis.__ASKR_FASTLANE;
|
|
168
|
+
try {
|
|
169
|
+
if (fastlaneBridge?.tryRuntimeFastLaneSync?.(instance, result)) {
|
|
170
|
+
warnUnusedStateReads(instance);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
} catch (err) {
|
|
174
|
+
if (isDevelopmentEnvironment()) throw err;
|
|
175
|
+
}
|
|
176
|
+
globalScheduler.enqueue(() => {
|
|
177
|
+
if (!instance.target && instance._placeholder) {
|
|
178
|
+
if (result === null || result === void 0) {
|
|
179
|
+
finalizeReadSubscriptions(instance);
|
|
180
|
+
warnUnusedStateReads(instance);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const placeholder = instance._placeholder;
|
|
184
|
+
const parent = placeholder.parentNode;
|
|
185
|
+
if (!parent) {
|
|
186
|
+
logger.warn("[Askr] placeholder no longer in DOM, cannot render component");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const host = document.createElement("div");
|
|
190
|
+
const executionFrame = {
|
|
191
|
+
parent: instance.ownerFrame,
|
|
192
|
+
values: null
|
|
193
|
+
};
|
|
194
|
+
const oldInstance = currentInstance;
|
|
195
|
+
currentInstance = instance;
|
|
196
|
+
try {
|
|
197
|
+
withContext(executionFrame, () => {
|
|
198
|
+
evaluate(result, host);
|
|
199
|
+
});
|
|
200
|
+
parent.replaceChild(host, placeholder);
|
|
201
|
+
instance.target = host;
|
|
202
|
+
instance._placeholder = void 0;
|
|
203
|
+
host.__ASKR_INSTANCE = instance;
|
|
204
|
+
finalizeReadSubscriptions(instance);
|
|
205
|
+
warnUnusedStateReads(instance);
|
|
206
|
+
} finally {
|
|
207
|
+
currentInstance = oldInstance;
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (instance.target) {
|
|
212
|
+
let oldChildren = [];
|
|
213
|
+
try {
|
|
214
|
+
const wasFirstMount = !instance.mounted;
|
|
215
|
+
const oldInstance = currentInstance;
|
|
216
|
+
currentInstance = instance;
|
|
217
|
+
const executionFrame = {
|
|
218
|
+
parent: instance.ownerFrame,
|
|
219
|
+
values: null
|
|
220
|
+
};
|
|
221
|
+
oldChildren = Array.from(instance.target.childNodes);
|
|
222
|
+
try {
|
|
223
|
+
withContext(executionFrame, () => {
|
|
224
|
+
evaluate(result, instance.target);
|
|
225
|
+
});
|
|
226
|
+
} catch (e) {
|
|
227
|
+
try {
|
|
228
|
+
const newChildren = Array.from(instance.target.childNodes);
|
|
229
|
+
for (const n of newChildren) try {
|
|
230
|
+
cleanupInstancesUnder(n);
|
|
231
|
+
} catch (err) {
|
|
232
|
+
logger.warn("[Askr] error cleaning up failed commit children:", err);
|
|
233
|
+
}
|
|
234
|
+
} catch (_err) {}
|
|
235
|
+
try {
|
|
236
|
+
incDevCounter("__DOM_REPLACE_COUNT");
|
|
237
|
+
setDevValue("__LAST_DOM_REPLACE_STACK_COMPONENT_RESTORE", (/* @__PURE__ */ new Error()).stack);
|
|
238
|
+
} catch (e) {}
|
|
239
|
+
instance.target.replaceChildren(...oldChildren);
|
|
240
|
+
throw e;
|
|
241
|
+
} finally {
|
|
242
|
+
currentInstance = oldInstance;
|
|
243
|
+
}
|
|
244
|
+
finalizeReadSubscriptions(instance);
|
|
245
|
+
warnUnusedStateReads(instance);
|
|
246
|
+
instance.mounted = true;
|
|
247
|
+
if (wasFirstMount && instance.mountOperations.length > 0) executeMountOperations(instance);
|
|
248
|
+
} catch (renderError) {
|
|
249
|
+
try {
|
|
250
|
+
const currentChildren = Array.from(instance.target.childNodes);
|
|
251
|
+
for (const n of currentChildren) try {
|
|
252
|
+
cleanupInstancesUnder(n);
|
|
253
|
+
} catch (err) {
|
|
254
|
+
logger.warn("[Askr] error cleaning up partial children during rollback:", err);
|
|
255
|
+
}
|
|
256
|
+
} catch (_err) {}
|
|
257
|
+
try {
|
|
258
|
+
incDevCounter("__DOM_REPLACE_COUNT");
|
|
259
|
+
setDevValue("__LAST_DOM_REPLACE_STACK_COMPONENT_ROLLBACK", (/* @__PURE__ */ new Error()).stack);
|
|
260
|
+
instance.target.replaceChildren(...oldChildren);
|
|
261
|
+
} catch {
|
|
262
|
+
instance.target.innerHTML = domSnapshot;
|
|
263
|
+
}
|
|
264
|
+
throw renderError;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Execute a component's render function synchronously.
|
|
272
|
+
* Returns either a vnode/promise immediately (does NOT render).
|
|
273
|
+
* Rendering happens separately through runComponent.
|
|
274
|
+
*/
|
|
275
|
+
function renderComponentInline(instance) {
|
|
276
|
+
const hadToken = instance._currentRenderToken !== void 0;
|
|
277
|
+
const prevToken = instance._currentRenderToken;
|
|
278
|
+
const prevPendingReads = instance._pendingReadSources;
|
|
279
|
+
if (!hadToken) {
|
|
280
|
+
instance._currentRenderToken = nextRenderToken();
|
|
281
|
+
instance._pendingReadSources = void 0;
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
const result = executeComponentSync(instance);
|
|
285
|
+
if (!hadToken) finalizeReadSubscriptions(instance);
|
|
286
|
+
return result;
|
|
287
|
+
} finally {
|
|
288
|
+
instance._currentRenderToken = prevToken;
|
|
289
|
+
instance._pendingReadSources = prevPendingReads;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function warnUnusedStateReads(instance) {
|
|
293
|
+
for (let i = 0; i < instance.stateValues.length; i++) {
|
|
294
|
+
const state = instance.stateValues[i];
|
|
295
|
+
const hasCommittedUsage = (state?._readers?.size ?? 0) > 0 || (state?._derivedSubscribers?.size ?? 0) > 0;
|
|
296
|
+
if (state && !state._hasBeenRead && !hasCommittedUsage) try {
|
|
297
|
+
const name = instance.fn?.name || "<anonymous>";
|
|
298
|
+
warnInstanceOnce(instance, `unused-state:${i}`, `[askr] Unused state variable detected in ${name} at index ${i}. State should be read during render or removed.`);
|
|
299
|
+
} catch {
|
|
300
|
+
warnInstanceOnce(instance, `unused-state:${i}`, `[askr] Unused state variable detected. State should be read during render or removed.`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function executeComponentSync(instance) {
|
|
305
|
+
resetRenderState(instance);
|
|
306
|
+
incDevCounter("componentRuns");
|
|
307
|
+
incDevCounter("componentReruns");
|
|
308
|
+
currentInstance = instance;
|
|
309
|
+
stateIndex = 0;
|
|
310
|
+
try {
|
|
311
|
+
const renderStartTime = isDevelopmentEnvironment() ? Date.now() : 0;
|
|
312
|
+
const context = { get signal() {
|
|
313
|
+
return ensureAbortController(instance).signal;
|
|
314
|
+
} };
|
|
315
|
+
const result = withContext({
|
|
316
|
+
parent: instance.ownerFrame,
|
|
317
|
+
values: null
|
|
318
|
+
}, () => instance.fn(instance.props, context));
|
|
319
|
+
const renderTime = Date.now() - renderStartTime;
|
|
320
|
+
if (renderTime > 5) warnInstanceOnce(instance, "slow-render", `[askr] Slow render detected: ${renderTime}ms. Consider optimizing component performance.`);
|
|
321
|
+
if (!instance.firstRenderComplete) instance.firstRenderComplete = true;
|
|
322
|
+
return result;
|
|
323
|
+
} finally {
|
|
324
|
+
currentInstance = null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Public entry point: Execute component with full lifecycle (execute + render)
|
|
329
|
+
* Handles both initial mount and re-execution. Always enqueues through scheduler.
|
|
330
|
+
* Single entry point to avoid lifecycle divergence.
|
|
331
|
+
*/
|
|
332
|
+
function executeComponent(instance) {
|
|
333
|
+
instance.abortController = null;
|
|
334
|
+
instance.notifyUpdate = instance._enqueueRun;
|
|
335
|
+
globalScheduler.enqueue(instance._pendingRunTask);
|
|
336
|
+
}
|
|
337
|
+
function getCurrentInstance() {
|
|
338
|
+
return currentInstance;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Get the abort signal for the current component
|
|
342
|
+
* Used to cancel async operations on unmount/navigation
|
|
343
|
+
*
|
|
344
|
+
* The signal is guaranteed to be aborted when:
|
|
345
|
+
* - Component unmounts
|
|
346
|
+
* - Navigation occurs (different route)
|
|
347
|
+
* - Parent is destroyed
|
|
348
|
+
*
|
|
349
|
+
* IMPORTANT: getSignal() must be called during component render execution.
|
|
350
|
+
* It captures the current component instance from context.
|
|
351
|
+
*
|
|
352
|
+
* @returns AbortSignal that will be aborted when component unmounts
|
|
353
|
+
* @throws Error if called outside component execution
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* // ✅ Correct: called during render, used in async operation
|
|
358
|
+
* export async function UserPage({ id }: { id: string }) {
|
|
359
|
+
* const signal = getSignal();
|
|
360
|
+
* const user = await fetch(`/api/users/${id}`, { signal });
|
|
361
|
+
* return <div>{user.name}</div>;
|
|
362
|
+
* }
|
|
363
|
+
*
|
|
364
|
+
* // ✅ Correct: passed to event handler
|
|
365
|
+
* export function Button() {
|
|
366
|
+
* const signal = getSignal();
|
|
367
|
+
* return {
|
|
368
|
+
* type: 'button',
|
|
369
|
+
* props: {
|
|
370
|
+
* onClick: async () => {
|
|
371
|
+
* const data = await fetch(url, { signal });
|
|
372
|
+
* }
|
|
373
|
+
* }
|
|
374
|
+
* };
|
|
375
|
+
* }
|
|
376
|
+
*
|
|
377
|
+
* // ❌ Wrong: called outside component context
|
|
378
|
+
* const signal = getSignal(); // Error: not in component
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
function getSignal() {
|
|
382
|
+
if (!currentInstance) throw new Error("getSignal() can only be called during component render execution. Ensure you are calling this from inside your component function.");
|
|
383
|
+
return ensureAbortController(currentInstance).signal;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Finalize read subscriptions for an instance after a successful commit.
|
|
387
|
+
* - Update per-state readers map to point to this instance's last committed token
|
|
388
|
+
* - Remove this instance from states it no longer reads
|
|
389
|
+
* This is deterministic and runs synchronously with commit to ensure
|
|
390
|
+
* subscribers are only notified when they actually read a state in their
|
|
391
|
+
* last committed render.
|
|
392
|
+
*/
|
|
393
|
+
function finalizeReadSubscriptions(instance) {
|
|
394
|
+
finalizeReadableSubscriptions(instance);
|
|
395
|
+
}
|
|
396
|
+
function getNextStateIndex() {
|
|
397
|
+
return stateIndex++;
|
|
398
|
+
}
|
|
399
|
+
function claimHookIndex(instance, hookName) {
|
|
400
|
+
const index = getNextStateIndex();
|
|
401
|
+
if (index < instance.stateIndexCheck) throw new Error(`Hook index violation: ${hookName}() call at index ${index}, but previously saw index ${instance.stateIndexCheck}. This happens when render-scoped hooks are called conditionally (inside if/for/etc). Move all ${hookName}() calls to the top level of your component function, before any conditionals.`);
|
|
402
|
+
instance.stateIndexCheck = index;
|
|
403
|
+
if (instance.firstRenderComplete) {
|
|
404
|
+
if (!instance.expectedStateIndices.includes(index)) throw new Error(`Hook order violation: ${hookName}() called at index ${index}, but this index was not in the first render's sequence [${instance.expectedStateIndices.join(", ")}]. This usually means ${hookName}() is inside a conditional or loop. Move all render-scoped hooks to the top level of your component function.`);
|
|
405
|
+
} else instance.expectedStateIndices.push(index);
|
|
406
|
+
return index;
|
|
407
|
+
}
|
|
408
|
+
function getCurrentStateIndex() {
|
|
409
|
+
return stateIndex;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Mount a component instance.
|
|
413
|
+
* This is just an alias to executeComponent() to maintain API compatibility.
|
|
414
|
+
* All lifecycle logic is unified in executeComponent().
|
|
415
|
+
*/
|
|
416
|
+
function mountComponent(instance) {
|
|
417
|
+
executeComponent(instance);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Clean up component — abort pending operations
|
|
421
|
+
* Called on unmount or route change
|
|
422
|
+
*/
|
|
423
|
+
function cleanupComponent(instance) {
|
|
424
|
+
const ownedChildScopes = instance._ownedChildScopes;
|
|
425
|
+
if (ownedChildScopes && ownedChildScopes.size > 0) {
|
|
426
|
+
instance._ownedChildScopes = /* @__PURE__ */ new Set();
|
|
427
|
+
for (const scope of ownedChildScopes) scope.dispose();
|
|
428
|
+
}
|
|
429
|
+
const cleanupErrors = [];
|
|
430
|
+
const cleanupFns = instance.cleanupFns;
|
|
431
|
+
for (const cleanup of cleanupFns) try {
|
|
432
|
+
cleanup();
|
|
433
|
+
} catch (err) {
|
|
434
|
+
if (instance.cleanupStrict) cleanupErrors.push(err);
|
|
435
|
+
else if (isDevelopmentEnvironment()) logger.warn("[Askr] cleanup function threw:", err);
|
|
436
|
+
}
|
|
437
|
+
instance.cleanupFns = [];
|
|
438
|
+
if (cleanupErrors.length > 0) throw new AggregateError(cleanupErrors, `Cleanup failed for component ${instance.id}`);
|
|
439
|
+
cleanupReadableSubscriptions(instance);
|
|
440
|
+
if (instance.abortController && !instance.abortController.signal.aborted) instance.abortController.abort();
|
|
441
|
+
instance.abortController = null;
|
|
442
|
+
instance.notifyUpdate = null;
|
|
443
|
+
instance._placeholder = void 0;
|
|
444
|
+
instance.mounted = false;
|
|
445
|
+
}
|
|
446
|
+
function registerOwnedChildScope(instance, scope) {
|
|
447
|
+
(instance._ownedChildScopes ??= /* @__PURE__ */ new Set()).add(scope);
|
|
448
|
+
}
|
|
449
|
+
function unregisterOwnedChildScope(instance, scope) {
|
|
450
|
+
instance._ownedChildScopes?.delete(scope);
|
|
451
|
+
}
|
|
452
|
+
function warnInstanceOnce(instance, key, message) {
|
|
453
|
+
if (isProductionEnvironment()) return;
|
|
454
|
+
const warnings = instance.devWarningsEmitted ??= /* @__PURE__ */ new Set();
|
|
455
|
+
if (warnings.has(key)) return;
|
|
456
|
+
warnings.add(key);
|
|
457
|
+
logger.warn(message);
|
|
458
|
+
}
|
|
459
|
+
//#endregion
|
|
460
|
+
export { claimHookIndex, cleanupComponent, createComponentInstance, finalizeReadSubscriptions, getCurrentComponentInstance, getCurrentInstance, getCurrentStateIndex, getSignal, mountComponent, mountInstanceInline, registerMountOperation, registerOwnedChildScope, renderComponentInline, renderScopedComponent, setCurrentComponentInstance, unregisterOwnedChildScope, warnUnusedStateReads };
|
|
461
|
+
|
|
462
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","names":[],"sources":["../../src/runtime/component.ts"],"sourcesContent":["/**\n * Component instance lifecycle management\n * Internal only — users never see this\n */\n\nimport { type State } from './state';\nimport { globalScheduler } from './scheduler';\nimport type { Props } from '../common/props';\nimport type { ComponentFunction } from '../common/component';\nimport {\n // withContext is the sole primitive for context restoration\n withContext,\n type ContextFrame,\n} from './context';\nimport {\n type ReadableSource,\n finalizeReadableSubscriptions,\n cleanupReadableSubscriptions,\n} from './readable';\nimport {\n isDevelopmentEnvironment,\n isProductionEnvironment,\n} from '../common/env';\nimport { logger } from '../dev/logger';\nimport { incDevCounter, setDevValue } from './dev-namespace';\n\nexport type { ComponentFunction } from '../common/component';\n\nexport interface ComponentInstance {\n id: string;\n fn: ComponentFunction;\n props: Props;\n target: Element | null;\n mounted: boolean;\n abortController: AbortController | null; // Lazily created per-component abort lifecycle\n ssr?: boolean; // Set to true for SSR temporary instances\n // Opt-in strict cleanup mode: when true cleanup errors are aggregated and re-thrown\n cleanupStrict?: boolean;\n stateValues: State<unknown>[]; // Persistent state storage across renders\n evaluationGeneration: number; // Prevents stale async evaluation completions\n notifyUpdate: (() => void) | null; // Callback for state updates (persisted on instance)\n // Internal: prebound helpers to avoid per-update closures (allocation hot-path)\n _pendingFlushTask?: () => void; // Clears hasPendingUpdate and triggers notifyUpdate\n _pendingRunTask?: () => void; // Clears hasPendingUpdate and runs component\n _enqueueRun?: () => void; // Batches run requests and enqueues _pendingRunTask\n stateIndexCheck: number; // Track state indices to catch conditional calls\n expectedStateIndices: number[]; // Expected sequence of render-scoped hook indices (frozen after first render)\n firstRenderComplete: boolean; // Flag to detect transition from first to subsequent renders\n mountOperations: Array<\n () => void | (() => void) | Promise<void | (() => void)>\n >; // Operations to run when component mounts\n cleanupFns: Array<() => void>; // Cleanup functions to run on unmount\n hasPendingUpdate: boolean; // Flag to batch state updates (coalescing)\n ownerFrame: ContextFrame | null; // Provider chain for this component (set by Scope, never overwritten)\n isRoot?: boolean;\n\n // Render-tracking for precise subscriptions (internal)\n _currentRenderToken?: number; // Token for the in-progress render (set before render)\n lastRenderToken?: number; // Token of the last *committed* render\n _pendingReadSources?: Set<ReadableSource<unknown>>; // Readables read during the in-progress render\n _lastReadSources?: Set<ReadableSource<unknown>>; // Readables read during the last committed render\n devWarningsEmitted?: Set<string>; // Dev-only warning dedupe for this instance\n\n // Placeholder for null-returning components. When a component initially returns\n // null, we create a comment placeholder so updates can replace it with content.\n _placeholder?: Comment;\n _ownedChildScopes?: Set<{\n key: string | number;\n dispose(): void;\n }>;\n}\n\nexport function createComponentInstance(\n id: string,\n fn: ComponentFunction,\n props: Props,\n target: Element | null\n): ComponentInstance {\n const instance: ComponentInstance = {\n id,\n fn,\n props,\n target,\n mounted: false,\n abortController: null,\n stateValues: [],\n evaluationGeneration: 0,\n notifyUpdate: null,\n // Prebound helpers (initialized below) to avoid per-update allocations\n _pendingFlushTask: undefined,\n _pendingRunTask: undefined,\n _enqueueRun: undefined,\n stateIndexCheck: -1,\n expectedStateIndices: [],\n firstRenderComplete: false,\n mountOperations: [],\n cleanupFns: [],\n hasPendingUpdate: false,\n ownerFrame: null, // Will be set by renderer when vnode is marked\n ssr: false,\n cleanupStrict: false,\n isRoot: false,\n\n // Render-tracking (for precise state subscriptions)\n _currentRenderToken: undefined,\n lastRenderToken: 0,\n _pendingReadSources: undefined,\n _lastReadSources: undefined,\n devWarningsEmitted: undefined,\n };\n\n // Initialize prebound helper tasks once per instance to avoid allocations\n instance._pendingRunTask = () => {\n // Clear pending flag when the run task executes\n instance.hasPendingUpdate = false;\n // Execute component run (will set up notifyUpdate before render)\n runComponent(instance);\n };\n\n instance._enqueueRun = () => {\n if (!instance.hasPendingUpdate) {\n instance.hasPendingUpdate = true;\n // Enqueue single run task (coalesces multiple writes)\n globalScheduler.enqueue(instance._pendingRunTask!);\n }\n };\n\n // Default state-driven updates enqueue the run task directly. Specialized\n // runtimes (for example `For` item instances) can still override this hook.\n instance._pendingFlushTask = instance._pendingRunTask;\n\n return instance;\n}\n\nlet currentInstance: ComponentInstance | null = null;\nlet stateIndex = 0;\n\ntype OwnedChildScope = {\n key: string | number;\n dispose(): void;\n};\n\nfunction ensureAbortController(instance: ComponentInstance): AbortController {\n let controller = instance.abortController;\n if (!controller || controller.signal.aborted) {\n controller = new AbortController();\n instance.abortController = controller;\n }\n return controller;\n}\n\n// Export for state.ts to access\nexport function getCurrentComponentInstance(): ComponentInstance | null {\n return currentInstance;\n}\n\n// Export for SSR to set temporary instance\nexport function setCurrentComponentInstance(\n instance: ComponentInstance | null\n): void {\n currentInstance = instance;\n}\n\n/**\n * Register a mount operation that will run after the component is mounted\n * Used by operations (task, on, timer, etc) to execute after render completes\n */\nimport { isBulkCommitActive } from './fastlane';\nimport { evaluate, cleanupInstancesUnder } from '../renderer';\n\nexport function registerMountOperation(\n operation: () => void | (() => void) | Promise<void | (() => void)>\n): void {\n const instance = getCurrentComponentInstance();\n if (instance) {\n // If we're in bulk-commit fast lane, registering mount operations is a\n // violation of the fast-lane preconditions. Throw in dev, otherwise ignore\n // silently in production (we must avoid scheduling work during bulk commit).\n if (isBulkCommitActive()) {\n if (isDevelopmentEnvironment()) {\n throw new Error(\n 'registerMountOperation called during bulk commit fast-lane'\n );\n }\n return;\n }\n instance.mountOperations.push(operation);\n }\n}\n\n/**\n * Execute all mount operations for a component\n * These run after the component is rendered and mounted to the DOM\n */\nfunction executeMountOperations(instance: ComponentInstance): void {\n // Only execute mount operations for root app instance. Child component\n // operations are currently registered but should not be executed (per\n // contract tests). They remain registered for cleanup purposes.\n if (!instance.isRoot) return;\n\n const mountOperations = instance.mountOperations;\n if (mountOperations.length === 0) {\n return;\n }\n\n for (const operation of mountOperations) {\n const result = operation();\n if (result instanceof Promise) {\n result.then((cleanup) => {\n if (typeof cleanup === 'function') {\n instance.cleanupFns.push(cleanup);\n }\n });\n } else if (typeof result === 'function') {\n instance.cleanupFns.push(result);\n }\n }\n // Clear the operations array so they don't run again on subsequent renders\n instance.mountOperations = [];\n}\n\nexport function mountInstanceInline(\n instance: ComponentInstance,\n target: Element | null\n): void {\n instance.target = target;\n // Record backref on host element so renderer can clean up when the\n // node is removed. Avoids leaks if the node is detached or replaced.\n try {\n if (target instanceof Element) {\n const host = target as Element & {\n __ASKR_INSTANCE?: ComponentInstance;\n __ASKR_INSTANCES?: ComponentInstance[];\n };\n const instances = host.__ASKR_INSTANCES ?? [];\n const nextInstances = instances.filter((entry) => entry !== instance);\n nextInstances.push(instance);\n host.__ASKR_INSTANCES = nextInstances;\n host.__ASKR_INSTANCE = nextInstances[0] ?? instance;\n }\n } catch (err) {\n void err;\n }\n\n // Ensure notifyUpdate is available for async resource completions that may\n // try to trigger re-render. This mirrors the setup in executeComponent().\n // Use prebound enqueue helper to avoid allocating a new closure\n instance.notifyUpdate = instance._enqueueRun!;\n\n const wasFirstMount = !instance.mounted;\n instance.mounted = true;\n if (wasFirstMount && instance.mountOperations.length > 0) {\n executeMountOperations(instance);\n }\n}\n\n/**\n * Run a component synchronously: execute function, handle result\n * This is the internal workhorse that manages async continuations and generation tracking.\n * Must always be called through the scheduler.\n *\n * ACTOR INVARIANT: This function is enqueued as a task, never called directly.\n */\nlet _globalRenderCounter = 0;\n\nfunction resetRenderState(instance: ComponentInstance): void {\n instance.stateIndexCheck = -1;\n\n for (const state of instance.stateValues) {\n if (state) {\n state._hasBeenRead = false;\n }\n }\n\n instance._pendingReadSources = undefined;\n}\n\nfunction nextRenderToken(): number {\n return ++_globalRenderCounter;\n}\n\nexport function renderScopedComponent<T>(\n instance: ComponentInstance,\n startStateIndex: number,\n render: () => T\n): T {\n const savedInstance = currentInstance;\n const savedStateIndex = stateIndex;\n\n instance.notifyUpdate = instance._enqueueRun!;\n resetRenderState(instance);\n instance._currentRenderToken = nextRenderToken();\n\n currentInstance = instance;\n stateIndex = startStateIndex;\n\n let didComplete = false;\n\n try {\n const executionFrame: ContextFrame = {\n parent: instance.ownerFrame,\n values: null,\n };\n const result = withContext(executionFrame, render);\n didComplete = true;\n return result;\n } finally {\n if (!didComplete) {\n instance._pendingReadSources = undefined;\n instance._currentRenderToken = undefined;\n }\n currentInstance = savedInstance;\n stateIndex = savedStateIndex;\n }\n}\n\nfunction runComponent(instance: ComponentInstance): void {\n // CRITICAL: Ensure notifyUpdate is available for state.set() calls during this render.\n // This must be set before executeComponentSync() runs, not after.\n // Use prebound enqueue helper to avoid allocating per-render closures\n instance.notifyUpdate = instance._enqueueRun!;\n\n // Assign a token for this in-progress render and start a fresh pending-read set\n instance._currentRenderToken = nextRenderToken();\n instance._pendingReadSources = undefined;\n const domSnapshot = instance.target ? instance.target.innerHTML : '';\n\n const result = executeComponentSync(instance);\n if (result instanceof Promise) {\n // Async components are not supported. Components must be synchronous and\n // must not return a Promise from their render function.\n throw new Error(\n 'Async components are not supported. Components must be synchronous.'\n );\n } else {\n // Try runtime fast-lane synchronously; if it activates we do not enqueue\n // follow-up work and the commit happens atomically in this task.\n // (Runtime fast-lane has conservative preconditions.)\n const fastlaneBridge = (\n globalThis as {\n __ASKR_FASTLANE?: {\n tryRuntimeFastLaneSync?: (\n instance: unknown,\n result: unknown\n ) => boolean;\n };\n }\n ).__ASKR_FASTLANE;\n try {\n const used = fastlaneBridge?.tryRuntimeFastLaneSync?.(instance, result);\n if (used) {\n warnUnusedStateReads(instance);\n return;\n }\n } catch (err) {\n // If invariant check failed in dev, surface the error; otherwise fall back\n if (isDevelopmentEnvironment()) throw err;\n }\n\n // Fallback: enqueue the render/commit normally\n globalScheduler.enqueue(() => {\n // Handle placeholder-based updates: when a component initially returned null,\n // we created a comment placeholder. If it now has content, we need to create\n // a host element and replace the placeholder.\n if (!instance.target && instance._placeholder) {\n // Component previously returned null (has placeholder), check if now has content\n if (result === null || result === undefined) {\n // Still null - nothing to do, keep placeholder\n finalizeReadSubscriptions(instance);\n warnUnusedStateReads(instance);\n return;\n }\n\n // Has content now - need to create DOM and replace placeholder\n const placeholder = instance._placeholder;\n const parent = placeholder.parentNode;\n if (!parent) {\n // Placeholder was removed from DOM - can't render\n logger.warn(\n '[Askr] placeholder no longer in DOM, cannot render component'\n );\n return;\n }\n\n // Create a new host element for the content\n const host = document.createElement('div');\n const executionFrame: ContextFrame = {\n parent: instance.ownerFrame,\n values: null,\n };\n\n // Set up instance for normal updates\n const oldInstance = currentInstance;\n currentInstance = instance;\n try {\n withContext(executionFrame, () => {\n evaluate(result, host);\n });\n\n // Replace placeholder with host\n parent.replaceChild(host, placeholder);\n\n // Set up instance for future updates\n instance.target = host;\n instance._placeholder = undefined;\n (\n host as Element & { __ASKR_INSTANCE?: ComponentInstance }\n ).__ASKR_INSTANCE = instance;\n\n finalizeReadSubscriptions(instance);\n warnUnusedStateReads(instance);\n } finally {\n currentInstance = oldInstance;\n }\n return;\n }\n\n if (instance.target) {\n let oldChildren: Node[] = [];\n try {\n const wasFirstMount = !instance.mounted;\n // Ensure nested component executions during evaluation have access to\n // the current component instance. This allows nested components to\n // call `state()`, `resource()`, and other runtime helpers which\n // rely on `getCurrentComponentInstance()` being available.\n const oldInstance = currentInstance;\n currentInstance = instance;\n const executionFrame: ContextFrame = {\n parent: instance.ownerFrame,\n values: null,\n };\n // Capture snapshot of current children (by reference) so we can\n // restore them on render failure without losing event listeners or\n // instance attachments.\n oldChildren = Array.from(instance.target.childNodes);\n\n try {\n withContext(executionFrame, () => {\n evaluate(result, instance.target);\n });\n } catch (e) {\n // If evaluation failed, attempt to cleanup any partially-added nodes\n // and restore the old children to preserve listeners and instances.\n try {\n const newChildren = Array.from(instance.target.childNodes);\n for (const n of newChildren) {\n try {\n cleanupInstancesUnder(n);\n } catch (err) {\n logger.warn(\n '[Askr] error cleaning up failed commit children:',\n err\n );\n }\n }\n } catch (_err) {\n void _err;\n }\n\n // Restore original children by re-inserting the old node references\n // this preserves attached listeners and instance backrefs.\n try {\n incDevCounter('__DOM_REPLACE_COUNT');\n setDevValue(\n '__LAST_DOM_REPLACE_STACK_COMPONENT_RESTORE',\n new Error().stack\n );\n } catch (e) {\n void e;\n }\n instance.target.replaceChildren(...oldChildren);\n throw e;\n } finally {\n currentInstance = oldInstance;\n }\n\n // Commit succeeded — finalize recorded state reads so subscriptions reflect\n // the last *committed* render. This updates per-state reader maps\n // deterministically and synchronously with the commit.\n finalizeReadSubscriptions(instance);\n warnUnusedStateReads(instance);\n\n instance.mounted = true;\n // Execute mount operations after first mount (do NOT run these with\n // currentInstance set - they may perform state mutations/registrations)\n if (wasFirstMount && instance.mountOperations.length > 0) {\n executeMountOperations(instance);\n }\n } catch (renderError) {\n // Atomic rendering: rollback on render error. Attempt non-lossy restore of\n // original child node references to preserve listeners/instances.\n try {\n const currentChildren = Array.from(instance.target.childNodes);\n for (const n of currentChildren) {\n try {\n cleanupInstancesUnder(n);\n } catch (err) {\n logger.warn(\n '[Askr] error cleaning up partial children during rollback:',\n err\n );\n }\n }\n } catch (_err) {\n void _err;\n }\n\n try {\n incDevCounter('__DOM_REPLACE_COUNT');\n setDevValue(\n '__LAST_DOM_REPLACE_STACK_COMPONENT_ROLLBACK',\n new Error().stack\n );\n instance.target.replaceChildren(...oldChildren);\n } catch {\n // Fallback to innerHTML restore if replaceChildren fails for some reason.\n instance.target.innerHTML = domSnapshot;\n }\n\n throw renderError;\n }\n }\n });\n }\n}\n\n/**\n * Execute a component's render function synchronously.\n * Returns either a vnode/promise immediately (does NOT render).\n * Rendering happens separately through runComponent.\n */\nexport function renderComponentInline(\n instance: ComponentInstance\n): unknown | Promise<unknown> {\n // Ensure inline executions (rendered during parent's evaluate) still\n // receive a render token and have their state reads finalized so\n // subscriptions are correctly recorded. If this function is called\n // as part of a scheduled run, the token will already be set by\n // runComponent and we should not overwrite it.\n const hadToken = instance._currentRenderToken !== undefined;\n const prevToken = instance._currentRenderToken;\n const prevPendingReads = instance._pendingReadSources;\n if (!hadToken) {\n instance._currentRenderToken = nextRenderToken();\n instance._pendingReadSources = undefined;\n }\n\n try {\n const result = executeComponentSync(instance);\n // If we set the token for inline execution, finalize subscriptions now\n // because the component is effectively committed as part of the parent's\n // synchronous evaluation.\n if (!hadToken) {\n finalizeReadSubscriptions(instance);\n }\n return result;\n } finally {\n // Restore previous token/read states for nested inline render scenarios\n instance._currentRenderToken = prevToken;\n instance._pendingReadSources = prevPendingReads;\n }\n}\n\nexport function warnUnusedStateReads(instance: ComponentInstance): void {\n for (let i = 0; i < instance.stateValues.length; i++) {\n const state = instance.stateValues[i];\n const hasCommittedUsage =\n (state?._readers?.size ?? 0) > 0 ||\n ((state as { _derivedSubscribers?: Set<unknown> } | undefined)\n ?._derivedSubscribers?.size ?? 0) > 0;\n\n if (state && !state._hasBeenRead && !hasCommittedUsage) {\n try {\n const name = instance.fn?.name || '<anonymous>';\n warnInstanceOnce(\n instance,\n `unused-state:${i}`,\n `[askr] Unused state variable detected in ${name} at index ${i}. State should be read during render or removed.`\n );\n } catch {\n warnInstanceOnce(\n instance,\n `unused-state:${i}`,\n `[askr] Unused state variable detected. State should be read during render or removed.`\n );\n }\n }\n }\n}\n\nfunction executeComponentSync(\n instance: ComponentInstance\n): unknown | Promise<unknown> {\n resetRenderState(instance);\n incDevCounter('componentRuns');\n incDevCounter('componentReruns');\n\n currentInstance = instance;\n stateIndex = 0;\n\n try {\n // Track render time in dev mode\n const renderStartTime = isDevelopmentEnvironment() ? Date.now() : 0;\n\n // Create context object with abort signal\n const context = {\n get signal(): AbortSignal {\n return ensureAbortController(instance).signal;\n },\n };\n\n // Execute component within its owner frame (provider chain).\n // This ensures all context reads see the correct provider values.\n // We create a new execution frame whose parent is the ownerFrame. The\n // `values` map is lazily allocated to avoid per-render Map allocations\n // for components that do not use context.\n const executionFrame: ContextFrame = {\n parent: instance.ownerFrame,\n values: null,\n };\n const result = withContext(executionFrame, () =>\n instance.fn(instance.props, context)\n );\n\n // Check render time\n const renderTime = Date.now() - renderStartTime;\n if (renderTime > 5) {\n warnInstanceOnce(\n instance,\n 'slow-render',\n `[askr] Slow render detected: ${renderTime}ms. Consider optimizing component performance.`\n );\n }\n\n // Mark first render complete after successful execution\n // This enables hook order validation on subsequent renders\n if (!instance.firstRenderComplete) {\n instance.firstRenderComplete = true;\n }\n\n return result;\n } finally {\n // Synchronous path: we did not push a fresh frame, so nothing to pop here.\n currentInstance = null;\n }\n}\n\n/**\n * Public entry point: Execute component with full lifecycle (execute + render)\n * Handles both initial mount and re-execution. Always enqueues through scheduler.\n * Single entry point to avoid lifecycle divergence.\n */\nexport function executeComponent(instance: ComponentInstance): void {\n // Lazily recreate abort controller only when signal is actually requested.\n instance.abortController = null;\n\n // Setup notifyUpdate callback using prebound helper to avoid per-call closures\n instance.notifyUpdate = instance._enqueueRun!;\n\n // Enqueue the initial component run\n globalScheduler.enqueue(instance._pendingRunTask!);\n}\n\nexport function getCurrentInstance(): ComponentInstance | null {\n return currentInstance;\n}\n\n/**\n * Get the abort signal for the current component\n * Used to cancel async operations on unmount/navigation\n *\n * The signal is guaranteed to be aborted when:\n * - Component unmounts\n * - Navigation occurs (different route)\n * - Parent is destroyed\n *\n * IMPORTANT: getSignal() must be called during component render execution.\n * It captures the current component instance from context.\n *\n * @returns AbortSignal that will be aborted when component unmounts\n * @throws Error if called outside component execution\n *\n * @example\n * ```ts\n * // ✅ Correct: called during render, used in async operation\n * export async function UserPage({ id }: { id: string }) {\n * const signal = getSignal();\n * const user = await fetch(`/api/users/${id}`, { signal });\n * return <div>{user.name}</div>;\n * }\n *\n * // ✅ Correct: passed to event handler\n * export function Button() {\n * const signal = getSignal();\n * return {\n * type: 'button',\n * props: {\n * onClick: async () => {\n * const data = await fetch(url, { signal });\n * }\n * }\n * };\n * }\n *\n * // ❌ Wrong: called outside component context\n * const signal = getSignal(); // Error: not in component\n * ```\n */\nexport function getSignal(): AbortSignal {\n if (!currentInstance) {\n throw new Error(\n 'getSignal() can only be called during component render execution. ' +\n 'Ensure you are calling this from inside your component function.'\n );\n }\n return ensureAbortController(currentInstance).signal;\n}\n\n/**\n * Finalize read subscriptions for an instance after a successful commit.\n * - Update per-state readers map to point to this instance's last committed token\n * - Remove this instance from states it no longer reads\n * This is deterministic and runs synchronously with commit to ensure\n * subscribers are only notified when they actually read a state in their\n * last committed render.\n */\nexport function finalizeReadSubscriptions(instance: ComponentInstance): void {\n finalizeReadableSubscriptions(instance);\n}\n\nexport function getNextStateIndex(): number {\n return stateIndex++;\n}\n\nexport function claimHookIndex(\n instance: ComponentInstance,\n hookName: string\n): number {\n const index = getNextStateIndex();\n\n if (index < instance.stateIndexCheck) {\n throw new Error(\n `Hook index violation: ${hookName}() call at index ${index}, ` +\n `but previously saw index ${instance.stateIndexCheck}. ` +\n `This happens when render-scoped hooks are called conditionally (inside if/for/etc). ` +\n `Move all ${hookName}() calls to the top level of your component function, ` +\n `before any conditionals.`\n );\n }\n\n instance.stateIndexCheck = index;\n\n if (instance.firstRenderComplete) {\n if (!instance.expectedStateIndices.includes(index)) {\n throw new Error(\n `Hook order violation: ${hookName}() called at index ${index}, ` +\n `but this index was not in the first render's sequence [${instance.expectedStateIndices.join(', ')}]. ` +\n `This usually means ${hookName}() is inside a conditional or loop. ` +\n `Move all render-scoped hooks to the top level of your component function.`\n );\n }\n } else {\n instance.expectedStateIndices.push(index);\n }\n\n return index;\n}\n\nexport function getCurrentStateIndex(): number {\n return stateIndex;\n}\n\nexport function resetStateIndex(): void {\n stateIndex = 0;\n}\n\nexport function setStateIndex(value: number): void {\n stateIndex = value;\n}\n\n/**\n * Mount a component instance.\n * This is just an alias to executeComponent() to maintain API compatibility.\n * All lifecycle logic is unified in executeComponent().\n */\nexport function mountComponent(instance: ComponentInstance): void {\n executeComponent(instance);\n}\n\n/**\n * Clean up component — abort pending operations\n * Called on unmount or route change\n */\nexport function cleanupComponent(instance: ComponentInstance): void {\n const ownedChildScopes = instance._ownedChildScopes;\n if (ownedChildScopes && ownedChildScopes.size > 0) {\n instance._ownedChildScopes = new Set();\n for (const scope of ownedChildScopes) {\n scope.dispose();\n }\n }\n\n // Execute cleanup functions (from mount effects)\n const cleanupErrors: unknown[] = [];\n const cleanupFns = instance.cleanupFns;\n for (const cleanup of cleanupFns) {\n try {\n cleanup();\n } catch (err) {\n if (instance.cleanupStrict) {\n cleanupErrors.push(err);\n } else {\n // Preserve previous behavior: log warnings in dev and continue\n if (isDevelopmentEnvironment()) {\n logger.warn('[Askr] cleanup function threw:', err);\n }\n }\n }\n }\n instance.cleanupFns = [];\n if (cleanupErrors.length > 0) {\n // If strict mode, surface all cleanup errors as an AggregateError after attempting all cleanups\n throw new AggregateError(\n cleanupErrors,\n `Cleanup failed for component ${instance.id}`\n );\n }\n\n // Remove deterministic state subscriptions for this instance\n cleanupReadableSubscriptions(instance);\n\n // Abort all pending operations\n if (instance.abortController && !instance.abortController.signal.aborted) {\n instance.abortController.abort();\n }\n instance.abortController = null;\n\n // Clear update callback to prevent dangling references and stale updates\n instance.notifyUpdate = null;\n instance._placeholder = undefined;\n\n // Mark instance as unmounted so external tracking (e.g., portal host lists)\n // can deterministically prune stale instances. Not marking this leads to\n // retained \"mounted\" flags across cleanup boundaries which breaks\n // owner selection in the portal fallback.\n instance.mounted = false;\n}\n\nexport function registerOwnedChildScope(\n instance: ComponentInstance,\n scope: OwnedChildScope\n): void {\n const scopes = (instance._ownedChildScopes ??= new Set());\n scopes.add(scope);\n}\n\nexport function unregisterOwnedChildScope(\n instance: ComponentInstance,\n scope: OwnedChildScope\n): void {\n instance._ownedChildScopes?.delete(scope);\n}\n\nfunction warnInstanceOnce(\n instance: ComponentInstance,\n key: string,\n message: string\n): void {\n if (isProductionEnvironment()) return;\n const warnings = (instance.devWarningsEmitted ??= new Set());\n if (warnings.has(key)) return;\n warnings.add(key);\n logger.warn(message);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwEA,SAAgB,wBACd,IACA,IACA,OACA,QACmB;CACnB,MAAM,WAA8B;EAClC;EACA;EACA;EACA;EACA,SAAS;EACT,iBAAiB;EACjB,aAAa,EAAE;EACf,sBAAsB;EACtB,cAAc;EAEd,mBAAmB;EACnB,iBAAiB;EACjB,aAAa;EACb,iBAAiB;EACjB,sBAAsB,EAAE;EACxB,qBAAqB;EACrB,iBAAiB,EAAE;EACnB,YAAY,EAAE;EACd,kBAAkB;EAClB,YAAY;EACZ,KAAK;EACL,eAAe;EACf,QAAQ;EAGR,qBAAqB;EACrB,iBAAiB;EACjB,qBAAqB;EACrB,kBAAkB;EAClB,oBAAoB;EACrB;AAGD,UAAS,wBAAwB;AAE/B,WAAS,mBAAmB;AAE5B,eAAa,SAAS;;AAGxB,UAAS,oBAAoB;AAC3B,MAAI,CAAC,SAAS,kBAAkB;AAC9B,YAAS,mBAAmB;AAE5B,mBAAgB,QAAQ,SAAS,gBAAiB;;;AAMtD,UAAS,oBAAoB,SAAS;AAEtC,QAAO;;AAGT,IAAI,kBAA4C;AAChD,IAAI,aAAa;AAOjB,SAAS,sBAAsB,UAA8C;CAC3E,IAAI,aAAa,SAAS;AAC1B,KAAI,CAAC,cAAc,WAAW,OAAO,SAAS;AAC5C,eAAa,IAAI,iBAAiB;AAClC,WAAS,kBAAkB;;AAE7B,QAAO;;AAIT,SAAgB,8BAAwD;AACtE,QAAO;;AAIT,SAAgB,4BACd,UACM;AACN,mBAAkB;;AAUpB,SAAgB,uBACd,WACM;CACN,MAAM,WAAW,6BAA6B;AAC9C,KAAI,UAAU;AAIZ,MAAI,oBAAoB,EAAE;AACxB,OAAI,0BAA0B,CAC5B,OAAM,IAAI,MACR,6DACD;AAEH;;AAEF,WAAS,gBAAgB,KAAK,U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,OAAM,IAAI,eACR,eACA,gCAAgC,SAAS,KAC1C;AAIH,8BAA6B,SAAS;AAGtC,KAAI,SAAS,mBAAmB,CAAC,SAAS,gBAAgB,OAAO,QAC/D,UAAS,gBAAgB,OAAO;AAElC,UAAS,kBAAkB;AAG3B,UAAS,eAAe;AACxB,UAAS,eAAe;AAMxB,UAAS,UAAU;;AAGrB,SAAgB,wBACd,UACA,OACM;AAEN,EADgB,SAAS,sCAAsB,IAAI,KAAK,EACjD,IAAI,MAAM;;AAGnB,SAAgB,0BACd,UACA,OACM;AACN,UAAS,mBAAmB,OAAO,MAAM;;AAG3C,SAAS,iBACP,UACA,KACA,SACM;AACN,KAAI,yBAAyB,CAAE;CAC/B,MAAM,WAAY,SAAS,uCAAuB,IAAI,KAAK;AAC3D,KAAI,SAAS,IAAI,IAAI,CAAE;AACvB,UAAS,IAAI,IAAI;AACjB,QAAO,KAAK,QAAQ"}
|
|
@@ -1,39 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* - Replayable execution
|
|
13
|
-
* - Debuggability
|
|
14
|
-
*
|
|
15
|
-
* INVARIANTS:
|
|
16
|
-
* - readContext() only works during component render (has currentContextFrame)
|
|
17
|
-
* - Each render captures a context snapshot
|
|
18
|
-
* - Async continuations see the snapshot from render start (frozen)
|
|
19
|
-
* - Provider (Scope) creates a new frame that shadows parent
|
|
20
|
-
* - Context updates require re-render to take effect
|
|
21
|
-
*/
|
|
22
|
-
import type { JSXElement } from '../common/jsx';
|
|
23
|
-
export type ContextKey = symbol;
|
|
24
|
-
export interface Context<T> {
|
|
25
|
-
readonly key: ContextKey;
|
|
26
|
-
readonly defaultValue: T;
|
|
27
|
-
readonly Scope: (props: {
|
|
28
|
-
value: unknown;
|
|
29
|
-
children?: unknown;
|
|
30
|
-
}) => JSXElement;
|
|
1
|
+
import { JSXElement } from "../common/jsx.js";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/context.d.ts
|
|
4
|
+
type ContextKey = symbol;
|
|
5
|
+
interface Context<T> {
|
|
6
|
+
readonly key: ContextKey;
|
|
7
|
+
readonly defaultValue: T;
|
|
8
|
+
readonly Scope: (props: {
|
|
9
|
+
value: unknown;
|
|
10
|
+
children?: unknown;
|
|
11
|
+
}) => JSXElement;
|
|
31
12
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
interface ContextFrame {
|
|
14
|
+
parent: ContextFrame | null;
|
|
15
|
+
values: Map<ContextKey, unknown> | null;
|
|
35
16
|
}
|
|
36
|
-
|
|
17
|
+
declare const CONTEXT_FRAME_SYMBOL: unique symbol;
|
|
18
|
+
declare function getVNodeContextFrame(node: unknown): ContextFrame | undefined;
|
|
19
|
+
declare function markVNodeWithContextFrame(node: unknown, frame: ContextFrame, overwrite?: boolean): void;
|
|
20
|
+
declare function markVNodeTreeWithContextFrame(node: unknown, frame: ContextFrame | null, overwrite?: boolean): unknown;
|
|
37
21
|
/**
|
|
38
22
|
* Execute a function within a specific context frame.
|
|
39
23
|
*
|
|
@@ -45,7 +29,7 @@ export declare const CONTEXT_FRAME_SYMBOL: unique symbol;
|
|
|
45
29
|
*
|
|
46
30
|
* This ensures no context frame remains globally active across await.
|
|
47
31
|
*/
|
|
48
|
-
|
|
32
|
+
declare function withContext<T>(frame: ContextFrame | null, fn: () => T): T;
|
|
49
33
|
/**
|
|
50
34
|
* Execute an async resource step within its frozen context snapshot.
|
|
51
35
|
*
|
|
@@ -55,26 +39,28 @@ export declare function withContext<T>(frame: ContextFrame | null, fn: () => T):
|
|
|
55
39
|
* observe or rely on a live resource frame. This keeps semantics simple and
|
|
56
40
|
* deterministic: async resources see only their creation-time snapshot.
|
|
57
41
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
declare function withAsyncResourceContext<T>(frame: ContextFrame | null, fn: () => T): T;
|
|
43
|
+
declare function defineContext<T>(defaultValue: T): Context<T>;
|
|
44
|
+
declare function readContext<T>(context: Context<T>): T;
|
|
61
45
|
/**
|
|
62
46
|
* Push a new context frame (for render entry)
|
|
63
47
|
* Called by component runtime when render starts
|
|
64
48
|
*/
|
|
65
|
-
|
|
49
|
+
declare function pushContextFrame(): ContextFrame;
|
|
66
50
|
/**
|
|
67
51
|
* Pop context frame (for render exit)
|
|
68
52
|
* Called by component runtime when render ends
|
|
69
53
|
*/
|
|
70
|
-
|
|
54
|
+
declare function popContextFrame(): void;
|
|
71
55
|
/**
|
|
72
56
|
* Get the current context frame for inspection (used by tests/diagnostics only)
|
|
73
57
|
*/
|
|
74
|
-
|
|
58
|
+
declare function getCurrentContextFrame(): ContextFrame | null;
|
|
75
59
|
/**
|
|
76
60
|
* Get the top of the context snapshot stack (used by runtime when deciding
|
|
77
61
|
* how to link snapshots for async continuations). Returns null if stack empty.
|
|
78
62
|
*/
|
|
79
|
-
|
|
63
|
+
declare function getTopContextSnapshot(): ContextFrame | null;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { Context, ContextFrame, defineContext, readContext };
|
|
80
66
|
//# sourceMappingURL=context.d.ts.map
|