@rangojs/router 0.0.0-experimental.9 → 0.0.0-experimental.963406dd
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/AGENTS.md +9 -0
- package/README.md +942 -4
- package/dist/__internal.d.ts +83 -0
- package/dist/__internal.d.ts.map +1 -0
- package/dist/__internal.js +19 -0
- package/dist/__internal.js.map +1 -0
- package/dist/__mocks__/version.d.ts +7 -0
- package/dist/__mocks__/version.d.ts.map +1 -0
- package/dist/__mocks__/version.js +7 -0
- package/dist/__mocks__/version.js.map +1 -0
- package/dist/__tests__/client-href.test.d.ts +2 -0
- package/dist/__tests__/client-href.test.d.ts.map +1 -0
- package/dist/__tests__/client-href.test.js +74 -0
- package/dist/__tests__/client-href.test.js.map +1 -0
- package/dist/__tests__/component-utils.test.d.ts +2 -0
- package/dist/__tests__/component-utils.test.d.ts.map +1 -0
- package/dist/__tests__/component-utils.test.js +51 -0
- package/dist/__tests__/component-utils.test.js.map +1 -0
- package/dist/__tests__/event-controller.test.d.ts +2 -0
- package/dist/__tests__/event-controller.test.d.ts.map +1 -0
- package/dist/__tests__/event-controller.test.js +538 -0
- package/dist/__tests__/event-controller.test.js.map +1 -0
- package/dist/__tests__/helpers/route-tree.d.ts +118 -0
- package/dist/__tests__/helpers/route-tree.d.ts.map +1 -0
- package/dist/__tests__/helpers/route-tree.js +374 -0
- package/dist/__tests__/helpers/route-tree.js.map +1 -0
- package/dist/__tests__/match-result.test.d.ts +2 -0
- package/dist/__tests__/match-result.test.d.ts.map +1 -0
- package/dist/__tests__/match-result.test.js +154 -0
- package/dist/__tests__/match-result.test.js.map +1 -0
- package/dist/__tests__/navigation-store.test.d.ts +2 -0
- package/dist/__tests__/navigation-store.test.d.ts.map +1 -0
- package/dist/__tests__/navigation-store.test.js +440 -0
- package/dist/__tests__/navigation-store.test.js.map +1 -0
- package/dist/__tests__/partial-update.test.d.ts +2 -0
- package/dist/__tests__/partial-update.test.d.ts.map +1 -0
- package/dist/__tests__/partial-update.test.js +1009 -0
- package/dist/__tests__/partial-update.test.js.map +1 -0
- package/dist/__tests__/reverse-types.test.d.ts +8 -0
- package/dist/__tests__/reverse-types.test.d.ts.map +1 -0
- package/dist/__tests__/reverse-types.test.js +656 -0
- package/dist/__tests__/reverse-types.test.js.map +1 -0
- package/dist/__tests__/route-definition.test.d.ts +2 -0
- package/dist/__tests__/route-definition.test.d.ts.map +1 -0
- package/dist/__tests__/route-definition.test.js +55 -0
- package/dist/__tests__/route-definition.test.js.map +1 -0
- package/dist/__tests__/router-helpers.test.d.ts +2 -0
- package/dist/__tests__/router-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/router-helpers.test.js +377 -0
- package/dist/__tests__/router-helpers.test.js.map +1 -0
- package/dist/__tests__/router-integration-2.test.d.ts +2 -0
- package/dist/__tests__/router-integration-2.test.d.ts.map +1 -0
- package/dist/__tests__/router-integration-2.test.js +426 -0
- package/dist/__tests__/router-integration-2.test.js.map +1 -0
- package/dist/__tests__/router-integration.test.d.ts +2 -0
- package/dist/__tests__/router-integration.test.d.ts.map +1 -0
- package/dist/__tests__/router-integration.test.js +1051 -0
- package/dist/__tests__/router-integration.test.js.map +1 -0
- package/dist/__tests__/search-params.test.d.ts +5 -0
- package/dist/__tests__/search-params.test.d.ts.map +1 -0
- package/dist/__tests__/search-params.test.js +306 -0
- package/dist/__tests__/search-params.test.js.map +1 -0
- package/dist/__tests__/segment-system.test.d.ts +2 -0
- package/dist/__tests__/segment-system.test.d.ts.map +1 -0
- package/dist/__tests__/segment-system.test.js +627 -0
- package/dist/__tests__/segment-system.test.js.map +1 -0
- package/dist/__tests__/static-handler-types.test.d.ts +8 -0
- package/dist/__tests__/static-handler-types.test.d.ts.map +1 -0
- package/dist/__tests__/static-handler-types.test.js +63 -0
- package/dist/__tests__/static-handler-types.test.js.map +1 -0
- package/dist/__tests__/urls.test.d.ts +2 -0
- package/dist/__tests__/urls.test.d.ts.map +1 -0
- package/dist/__tests__/urls.test.js +421 -0
- package/dist/__tests__/urls.test.js.map +1 -0
- package/dist/__tests__/use-mount.test.d.ts +2 -0
- package/dist/__tests__/use-mount.test.d.ts.map +1 -0
- package/dist/__tests__/use-mount.test.js +35 -0
- package/dist/__tests__/use-mount.test.js.map +1 -0
- package/dist/bin/rango.d.ts +2 -0
- package/dist/bin/rango.d.ts.map +1 -0
- package/dist/bin/rango.js +1619 -155
- package/dist/bin/rango.js.map +1 -0
- package/dist/browser/event-controller.d.ts +191 -0
- package/dist/browser/event-controller.d.ts.map +1 -0
- package/dist/browser/event-controller.js +559 -0
- package/dist/browser/event-controller.js.map +1 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +14 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/link-interceptor.d.ts +38 -0
- package/dist/browser/link-interceptor.d.ts.map +1 -0
- package/dist/browser/link-interceptor.js +99 -0
- package/dist/browser/link-interceptor.js.map +1 -0
- package/dist/browser/logging.d.ts +10 -0
- package/dist/browser/logging.d.ts.map +1 -0
- package/dist/browser/logging.js +29 -0
- package/dist/browser/logging.js.map +1 -0
- package/dist/browser/lru-cache.d.ts +17 -0
- package/dist/browser/lru-cache.d.ts.map +1 -0
- package/dist/browser/lru-cache.js +50 -0
- package/dist/browser/lru-cache.js.map +1 -0
- package/dist/browser/merge-segment-loaders.d.ts +39 -0
- package/dist/browser/merge-segment-loaders.d.ts.map +1 -0
- package/dist/browser/merge-segment-loaders.js +102 -0
- package/dist/browser/merge-segment-loaders.js.map +1 -0
- package/dist/browser/navigation-bridge.d.ts +102 -0
- package/dist/browser/navigation-bridge.d.ts.map +1 -0
- package/dist/browser/navigation-bridge.js +708 -0
- package/dist/browser/navigation-bridge.js.map +1 -0
- package/dist/browser/navigation-client.d.ts +25 -0
- package/dist/browser/navigation-client.d.ts.map +1 -0
- package/dist/browser/navigation-client.js +157 -0
- package/dist/browser/navigation-client.js.map +1 -0
- package/dist/browser/navigation-store.d.ts +101 -0
- package/dist/browser/navigation-store.d.ts.map +1 -0
- package/dist/browser/navigation-store.js +625 -0
- package/dist/browser/navigation-store.js.map +1 -0
- package/dist/browser/partial-update.d.ts +75 -0
- package/dist/browser/partial-update.d.ts.map +1 -0
- package/dist/browser/partial-update.js +426 -0
- package/dist/browser/partial-update.js.map +1 -0
- package/dist/browser/react/Link.d.ts +86 -0
- package/dist/browser/react/Link.d.ts.map +1 -0
- package/dist/browser/react/Link.js +128 -0
- package/dist/browser/react/Link.js.map +1 -0
- package/dist/browser/react/NavigationProvider.d.ts +63 -0
- package/dist/browser/react/NavigationProvider.d.ts.map +1 -0
- package/dist/browser/react/NavigationProvider.js +216 -0
- package/dist/browser/react/NavigationProvider.js.map +1 -0
- package/dist/browser/react/ScrollRestoration.d.ts +75 -0
- package/dist/browser/react/ScrollRestoration.d.ts.map +1 -0
- package/dist/browser/react/ScrollRestoration.js +57 -0
- package/dist/browser/react/ScrollRestoration.js.map +1 -0
- package/dist/browser/react/context.d.ts +46 -0
- package/dist/browser/react/context.d.ts.map +1 -0
- package/dist/browser/react/context.js +10 -0
- package/dist/browser/react/context.js.map +1 -0
- package/dist/browser/react/index.d.ts +11 -0
- package/dist/browser/react/index.d.ts.map +1 -0
- package/dist/browser/react/index.js +22 -0
- package/dist/browser/react/index.js.map +1 -0
- package/dist/browser/react/location-state-shared.d.ts +63 -0
- package/dist/browser/react/location-state-shared.d.ts.map +1 -0
- package/dist/browser/react/location-state-shared.js +81 -0
- package/dist/browser/react/location-state-shared.js.map +1 -0
- package/dist/browser/react/location-state.d.ts +23 -0
- package/dist/browser/react/location-state.d.ts.map +1 -0
- package/dist/browser/react/location-state.js +29 -0
- package/dist/browser/react/location-state.js.map +1 -0
- package/dist/browser/react/mount-context.d.ts +24 -0
- package/dist/browser/react/mount-context.d.ts.map +1 -0
- package/dist/browser/react/mount-context.js +24 -0
- package/dist/browser/react/mount-context.js.map +1 -0
- package/dist/browser/react/use-action.d.ts +64 -0
- package/dist/browser/react/use-action.d.ts.map +1 -0
- package/dist/browser/react/use-action.js +134 -0
- package/dist/browser/react/use-action.js.map +1 -0
- package/dist/browser/react/use-client-cache.d.ts +41 -0
- package/dist/browser/react/use-client-cache.d.ts.map +1 -0
- package/dist/browser/react/use-client-cache.js +39 -0
- package/dist/browser/react/use-client-cache.js.map +1 -0
- package/dist/browser/react/use-handle.d.ts +31 -0
- package/dist/browser/react/use-handle.d.ts.map +1 -0
- package/dist/browser/react/use-handle.js +144 -0
- package/dist/browser/react/use-handle.js.map +1 -0
- package/dist/browser/react/use-href.d.ts +33 -0
- package/dist/browser/react/use-href.d.ts.map +1 -0
- package/dist/browser/react/use-href.js +39 -0
- package/dist/browser/react/use-href.js.map +1 -0
- package/dist/browser/react/use-link-status.d.ts +37 -0
- package/dist/browser/react/use-link-status.d.ts.map +1 -0
- package/dist/browser/react/use-link-status.js +99 -0
- package/dist/browser/react/use-link-status.js.map +1 -0
- package/dist/browser/react/use-mount.d.ts +25 -0
- package/dist/browser/react/use-mount.d.ts.map +1 -0
- package/dist/browser/react/use-mount.js +30 -0
- package/dist/browser/react/use-mount.js.map +1 -0
- package/dist/browser/react/use-navigation.d.ts +27 -0
- package/dist/browser/react/use-navigation.d.ts.map +1 -0
- package/dist/browser/react/use-navigation.js +87 -0
- package/dist/browser/react/use-navigation.js.map +1 -0
- package/dist/browser/react/use-segments.d.ts +38 -0
- package/dist/browser/react/use-segments.d.ts.map +1 -0
- package/dist/browser/react/use-segments.js +130 -0
- package/dist/browser/react/use-segments.js.map +1 -0
- package/dist/browser/request-controller.d.ts +26 -0
- package/dist/browser/request-controller.d.ts.map +1 -0
- package/dist/browser/request-controller.js +147 -0
- package/dist/browser/request-controller.js.map +1 -0
- package/dist/browser/rsc-router.d.ts +129 -0
- package/dist/browser/rsc-router.d.ts.map +1 -0
- package/dist/browser/rsc-router.js +195 -0
- package/dist/browser/rsc-router.js.map +1 -0
- package/dist/browser/scroll-restoration.d.ts +93 -0
- package/dist/browser/scroll-restoration.d.ts.map +1 -0
- package/dist/browser/scroll-restoration.js +321 -0
- package/dist/browser/scroll-restoration.js.map +1 -0
- package/dist/browser/segment-structure-assert.d.ts +17 -0
- package/dist/browser/segment-structure-assert.d.ts.map +1 -0
- package/dist/browser/segment-structure-assert.js +59 -0
- package/dist/browser/segment-structure-assert.js.map +1 -0
- package/dist/browser/server-action-bridge.d.ts +26 -0
- package/dist/browser/server-action-bridge.d.ts.map +1 -0
- package/dist/browser/server-action-bridge.js +668 -0
- package/dist/browser/server-action-bridge.js.map +1 -0
- package/dist/browser/shallow.d.ts +12 -0
- package/dist/browser/shallow.d.ts.map +1 -0
- package/dist/browser/shallow.js +34 -0
- package/dist/browser/shallow.js.map +1 -0
- package/dist/browser/types.d.ts +369 -0
- package/dist/browser/types.d.ts.map +1 -0
- package/dist/browser/types.js +2 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/build/__tests__/generate-cli.test.d.ts +2 -0
- package/dist/build/__tests__/generate-cli.test.d.ts.map +1 -0
- package/dist/build/__tests__/generate-cli.test.js +237 -0
- package/dist/build/__tests__/generate-cli.test.js.map +1 -0
- package/dist/build/__tests__/generate-manifest.test.d.ts +2 -0
- package/dist/build/__tests__/generate-manifest.test.d.ts.map +1 -0
- package/dist/build/__tests__/generate-manifest.test.js +119 -0
- package/dist/build/__tests__/generate-manifest.test.js.map +1 -0
- package/dist/build/__tests__/generate-route-types.test.d.ts +2 -0
- package/dist/build/__tests__/generate-route-types.test.d.ts.map +1 -0
- package/dist/build/__tests__/generate-route-types.test.js +620 -0
- package/dist/build/__tests__/generate-route-types.test.js.map +1 -0
- package/dist/build/__tests__/per-router-manifest.test.d.ts +2 -0
- package/dist/build/__tests__/per-router-manifest.test.d.ts.map +1 -0
- package/dist/build/__tests__/per-router-manifest.test.js +308 -0
- package/dist/build/__tests__/per-router-manifest.test.js.map +1 -0
- package/dist/build/generate-manifest.d.ts +81 -0
- package/dist/build/generate-manifest.d.ts.map +1 -0
- package/dist/build/generate-manifest.js +276 -0
- package/dist/build/generate-manifest.js.map +1 -0
- package/dist/build/generate-route-types.d.ts +115 -0
- package/dist/build/generate-route-types.d.ts.map +1 -0
- package/dist/build/generate-route-types.js +740 -0
- package/dist/build/generate-route-types.js.map +1 -0
- package/dist/build/index.d.ts +21 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +21 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/route-trie.d.ts +71 -0
- package/dist/build/route-trie.d.ts.map +1 -0
- package/dist/build/route-trie.js +175 -0
- package/dist/build/route-trie.js.map +1 -0
- package/dist/cache/__tests__/cache-scope.test.d.ts +2 -0
- package/dist/cache/__tests__/cache-scope.test.d.ts.map +1 -0
- package/dist/cache/__tests__/cache-scope.test.js +208 -0
- package/dist/cache/__tests__/cache-scope.test.js.map +1 -0
- package/dist/cache/__tests__/document-cache.test.d.ts +2 -0
- package/dist/cache/__tests__/document-cache.test.d.ts.map +1 -0
- package/dist/cache/__tests__/document-cache.test.js +345 -0
- package/dist/cache/__tests__/document-cache.test.js.map +1 -0
- package/dist/cache/__tests__/memory-segment-store.test.d.ts +2 -0
- package/dist/cache/__tests__/memory-segment-store.test.d.ts.map +1 -0
- package/dist/cache/__tests__/memory-segment-store.test.js +425 -0
- package/dist/cache/__tests__/memory-segment-store.test.js.map +1 -0
- package/dist/cache/__tests__/memory-store.test.d.ts +2 -0
- package/dist/cache/__tests__/memory-store.test.d.ts.map +1 -0
- package/dist/cache/__tests__/memory-store.test.js +367 -0
- package/dist/cache/__tests__/memory-store.test.js.map +1 -0
- package/dist/cache/cache-scope.d.ts +102 -0
- package/dist/cache/cache-scope.d.ts.map +1 -0
- package/dist/cache/cache-scope.js +440 -0
- package/dist/cache/cache-scope.js.map +1 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.d.ts +2 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.d.ts.map +1 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.js +330 -0
- package/dist/cache/cf/__tests__/cf-cache-store.test.js.map +1 -0
- package/dist/cache/cf/cf-cache-store.d.ts +165 -0
- package/dist/cache/cf/cf-cache-store.d.ts.map +1 -0
- package/dist/cache/cf/cf-cache-store.js +242 -0
- package/dist/cache/cf/cf-cache-store.js.map +1 -0
- package/dist/cache/cf/index.d.ts +14 -0
- package/dist/cache/cf/index.d.ts.map +1 -0
- package/dist/cache/cf/index.js +17 -0
- package/dist/cache/cf/index.js.map +1 -0
- package/dist/cache/document-cache.d.ts +64 -0
- package/dist/cache/document-cache.d.ts.map +1 -0
- package/dist/cache/document-cache.js +228 -0
- package/dist/cache/document-cache.js.map +1 -0
- package/dist/cache/index.d.ts +19 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +21 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/memory-segment-store.d.ts +110 -0
- package/dist/cache/memory-segment-store.d.ts.map +1 -0
- package/dist/cache/memory-segment-store.js +117 -0
- package/dist/cache/memory-segment-store.js.map +1 -0
- package/dist/cache/memory-store.d.ts +41 -0
- package/dist/cache/memory-store.d.ts.map +1 -0
- package/dist/cache/memory-store.js +191 -0
- package/dist/cache/memory-store.js.map +1 -0
- package/dist/cache/types.d.ts +317 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +12 -0
- package/dist/cache/types.js.map +1 -0
- package/dist/client.d.ts +248 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +367 -0
- package/dist/client.js.map +1 -0
- package/dist/client.rsc.d.ts +26 -0
- package/dist/client.rsc.d.ts.map +1 -0
- package/dist/client.rsc.js +46 -0
- package/dist/client.rsc.js.map +1 -0
- package/dist/component-utils.d.ts +36 -0
- package/dist/component-utils.d.ts.map +1 -0
- package/dist/component-utils.js +61 -0
- package/dist/component-utils.js.map +1 -0
- package/dist/components/DefaultDocument.d.ts +13 -0
- package/dist/components/DefaultDocument.d.ts.map +1 -0
- package/dist/components/DefaultDocument.js +15 -0
- package/dist/components/DefaultDocument.js.map +1 -0
- package/dist/debug.d.ts +58 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +157 -0
- package/dist/debug.js.map +1 -0
- package/dist/default-error-boundary.d.ts +11 -0
- package/dist/default-error-boundary.d.ts.map +1 -0
- package/dist/default-error-boundary.js +45 -0
- package/dist/default-error-boundary.js.map +1 -0
- package/dist/deps/browser.d.ts +2 -0
- package/dist/deps/browser.d.ts.map +1 -0
- package/dist/deps/browser.js +3 -0
- package/dist/deps/browser.js.map +1 -0
- package/dist/deps/html-stream-client.d.ts +2 -0
- package/dist/deps/html-stream-client.d.ts.map +1 -0
- package/dist/deps/html-stream-client.js +3 -0
- package/dist/deps/html-stream-client.js.map +1 -0
- package/dist/deps/html-stream-server.d.ts +2 -0
- package/dist/deps/html-stream-server.d.ts.map +1 -0
- package/dist/deps/html-stream-server.js +3 -0
- package/dist/deps/html-stream-server.js.map +1 -0
- package/dist/deps/rsc.d.ts +2 -0
- package/dist/deps/rsc.d.ts.map +1 -0
- package/dist/deps/rsc.js +4 -0
- package/dist/deps/rsc.js.map +1 -0
- package/dist/deps/ssr.d.ts +2 -0
- package/dist/deps/ssr.d.ts.map +1 -0
- package/dist/deps/ssr.js +3 -0
- package/dist/deps/ssr.js.map +1 -0
- package/dist/errors.d.ts +174 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +241 -0
- package/dist/errors.js.map +1 -0
- package/dist/handle.d.ts +78 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +82 -0
- package/dist/handle.js.map +1 -0
- package/dist/handles/MetaTags.d.ts +14 -0
- package/dist/handles/MetaTags.d.ts.map +1 -0
- package/dist/handles/MetaTags.js +136 -0
- package/dist/handles/MetaTags.js.map +1 -0
- package/dist/handles/index.d.ts +6 -0
- package/dist/handles/index.d.ts.map +1 -0
- package/dist/handles/index.js +6 -0
- package/dist/handles/index.js.map +1 -0
- package/dist/handles/meta.d.ts +39 -0
- package/dist/handles/meta.d.ts.map +1 -0
- package/dist/handles/meta.js +202 -0
- package/dist/handles/meta.js.map +1 -0
- package/dist/host/__tests__/errors.test.d.ts +2 -0
- package/dist/host/__tests__/errors.test.d.ts.map +1 -0
- package/dist/host/__tests__/errors.test.js +76 -0
- package/dist/host/__tests__/errors.test.js.map +1 -0
- package/dist/host/__tests__/pattern-comprehensive.test.d.ts +2 -0
- package/dist/host/__tests__/pattern-comprehensive.test.d.ts.map +1 -0
- package/dist/host/__tests__/pattern-comprehensive.test.js +732 -0
- package/dist/host/__tests__/pattern-comprehensive.test.js.map +1 -0
- package/dist/host/__tests__/pattern-matcher.test.d.ts +2 -0
- package/dist/host/__tests__/pattern-matcher.test.d.ts.map +1 -0
- package/dist/host/__tests__/pattern-matcher.test.js +251 -0
- package/dist/host/__tests__/pattern-matcher.test.js.map +1 -0
- package/dist/host/__tests__/router.test.d.ts +2 -0
- package/dist/host/__tests__/router.test.d.ts.map +1 -0
- package/dist/host/__tests__/router.test.js +241 -0
- package/dist/host/__tests__/router.test.js.map +1 -0
- package/dist/host/__tests__/testing.test.d.ts +2 -0
- package/dist/host/__tests__/testing.test.d.ts.map +1 -0
- package/dist/host/__tests__/testing.test.js +64 -0
- package/dist/host/__tests__/testing.test.js.map +1 -0
- package/dist/host/__tests__/utils.test.d.ts +2 -0
- package/dist/host/__tests__/utils.test.d.ts.map +1 -0
- package/dist/host/__tests__/utils.test.js +29 -0
- package/dist/host/__tests__/utils.test.js.map +1 -0
- package/dist/host/cookie-handler.d.ts +34 -0
- package/dist/host/cookie-handler.d.ts.map +1 -0
- package/dist/host/cookie-handler.js +124 -0
- package/dist/host/cookie-handler.js.map +1 -0
- package/dist/host/errors.d.ts +56 -0
- package/dist/host/errors.d.ts.map +1 -0
- package/dist/host/errors.js +79 -0
- package/dist/host/errors.js.map +1 -0
- package/dist/host/index.d.ts +29 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +32 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/pattern-matcher.d.ts +36 -0
- package/dist/host/pattern-matcher.d.ts.map +1 -0
- package/dist/host/pattern-matcher.js +172 -0
- package/dist/host/pattern-matcher.js.map +1 -0
- package/dist/host/router.d.ts +26 -0
- package/dist/host/router.d.ts.map +1 -0
- package/dist/host/router.js +218 -0
- package/dist/host/router.js.map +1 -0
- package/dist/host/testing.d.ts +36 -0
- package/dist/host/testing.d.ts.map +1 -0
- package/dist/host/testing.js +55 -0
- package/dist/host/testing.js.map +1 -0
- package/dist/host/types.d.ts +115 -0
- package/dist/host/types.d.ts.map +1 -0
- package/dist/host/types.js +7 -0
- package/dist/host/types.js.map +1 -0
- package/dist/host/utils.d.ts +21 -0
- package/dist/host/utils.d.ts.map +1 -0
- package/dist/host/utils.js +23 -0
- package/dist/host/utils.js.map +1 -0
- package/dist/href-client.d.ts +131 -0
- package/dist/href-client.d.ts.map +1 -0
- package/dist/href-client.js +64 -0
- package/dist/href-client.js.map +1 -0
- package/{src/href-context.ts → dist/href-context.d.ts} +7 -11
- package/dist/href-context.d.ts.map +1 -0
- package/dist/href-context.js +21 -0
- package/dist/href-context.js.map +1 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/dist/index.rsc.d.ts +32 -0
- package/dist/index.rsc.d.ts.map +1 -0
- package/dist/index.rsc.js +40 -0
- package/dist/index.rsc.js.map +1 -0
- package/dist/internal-debug.d.ts +2 -0
- package/dist/internal-debug.d.ts.map +1 -0
- package/dist/internal-debug.js +5 -0
- package/dist/internal-debug.js.map +1 -0
- package/dist/loader.d.ts +14 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +20 -0
- package/dist/loader.js.map +1 -0
- package/dist/loader.rsc.d.ts +19 -0
- package/dist/loader.rsc.d.ts.map +1 -0
- package/dist/loader.rsc.js +99 -0
- package/dist/loader.rsc.js.map +1 -0
- package/dist/network-error-thrower.d.ts +17 -0
- package/dist/network-error-thrower.d.ts.map +1 -0
- package/dist/network-error-thrower.js +14 -0
- package/dist/network-error-thrower.js.map +1 -0
- package/dist/outlet-context.d.ts +13 -0
- package/dist/outlet-context.d.ts.map +1 -0
- package/dist/outlet-context.js +3 -0
- package/dist/outlet-context.js.map +1 -0
- package/dist/prerender/__tests__/param-hash.test.d.ts +2 -0
- package/dist/prerender/__tests__/param-hash.test.d.ts.map +1 -0
- package/dist/prerender/__tests__/param-hash.test.js +148 -0
- package/dist/prerender/__tests__/param-hash.test.js.map +1 -0
- package/dist/prerender/param-hash.d.ts +16 -0
- package/dist/prerender/param-hash.d.ts.map +1 -0
- package/dist/prerender/param-hash.js +36 -0
- package/dist/prerender/param-hash.js.map +1 -0
- package/dist/prerender/store.d.ts +38 -0
- package/dist/prerender/store.d.ts.map +1 -0
- package/dist/prerender/store.js +61 -0
- package/dist/prerender/store.js.map +1 -0
- package/dist/prerender.d.ts +66 -0
- package/dist/prerender.d.ts.map +1 -0
- package/dist/prerender.js +57 -0
- package/dist/prerender.js.map +1 -0
- package/dist/reverse.d.ts +196 -0
- package/dist/reverse.d.ts.map +1 -0
- package/dist/reverse.js +78 -0
- package/dist/reverse.js.map +1 -0
- package/dist/root-error-boundary.d.ts +33 -0
- package/dist/root-error-boundary.d.ts.map +1 -0
- package/dist/root-error-boundary.js +165 -0
- package/dist/root-error-boundary.js.map +1 -0
- package/dist/route-content-wrapper.d.ts +46 -0
- package/dist/route-content-wrapper.d.ts.map +1 -0
- package/dist/route-content-wrapper.js +77 -0
- package/dist/route-content-wrapper.js.map +1 -0
- package/dist/route-definition.d.ts +421 -0
- package/dist/route-definition.d.ts.map +1 -0
- package/dist/route-definition.js +868 -0
- package/dist/route-definition.js.map +1 -0
- package/dist/route-map-builder.d.ts +155 -0
- package/dist/route-map-builder.d.ts.map +1 -0
- package/dist/route-map-builder.js +237 -0
- package/dist/route-map-builder.js.map +1 -0
- package/dist/route-types.d.ts +165 -0
- package/dist/route-types.d.ts.map +1 -0
- package/dist/route-types.js +7 -0
- package/dist/route-types.js.map +1 -0
- package/dist/router/__tests__/handler-context.test.d.ts +2 -0
- package/dist/router/__tests__/handler-context.test.d.ts.map +1 -0
- package/dist/router/__tests__/handler-context.test.js +65 -0
- package/dist/router/__tests__/handler-context.test.js.map +1 -0
- package/dist/router/__tests__/loader-cycle-detection.test.d.ts +2 -0
- package/dist/router/__tests__/loader-cycle-detection.test.d.ts.map +1 -0
- package/dist/router/__tests__/loader-cycle-detection.test.js +221 -0
- package/dist/router/__tests__/loader-cycle-detection.test.js.map +1 -0
- package/dist/router/__tests__/match-context.test.d.ts +2 -0
- package/dist/router/__tests__/match-context.test.d.ts.map +1 -0
- package/dist/router/__tests__/match-context.test.js +92 -0
- package/dist/router/__tests__/match-context.test.js.map +1 -0
- package/dist/router/__tests__/match-pipelines.test.d.ts +2 -0
- package/dist/router/__tests__/match-pipelines.test.d.ts.map +1 -0
- package/dist/router/__tests__/match-pipelines.test.js +417 -0
- package/dist/router/__tests__/match-pipelines.test.js.map +1 -0
- package/dist/router/__tests__/match-result.test.d.ts +2 -0
- package/dist/router/__tests__/match-result.test.d.ts.map +1 -0
- package/dist/router/__tests__/match-result.test.js +457 -0
- package/dist/router/__tests__/match-result.test.js.map +1 -0
- package/dist/router/__tests__/on-error.test.d.ts +2 -0
- package/dist/router/__tests__/on-error.test.d.ts.map +1 -0
- package/dist/router/__tests__/on-error.test.js +678 -0
- package/dist/router/__tests__/on-error.test.js.map +1 -0
- package/dist/router/__tests__/pattern-matching.test.d.ts +2 -0
- package/dist/router/__tests__/pattern-matching.test.d.ts.map +1 -0
- package/dist/router/__tests__/pattern-matching.test.js +629 -0
- package/dist/router/__tests__/pattern-matching.test.js.map +1 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.d.ts +2 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.d.ts.map +1 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.js +155 -0
- package/dist/router/__tests__/segment-resolution-parallel-loading.test.js.map +1 -0
- package/dist/router/error-handling.d.ts +77 -0
- package/dist/router/error-handling.d.ts.map +1 -0
- package/dist/router/error-handling.js +202 -0
- package/dist/router/error-handling.js.map +1 -0
- package/dist/router/handler-context.d.ts +20 -0
- package/dist/router/handler-context.d.ts.map +1 -0
- package/dist/router/handler-context.js +198 -0
- package/dist/router/handler-context.js.map +1 -0
- package/dist/router/intercept-resolution.d.ts +66 -0
- package/dist/router/intercept-resolution.d.ts.map +1 -0
- package/dist/router/intercept-resolution.js +246 -0
- package/dist/router/intercept-resolution.js.map +1 -0
- package/dist/router/loader-resolution.d.ts +64 -0
- package/dist/router/loader-resolution.d.ts.map +1 -0
- package/dist/router/loader-resolution.js +284 -0
- package/dist/router/loader-resolution.js.map +1 -0
- package/dist/router/logging.d.ts +15 -0
- package/dist/router/logging.d.ts.map +1 -0
- package/dist/router/logging.js +99 -0
- package/dist/router/logging.js.map +1 -0
- package/dist/router/manifest.d.ts +22 -0
- package/dist/router/manifest.d.ts.map +1 -0
- package/dist/router/manifest.js +181 -0
- package/dist/router/manifest.js.map +1 -0
- package/dist/router/match-api.d.ts +35 -0
- package/dist/router/match-api.d.ts.map +1 -0
- package/dist/router/match-api.js +406 -0
- package/dist/router/match-api.js.map +1 -0
- package/dist/router/match-context.d.ts +206 -0
- package/dist/router/match-context.d.ts.map +1 -0
- package/dist/router/match-context.js +17 -0
- package/dist/router/match-context.js.map +1 -0
- package/dist/router/match-middleware/background-revalidation.d.ts +127 -0
- package/dist/router/match-middleware/background-revalidation.d.ts.map +1 -0
- package/dist/router/match-middleware/background-revalidation.js +75 -0
- package/dist/router/match-middleware/background-revalidation.js.map +1 -0
- package/dist/router/match-middleware/cache-lookup.d.ts +112 -0
- package/dist/router/match-middleware/cache-lookup.d.ts.map +1 -0
- package/dist/router/match-middleware/cache-lookup.js +257 -0
- package/dist/router/match-middleware/cache-lookup.js.map +1 -0
- package/dist/router/match-middleware/cache-store.d.ts +113 -0
- package/dist/router/match-middleware/cache-store.d.ts.map +1 -0
- package/dist/router/match-middleware/cache-store.js +108 -0
- package/dist/router/match-middleware/cache-store.js.map +1 -0
- package/dist/router/match-middleware/index.d.ts +81 -0
- package/dist/router/match-middleware/index.d.ts.map +1 -0
- package/dist/router/match-middleware/index.js +80 -0
- package/dist/router/match-middleware/index.js.map +1 -0
- package/dist/router/match-middleware/intercept-resolution.d.ts +117 -0
- package/dist/router/match-middleware/intercept-resolution.d.ts.map +1 -0
- package/dist/router/match-middleware/intercept-resolution.js +134 -0
- package/dist/router/match-middleware/intercept-resolution.js.map +1 -0
- package/dist/router/match-middleware/segment-resolution.d.ts +99 -0
- package/dist/router/match-middleware/segment-resolution.d.ts.map +1 -0
- package/dist/router/match-middleware/segment-resolution.js +53 -0
- package/dist/router/match-middleware/segment-resolution.js.map +1 -0
- package/dist/router/match-pipelines.d.ts +147 -0
- package/dist/router/match-pipelines.d.ts.map +1 -0
- package/dist/router/match-pipelines.js +82 -0
- package/dist/router/match-pipelines.js.map +1 -0
- package/dist/router/match-result.d.ts +126 -0
- package/dist/router/match-result.d.ts.map +1 -0
- package/dist/router/match-result.js +93 -0
- package/dist/router/match-result.js.map +1 -0
- package/dist/router/metrics.d.ts +20 -0
- package/dist/router/metrics.d.ts.map +1 -0
- package/dist/router/metrics.js +47 -0
- package/dist/router/metrics.js.map +1 -0
- package/dist/router/middleware.d.ts +249 -0
- package/dist/router/middleware.d.ts.map +1 -0
- package/dist/router/middleware.js +434 -0
- package/dist/router/middleware.js.map +1 -0
- package/dist/router/middleware.test.d.ts +2 -0
- package/dist/router/middleware.test.d.ts.map +1 -0
- package/dist/router/middleware.test.js +816 -0
- package/dist/router/middleware.test.js.map +1 -0
- package/dist/router/pattern-matching.d.ts +149 -0
- package/dist/router/pattern-matching.d.ts.map +1 -0
- package/dist/router/pattern-matching.js +349 -0
- package/dist/router/pattern-matching.js.map +1 -0
- package/dist/router/revalidation.d.ts +44 -0
- package/dist/router/revalidation.d.ts.map +1 -0
- package/dist/router/revalidation.js +147 -0
- package/dist/router/revalidation.js.map +1 -0
- package/dist/router/router-context.d.ts +135 -0
- package/dist/router/router-context.d.ts.map +1 -0
- package/dist/router/router-context.js +36 -0
- package/dist/router/router-context.js.map +1 -0
- package/dist/router/segment-resolution.d.ts +127 -0
- package/dist/router/segment-resolution.d.ts.map +1 -0
- package/dist/router/segment-resolution.js +919 -0
- package/dist/router/segment-resolution.js.map +1 -0
- package/dist/router/trie-matching.d.ts +40 -0
- package/dist/router/trie-matching.d.ts.map +1 -0
- package/dist/router/trie-matching.js +127 -0
- package/dist/router/trie-matching.js.map +1 -0
- package/dist/router/types.d.ts +136 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/types.js +7 -0
- package/dist/router/types.js.map +1 -0
- package/dist/router.d.ts +753 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.gen.d.ts +6 -0
- package/dist/router.gen.d.ts.map +1 -0
- package/dist/router.gen.js +6 -0
- package/dist/router.gen.js.map +1 -0
- package/dist/router.js +1304 -0
- package/dist/router.js.map +1 -0
- package/dist/rsc/__tests__/helpers.test.d.ts +2 -0
- package/dist/rsc/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/rsc/__tests__/helpers.test.js +140 -0
- package/dist/rsc/__tests__/helpers.test.js.map +1 -0
- package/dist/rsc/handler.d.ts +45 -0
- package/dist/rsc/handler.d.ts.map +1 -0
- package/dist/rsc/handler.js +1172 -0
- package/dist/rsc/handler.js.map +1 -0
- package/dist/rsc/helpers.d.ts +16 -0
- package/dist/rsc/helpers.d.ts.map +1 -0
- package/dist/rsc/helpers.js +55 -0
- package/dist/rsc/helpers.js.map +1 -0
- package/dist/rsc/index.d.ts +22 -0
- package/dist/rsc/index.d.ts.map +1 -0
- package/dist/rsc/index.js +23 -0
- package/dist/rsc/index.js.map +1 -0
- package/dist/rsc/nonce.d.ts +9 -0
- package/dist/rsc/nonce.d.ts.map +1 -0
- package/dist/rsc/nonce.js +18 -0
- package/dist/rsc/nonce.js.map +1 -0
- package/dist/rsc/types.d.ts +206 -0
- package/dist/rsc/types.d.ts.map +1 -0
- package/dist/rsc/types.js +8 -0
- package/dist/rsc/types.js.map +1 -0
- package/dist/search-params.d.ts +103 -0
- package/dist/search-params.d.ts.map +1 -0
- package/dist/search-params.js +74 -0
- package/dist/search-params.js.map +1 -0
- package/dist/segment-system.d.ts +75 -0
- package/dist/segment-system.d.ts.map +1 -0
- package/dist/segment-system.js +336 -0
- package/dist/segment-system.js.map +1 -0
- package/dist/server/context.d.ts +245 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +197 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/fetchable-loader-store.d.ts +18 -0
- package/dist/server/fetchable-loader-store.d.ts.map +1 -0
- package/dist/server/fetchable-loader-store.js +18 -0
- package/dist/server/fetchable-loader-store.js.map +1 -0
- package/dist/server/handle-store.d.ts +85 -0
- package/dist/server/handle-store.d.ts.map +1 -0
- package/dist/server/handle-store.js +142 -0
- package/dist/server/handle-store.js.map +1 -0
- package/dist/server/loader-registry.d.ts +55 -0
- package/dist/server/loader-registry.d.ts.map +1 -0
- package/dist/server/loader-registry.js +132 -0
- package/dist/server/loader-registry.js.map +1 -0
- package/dist/server/request-context.d.ts +226 -0
- package/dist/server/request-context.d.ts.map +1 -0
- package/dist/server/request-context.js +290 -0
- package/dist/server/request-context.js.map +1 -0
- package/dist/server/root-layout.d.ts +4 -0
- package/dist/server/root-layout.d.ts.map +1 -0
- package/dist/server/root-layout.js +5 -0
- package/dist/server/root-layout.js.map +1 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +20 -0
- package/dist/server.js.map +1 -0
- package/dist/ssr/__tests__/ssr-handler.test.d.ts +2 -0
- package/dist/ssr/__tests__/ssr-handler.test.d.ts.map +1 -0
- package/dist/ssr/__tests__/ssr-handler.test.js +132 -0
- package/dist/ssr/__tests__/ssr-handler.test.js.map +1 -0
- package/dist/ssr/index.d.ts +98 -0
- package/dist/ssr/index.d.ts.map +1 -0
- package/dist/ssr/index.js +158 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/static-handler.d.ts +50 -0
- package/dist/static-handler.d.ts.map +1 -0
- package/dist/static-handler.gen.d.ts +5 -0
- package/dist/static-handler.gen.d.ts.map +1 -0
- package/dist/static-handler.gen.js +5 -0
- package/dist/static-handler.gen.js.map +1 -0
- package/dist/static-handler.js +29 -0
- package/dist/static-handler.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +20 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +240 -0
- package/dist/theme/ThemeProvider.js.map +1 -0
- package/dist/theme/ThemeScript.d.ts +48 -0
- package/dist/theme/ThemeScript.d.ts.map +1 -0
- package/dist/theme/ThemeScript.js +13 -0
- package/dist/theme/ThemeScript.js.map +1 -0
- package/dist/theme/__tests__/theme.test.d.ts +2 -0
- package/dist/theme/__tests__/theme.test.d.ts.map +1 -0
- package/dist/theme/__tests__/theme.test.js +103 -0
- package/dist/theme/__tests__/theme.test.js.map +1 -0
- package/dist/theme/constants.d.ts +29 -0
- package/dist/theme/constants.d.ts.map +1 -0
- package/dist/theme/constants.js +48 -0
- package/dist/theme/constants.js.map +1 -0
- package/dist/theme/index.d.ts +31 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +36 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/theme-context.d.ts +40 -0
- package/dist/theme/theme-context.d.ts.map +1 -0
- package/dist/theme/theme-context.js +60 -0
- package/dist/theme/theme-context.js.map +1 -0
- package/dist/theme/theme-script.d.ts +27 -0
- package/dist/theme/theme-script.d.ts.map +1 -0
- package/dist/theme/theme-script.js +147 -0
- package/dist/theme/theme-script.js.map +1 -0
- package/dist/theme/types.d.ts +163 -0
- package/dist/theme/types.d.ts.map +1 -0
- package/dist/theme/types.js +11 -0
- package/dist/theme/types.js.map +1 -0
- package/dist/theme/use-theme.d.ts +12 -0
- package/dist/theme/use-theme.d.ts.map +1 -0
- package/dist/theme/use-theme.js +40 -0
- package/dist/theme/use-theme.js.map +1 -0
- package/dist/types.d.ts +1479 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/urls.d.ts +441 -0
- package/dist/urls.d.ts.map +1 -0
- package/dist/urls.gen.d.ts +8 -0
- package/dist/urls.gen.d.ts.map +1 -0
- package/dist/urls.gen.js +8 -0
- package/dist/urls.gen.js.map +1 -0
- package/dist/urls.js +443 -0
- package/dist/urls.js.map +1 -0
- package/dist/use-loader.d.ts +127 -0
- package/dist/use-loader.d.ts.map +1 -0
- package/dist/use-loader.js +237 -0
- package/dist/use-loader.js.map +1 -0
- package/dist/vite/__tests__/ast-handler-extract.test.d.ts +2 -0
- package/dist/vite/__tests__/ast-handler-extract.test.d.ts.map +1 -0
- package/dist/vite/__tests__/ast-handler-extract.test.js +294 -0
- package/dist/vite/__tests__/ast-handler-extract.test.js.map +1 -0
- package/dist/vite/__tests__/expose-id-utils.test.d.ts +2 -0
- package/dist/vite/__tests__/expose-id-utils.test.d.ts.map +1 -0
- package/dist/vite/__tests__/expose-id-utils.test.js +224 -0
- package/dist/vite/__tests__/expose-id-utils.test.js.map +1 -0
- package/dist/vite/__tests__/expose-internal-ids.test.d.ts +2 -0
- package/dist/vite/__tests__/expose-internal-ids.test.d.ts.map +1 -0
- package/dist/vite/__tests__/expose-internal-ids.test.js +647 -0
- package/dist/vite/__tests__/expose-internal-ids.test.js.map +1 -0
- package/dist/vite/__tests__/expose-router-id.test.d.ts +2 -0
- package/dist/vite/__tests__/expose-router-id.test.d.ts.map +1 -0
- package/dist/vite/__tests__/expose-router-id.test.js +39 -0
- package/dist/vite/__tests__/expose-router-id.test.js.map +1 -0
- package/dist/vite/ast-handler-extract.d.ts +49 -0
- package/dist/vite/ast-handler-extract.d.ts.map +1 -0
- package/dist/vite/ast-handler-extract.js +249 -0
- package/dist/vite/ast-handler-extract.js.map +1 -0
- package/dist/vite/expose-action-id.d.ts +19 -0
- package/dist/vite/expose-action-id.d.ts.map +1 -0
- package/dist/vite/expose-action-id.js +250 -0
- package/dist/vite/expose-action-id.js.map +1 -0
- package/dist/vite/expose-id-utils.d.ts +69 -0
- package/dist/vite/expose-id-utils.d.ts.map +1 -0
- package/dist/vite/expose-id-utils.js +289 -0
- package/dist/vite/expose-id-utils.js.map +1 -0
- package/dist/vite/expose-internal-ids.d.ts +22 -0
- package/dist/vite/expose-internal-ids.d.ts.map +1 -0
- package/dist/vite/expose-internal-ids.js +886 -0
- package/dist/vite/expose-internal-ids.js.map +1 -0
- package/dist/vite/index.d.ts +149 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +4916 -2234
- package/dist/vite/index.js.bak +5448 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/index.named-routes.gen.ts +103 -0
- package/dist/vite/package-resolution.d.ts +43 -0
- package/dist/vite/package-resolution.d.ts.map +1 -0
- package/dist/vite/package-resolution.js +112 -0
- package/dist/vite/package-resolution.js.map +1 -0
- package/dist/vite/virtual-entries.d.ts +25 -0
- package/dist/vite/virtual-entries.d.ts.map +1 -0
- package/{src/vite/virtual-entries.ts → dist/vite/virtual-entries.js} +12 -16
- package/dist/vite/virtual-entries.js.map +1 -0
- package/package.json +70 -63
- package/skills/breadcrumbs/SKILL.md +250 -0
- package/skills/cache-guide/SKILL.md +294 -0
- package/skills/caching/SKILL.md +93 -23
- package/skills/composability/SKILL.md +172 -0
- package/skills/debug-manifest/SKILL.md +12 -8
- package/skills/document-cache/SKILL.md +18 -16
- package/skills/fonts/SKILL.md +6 -4
- package/skills/hooks/SKILL.md +333 -71
- package/skills/host-router/SKILL.md +218 -0
- package/skills/intercept/SKILL.md +131 -8
- package/skills/layout/SKILL.md +100 -3
- package/skills/links/SKILL.md +77 -16
- package/skills/loader/SKILL.md +404 -44
- package/skills/middleware/SKILL.md +173 -34
- package/skills/mime-routes/SKILL.md +15 -11
- package/skills/parallel/SKILL.md +204 -1
- package/skills/prerender/SKILL.md +467 -65
- package/skills/rango/SKILL.md +85 -21
- package/skills/response-routes/SKILL.md +144 -91
- package/skills/route/SKILL.md +257 -14
- package/skills/router-setup/SKILL.md +210 -32
- package/skills/theme/SKILL.md +9 -8
- package/skills/typesafety/SKILL.md +326 -87
- package/skills/use-cache/SKILL.md +324 -0
- package/src/__internal.ts +102 -4
- package/src/bin/rango.ts +312 -15
- package/src/browser/action-coordinator.ts +97 -0
- package/src/browser/action-response-classifier.ts +99 -0
- package/src/browser/app-version.ts +14 -0
- package/src/browser/event-controller.ts +92 -64
- package/src/browser/history-state.ts +80 -0
- package/src/browser/intercept-utils.ts +52 -0
- package/src/browser/link-interceptor.ts +24 -4
- package/src/browser/logging.ts +55 -0
- package/src/browser/merge-segment-loaders.ts +20 -12
- package/src/browser/navigation-bridge.ts +296 -558
- package/src/browser/navigation-client.ts +178 -71
- package/src/browser/navigation-store.ts +73 -55
- package/src/browser/navigation-transaction.ts +297 -0
- package/src/browser/network-error-handler.ts +61 -0
- package/src/browser/partial-update.ts +328 -313
- package/src/browser/prefetch/cache.ts +206 -0
- package/src/browser/prefetch/fetch.ts +150 -0
- package/src/browser/prefetch/observer.ts +65 -0
- package/src/browser/prefetch/policy.ts +48 -0
- package/src/browser/prefetch/queue.ts +160 -0
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/rango-state.ts +112 -0
- package/src/browser/react/Link.tsx +227 -71
- package/src/browser/react/NavigationProvider.tsx +87 -11
- package/src/browser/react/context.ts +11 -0
- package/src/browser/react/filter-segment-order.ts +11 -0
- package/src/browser/react/index.ts +12 -12
- package/src/browser/react/location-state-shared.ts +95 -53
- package/src/browser/react/location-state.ts +60 -15
- package/src/browser/react/mount-context.ts +6 -1
- package/src/browser/react/nonce-context.ts +23 -0
- package/src/browser/react/shallow-equal.ts +27 -0
- package/src/browser/react/use-action.ts +29 -51
- package/src/browser/react/use-client-cache.ts +5 -3
- package/src/browser/react/use-handle.ts +30 -120
- package/src/browser/react/use-link-status.ts +6 -5
- package/src/browser/react/use-navigation.ts +22 -63
- package/src/browser/react/use-params.ts +65 -0
- package/src/browser/react/use-pathname.ts +47 -0
- package/src/browser/react/use-router.ts +76 -0
- package/src/browser/react/use-search-params.ts +56 -0
- package/src/browser/react/use-segments.ts +80 -97
- package/src/browser/response-adapter.ts +73 -0
- package/src/browser/rsc-router.tsx +214 -60
- package/src/browser/scroll-restoration.ts +127 -52
- package/src/browser/segment-reconciler.ts +221 -0
- package/src/browser/segment-structure-assert.ts +16 -0
- package/src/browser/server-action-bridge.ts +510 -603
- package/src/browser/shallow.ts +6 -1
- package/src/browser/types.ts +139 -48
- package/src/browser/validate-redirect-origin.ts +29 -0
- package/src/build/generate-manifest.ts +84 -23
- package/src/build/generate-route-types.ts +39 -752
- package/src/build/index.ts +6 -5
- package/src/build/route-trie.ts +39 -13
- package/src/build/route-types/ast-helpers.ts +25 -0
- package/src/build/route-types/ast-route-extraction.ts +98 -0
- package/src/build/route-types/codegen.ts +102 -0
- package/src/build/route-types/include-resolution.ts +418 -0
- package/src/build/route-types/param-extraction.ts +48 -0
- package/src/build/route-types/per-module-writer.ts +128 -0
- package/src/build/route-types/router-processing.ts +618 -0
- package/src/build/route-types/scan-filter.ts +85 -0
- package/src/build/runtime-discovery.ts +231 -0
- package/src/cache/background-task.ts +34 -0
- package/src/cache/cache-key-utils.ts +44 -0
- package/src/cache/cache-policy.ts +125 -0
- package/src/cache/cache-runtime.ts +342 -0
- package/src/cache/cache-scope.ts +167 -307
- package/src/cache/cf/cf-cache-store.ts +571 -17
- package/src/cache/cf/index.ts +13 -3
- package/src/cache/document-cache.ts +116 -77
- package/src/cache/handle-capture.ts +81 -0
- package/src/cache/handle-snapshot.ts +41 -0
- package/src/cache/index.ts +1 -15
- package/src/cache/memory-segment-store.ts +191 -13
- package/src/cache/profile-registry.ts +73 -0
- package/src/cache/read-through-swr.ts +134 -0
- package/src/cache/segment-codec.ts +256 -0
- package/src/cache/taint.ts +153 -0
- package/src/cache/types.ts +72 -122
- package/src/client.rsc.tsx +3 -1
- package/src/client.tsx +83 -179
- package/src/component-utils.ts +4 -4
- package/src/components/DefaultDocument.tsx +5 -1
- package/src/context-var.ts +156 -0
- package/src/debug.ts +19 -9
- package/src/errors.ts +77 -7
- package/src/handle.ts +55 -10
- package/src/handles/MetaTags.tsx +73 -20
- package/src/handles/breadcrumbs.ts +66 -0
- package/src/handles/index.ts +1 -0
- package/src/handles/meta.ts +30 -13
- package/src/host/cookie-handler.ts +21 -15
- package/src/host/errors.ts +8 -8
- package/src/host/index.ts +4 -7
- package/src/host/pattern-matcher.ts +27 -27
- package/src/host/router.ts +61 -39
- package/src/host/testing.ts +8 -8
- package/src/host/types.ts +15 -7
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +65 -45
- package/src/index.rsc.ts +135 -21
- package/src/index.ts +175 -51
- package/src/internal-debug.ts +11 -0
- package/src/loader.rsc.ts +25 -143
- package/src/loader.ts +27 -10
- package/src/network-error-thrower.tsx +3 -1
- package/src/outlet-provider.tsx +45 -0
- package/src/prerender/param-hash.ts +4 -2
- package/src/prerender/store.ts +159 -13
- package/src/prerender.ts +397 -29
- package/src/reverse.ts +205 -121
- package/src/root-error-boundary.tsx +41 -29
- package/src/route-content-wrapper.tsx +7 -4
- package/src/route-definition/dsl-helpers.ts +982 -0
- package/src/route-definition/helper-factories.ts +200 -0
- package/src/route-definition/helpers-types.ts +434 -0
- package/src/route-definition/index.ts +55 -0
- package/src/route-definition/redirect.ts +101 -0
- package/src/route-definition/resolve-handler-use.ts +149 -0
- package/src/route-definition.ts +1 -1431
- package/src/route-map-builder.ts +162 -123
- package/src/route-name.ts +53 -0
- package/src/route-types.ts +59 -9
- package/src/router/content-negotiation.ts +215 -0
- package/src/router/debug-manifest.ts +72 -0
- package/src/router/error-handling.ts +9 -9
- package/src/router/find-match.ts +160 -0
- package/src/router/handler-context.ts +435 -86
- package/src/router/intercept-resolution.ts +35 -20
- package/src/router/lazy-includes.ts +237 -0
- package/src/router/loader-resolution.ts +356 -128
- package/src/router/logging.ts +251 -0
- package/src/router/manifest.ts +89 -32
- package/src/router/match-api.ts +192 -258
- package/src/router/match-context.ts +4 -2
- package/src/router/match-handlers.ts +440 -0
- package/src/router/match-middleware/background-revalidation.ts +108 -93
- package/src/router/match-middleware/cache-lookup.ts +414 -86
- package/src/router/match-middleware/cache-store.ts +91 -29
- package/src/router/match-middleware/intercept-resolution.ts +48 -21
- package/src/router/match-middleware/segment-resolution.ts +73 -9
- package/src/router/match-pipelines.ts +10 -45
- package/src/router/match-result.ts +55 -33
- package/src/router/metrics.ts +240 -15
- package/src/router/middleware-cookies.ts +55 -0
- package/src/router/middleware-types.ts +220 -0
- package/src/router/middleware.ts +324 -369
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/pattern-matching.ts +197 -41
- package/src/router/prerender-match.ts +502 -0
- package/src/router/preview-match.ts +98 -0
- package/src/router/request-classification.ts +310 -0
- package/src/router/revalidation.ts +137 -38
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-context.ts +41 -21
- package/src/router/router-interfaces.ts +484 -0
- package/src/router/router-options.ts +618 -0
- package/src/router/router-registry.ts +24 -0
- package/src/router/segment-resolution/fresh.ts +743 -0
- package/src/router/segment-resolution/helpers.ts +268 -0
- package/src/router/segment-resolution/loader-cache.ts +199 -0
- package/src/router/segment-resolution/revalidation.ts +1373 -0
- package/src/router/segment-resolution/static-store.ts +67 -0
- package/src/router/segment-resolution.ts +21 -1315
- package/src/router/segment-wrappers.ts +291 -0
- package/src/router/telemetry-otel.ts +299 -0
- package/src/router/telemetry.ts +300 -0
- package/src/router/timeout.ts +148 -0
- package/src/router/trie-matching.ts +96 -29
- package/src/router/types.ts +17 -9
- package/src/router.ts +646 -1986
- package/src/rsc/handler-context.ts +45 -0
- package/src/rsc/handler.ts +853 -1111
- package/src/rsc/helpers.ts +140 -6
- package/src/rsc/index.ts +0 -20
- package/src/rsc/loader-fetch.ts +229 -0
- package/src/rsc/manifest-init.ts +90 -0
- package/src/rsc/nonce.ts +14 -0
- package/src/rsc/origin-guard.ts +141 -0
- package/src/rsc/progressive-enhancement.ts +391 -0
- package/src/rsc/response-error.ts +37 -0
- package/src/rsc/response-route-handler.ts +347 -0
- package/src/rsc/rsc-rendering.ts +246 -0
- package/src/rsc/runtime-warnings.ts +42 -0
- package/src/rsc/server-action.ts +356 -0
- package/src/rsc/ssr-setup.ts +128 -0
- package/src/rsc/types.ts +46 -11
- package/src/search-params.ts +230 -0
- package/src/segment-system.tsx +165 -17
- package/src/server/context.ts +307 -56
- package/src/server/cookie-store.ts +190 -0
- package/src/server/fetchable-loader-store.ts +37 -0
- package/src/server/handle-store.ts +113 -15
- package/src/server/loader-registry.ts +24 -64
- package/src/server/request-context.ts +607 -81
- package/src/server.ts +35 -155
- package/src/ssr/index.tsx +103 -30
- package/src/static-handler.ts +126 -0
- package/src/theme/ThemeProvider.tsx +21 -15
- package/src/theme/ThemeScript.tsx +5 -5
- package/src/theme/constants.ts +5 -2
- package/src/theme/index.ts +4 -14
- package/src/theme/theme-context.ts +4 -30
- package/src/theme/theme-script.ts +21 -18
- package/src/types/boundaries.ts +158 -0
- package/src/types/cache-types.ts +198 -0
- package/src/types/error-types.ts +192 -0
- package/src/types/global-namespace.ts +100 -0
- package/src/types/handler-context.ts +791 -0
- package/src/types/index.ts +88 -0
- package/src/types/loader-types.ts +210 -0
- package/src/types/route-config.ts +170 -0
- package/src/types/route-entry.ts +109 -0
- package/src/types/segments.ts +150 -0
- package/src/types.ts +1 -1757
- package/src/urls/include-helper.ts +197 -0
- package/src/urls/index.ts +53 -0
- package/src/urls/path-helper-types.ts +346 -0
- package/src/urls/path-helper.ts +364 -0
- package/src/urls/pattern-types.ts +107 -0
- package/src/urls/response-types.ts +116 -0
- package/src/urls/type-extraction.ts +372 -0
- package/src/urls/urls-function.ts +98 -0
- package/src/urls.ts +1 -1282
- package/src/use-loader.tsx +158 -81
- package/src/vite/discovery/bundle-postprocess.ts +181 -0
- package/src/vite/discovery/discover-routers.ts +348 -0
- package/src/vite/discovery/prerender-collection.ts +439 -0
- package/src/vite/discovery/route-types-writer.ts +258 -0
- package/src/vite/discovery/self-gen-tracking.ts +47 -0
- package/src/vite/discovery/state.ts +117 -0
- package/src/vite/discovery/virtual-module-codegen.ts +203 -0
- package/src/vite/index.ts +15 -1963
- package/src/vite/plugin-types.ts +103 -0
- package/src/vite/plugins/cjs-to-esm.ts +93 -0
- package/src/vite/plugins/client-ref-dedup.ts +115 -0
- package/src/vite/plugins/client-ref-hashing.ts +105 -0
- package/src/vite/{expose-action-id.ts → plugins/expose-action-id.ts} +72 -53
- package/src/vite/plugins/expose-id-utils.ts +299 -0
- package/src/vite/plugins/expose-ids/export-analysis.ts +296 -0
- package/src/vite/plugins/expose-ids/handler-transform.ts +209 -0
- package/src/vite/plugins/expose-ids/loader-transform.ts +74 -0
- package/src/vite/plugins/expose-ids/router-transform.ts +110 -0
- package/src/vite/plugins/expose-ids/types.ts +45 -0
- package/src/vite/plugins/expose-internal-ids.ts +781 -0
- package/src/vite/plugins/performance-tracks.ts +88 -0
- package/src/vite/plugins/refresh-cmd.ts +127 -0
- package/src/vite/plugins/use-cache-transform.ts +323 -0
- package/src/vite/plugins/version-injector.ts +83 -0
- package/src/vite/plugins/version-plugin.ts +266 -0
- package/src/vite/plugins/virtual-entries.ts +123 -0
- package/src/vite/plugins/virtual-stub-plugin.ts +29 -0
- package/src/vite/rango.ts +462 -0
- package/src/vite/router-discovery.ts +918 -0
- package/src/vite/utils/ast-handler-extract.ts +517 -0
- package/src/vite/utils/banner.ts +36 -0
- package/src/vite/utils/bundle-analysis.ts +137 -0
- package/src/vite/utils/manifest-utils.ts +70 -0
- package/src/vite/{package-resolution.ts → utils/package-resolution.ts} +25 -29
- package/src/vite/utils/prerender-utils.ts +207 -0
- package/src/vite/utils/shared-utils.ts +170 -0
- package/CLAUDE.md +0 -43
- package/src/browser/lru-cache.ts +0 -69
- package/src/browser/request-controller.ts +0 -164
- package/src/cache/memory-store.ts +0 -253
- package/src/router.gen.ts +0 -6
- package/src/urls.gen.ts +0 -8
- package/src/vite/expose-handle-id.ts +0 -209
- package/src/vite/expose-loader-id.ts +0 -426
- package/src/vite/expose-location-state-id.ts +0 -177
- package/src/vite/expose-prerender-handler-id.ts +0 -429
- /package/src/vite/{version.d.ts → plugins/version.d.ts} +0 -0
package/src/router.ts
CHANGED
|
@@ -1,60 +1,46 @@
|
|
|
1
|
-
import type { ComponentType } from "react";
|
|
2
1
|
import { type ReactNode } from "react";
|
|
3
2
|
import { createCacheScope } from "./cache/cache-scope.js";
|
|
4
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
setCacheProfiles,
|
|
5
|
+
resolveCacheProfiles,
|
|
6
|
+
} from "./cache/profile-registry.js";
|
|
7
|
+
import { isCachedFunction } from "./cache/taint.js";
|
|
5
8
|
import { assertClientComponent } from "./component-utils.js";
|
|
6
9
|
import { DefaultDocument } from "./components/DefaultDocument.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
} from "./errors";
|
|
10
|
-
import { serializeManifest, type SerializedManifest } from "./debug.js";
|
|
11
|
-
import {
|
|
12
|
-
createReverse,
|
|
13
|
-
type ReverseFunction,
|
|
14
|
-
type PrefixRoutePatterns,
|
|
15
|
-
} from "./reverse.js";
|
|
10
|
+
import type { SerializedManifest } from "./debug.js";
|
|
11
|
+
import { createReverse, type ReverseFunction } from "./reverse.js";
|
|
16
12
|
import {
|
|
17
13
|
registerRouteMap,
|
|
18
14
|
getPrecomputedEntries,
|
|
19
|
-
|
|
15
|
+
getRouterManifest,
|
|
16
|
+
getRouterPrecomputedEntries,
|
|
17
|
+
ensureRouterManifest,
|
|
20
18
|
} from "./route-map-builder.js";
|
|
21
|
-
import { tryTrieMatch } from "./router/trie-matching.js";
|
|
22
|
-
import {
|
|
23
|
-
createRouteHelpers,
|
|
24
|
-
type RouteHandlers,
|
|
25
|
-
} from "./route-definition.js";
|
|
26
19
|
import MapRootLayout from "./server/root-layout.js";
|
|
27
|
-
import type { AllUseItems
|
|
20
|
+
import type { AllUseItems } from "./route-types.js";
|
|
28
21
|
import type { UrlPatterns } from "./urls.js";
|
|
22
|
+
import type { UrlBuilder } from "./urls/pattern-types.js";
|
|
23
|
+
import { urls } from "./urls.js";
|
|
29
24
|
import {
|
|
30
25
|
EntryData,
|
|
31
|
-
InterceptEntry,
|
|
32
26
|
InterceptSelectorContext,
|
|
33
27
|
getContext,
|
|
34
28
|
RSCRouterContext,
|
|
35
|
-
runWithPrefixes,
|
|
36
29
|
type MetricsStore,
|
|
37
30
|
} from "./server/context";
|
|
38
31
|
import { createHandleStore, type HandleStore } from "./server/handle-store.js";
|
|
39
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
getRequestContext,
|
|
34
|
+
_getRequestContext,
|
|
35
|
+
} from "./server/request-context.js";
|
|
40
36
|
import type {
|
|
41
|
-
ErrorBoundaryHandler,
|
|
42
|
-
ErrorInfo,
|
|
43
37
|
ErrorPhase,
|
|
44
38
|
HandlerContext,
|
|
45
39
|
LoaderDataResult,
|
|
46
|
-
MatchResult,
|
|
47
|
-
NotFoundBoundaryHandler,
|
|
48
|
-
OnErrorCallback,
|
|
49
40
|
ResolvedRouteMap,
|
|
50
|
-
RouteDefinition,
|
|
51
41
|
RouteEntry,
|
|
52
42
|
TrailingSlashMode,
|
|
53
43
|
} from "./types";
|
|
54
|
-
import type {
|
|
55
|
-
NonceProvider,
|
|
56
|
-
} from "./rsc/types.js";
|
|
57
|
-
import type { ExecutionContext } from "./server/request-context.js";
|
|
58
44
|
|
|
59
45
|
// Extracted router utilities
|
|
60
46
|
import {
|
|
@@ -64,28 +50,10 @@ import {
|
|
|
64
50
|
invokeOnError,
|
|
65
51
|
} from "./router/error-handling.js";
|
|
66
52
|
|
|
67
|
-
// Extracted
|
|
68
|
-
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
resolveLoadersOnlyWithRevalidation as _resolveLoadersOnlyWithRevalidation,
|
|
72
|
-
buildEntryRevalidateMap as _buildEntryRevalidateMap,
|
|
73
|
-
resolveAllSegmentsWithRevalidation as _resolveAllSegmentsWithRevalidation,
|
|
74
|
-
} from "./router/segment-resolution.js";
|
|
75
|
-
|
|
76
|
-
// Extracted intercept resolution functions
|
|
77
|
-
import {
|
|
78
|
-
findInterceptForRoute as _findInterceptForRoute,
|
|
79
|
-
resolveInterceptEntry as _resolveInterceptEntry,
|
|
80
|
-
resolveInterceptLoadersOnly as _resolveInterceptLoadersOnly,
|
|
81
|
-
} from "./router/intercept-resolution.js";
|
|
82
|
-
|
|
83
|
-
// Extracted match API functions
|
|
84
|
-
import {
|
|
85
|
-
createMatchContextForFull as _createMatchContextForFull,
|
|
86
|
-
createMatchContextForPartial as _createMatchContextForPartial,
|
|
87
|
-
matchError as _matchError,
|
|
88
|
-
} from "./router/match-api.js";
|
|
53
|
+
// Extracted module factories
|
|
54
|
+
import { createSegmentWrappers } from "./router/segment-wrappers.js";
|
|
55
|
+
import { createMatchHandlers } from "./router/match-handlers.js";
|
|
56
|
+
import { buildDebugManifest } from "./router/debug-manifest.js";
|
|
89
57
|
|
|
90
58
|
import type { SegmentResolutionDeps, MatchApiDeps } from "./router/types.js";
|
|
91
59
|
import { createHandlerContext } from "./router/handler-context.js";
|
|
@@ -95,993 +63,79 @@ import {
|
|
|
95
63
|
wrapLoaderWithErrorHandling,
|
|
96
64
|
} from "./router/loader-resolution.js";
|
|
97
65
|
import { loadManifest } from "./router/manifest.js";
|
|
66
|
+
import { createMetricsStore } from "./router/metrics.js";
|
|
98
67
|
import {
|
|
99
|
-
createMetricsStore,
|
|
100
|
-
} from "./router/metrics.js";
|
|
101
|
-
import {
|
|
102
|
-
collectRouteMiddleware,
|
|
103
68
|
parsePattern,
|
|
104
69
|
type MiddlewareEntry,
|
|
105
70
|
type MiddlewareFn,
|
|
106
71
|
} from "./router/middleware.js";
|
|
107
72
|
import {
|
|
108
73
|
extractStaticPrefix,
|
|
109
|
-
findMatch as findRouteMatch,
|
|
110
|
-
isLazyEvaluationNeeded,
|
|
111
74
|
traverseBack,
|
|
112
|
-
type RouteMatchResult,
|
|
113
75
|
} from "./router/pattern-matching.js";
|
|
76
|
+
import { resolveSink, safeEmit, getRequestId } from "./router/telemetry.js";
|
|
114
77
|
import { evaluateRevalidation } from "./router/revalidation.js";
|
|
115
78
|
import {
|
|
116
79
|
type RouterContext,
|
|
117
80
|
runWithRouterContext,
|
|
118
81
|
} from "./router/router-context.js";
|
|
119
|
-
import {
|
|
120
|
-
type ActionContext,
|
|
121
|
-
type MatchContext,
|
|
122
|
-
createPipelineState,
|
|
123
|
-
} from "./router/match-context.js";
|
|
124
|
-
import { createMatchPartialPipeline } from "./router/match-pipelines.js";
|
|
125
|
-
import { collectMatchResult } from "./router/match-result.js";
|
|
126
82
|
import { resolveThemeConfig } from "./theme/constants.js";
|
|
83
|
+
import { resolveTimeouts } from "./router/timeout.js";
|
|
127
84
|
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
json: "application/json",
|
|
131
|
-
text: "text/plain",
|
|
132
|
-
xml: "application/xml",
|
|
133
|
-
html: "text/html",
|
|
134
|
-
md: "text/markdown",
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// Reverse lookup: MIME type -> response type tag (e.g. "text/html" -> "html")
|
|
138
|
-
const MIME_RESPONSE_TYPE: Record<string, string> = Object.fromEntries(
|
|
139
|
-
Object.entries(RESPONSE_TYPE_MIME).map(([tag, mime]) => [mime, tag]),
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
interface AcceptEntry {
|
|
143
|
-
mime: string;
|
|
144
|
-
q: number;
|
|
145
|
-
order: number;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Parse an Accept header into a sorted array of MIME entries.
|
|
150
|
-
* Respects q-values (default 1.0) and uses client order as tiebreaker
|
|
151
|
-
* when q-values are equal (matching Express/Hono behavior).
|
|
152
|
-
*/
|
|
153
|
-
function parseAcceptTypes(accept: string): AcceptEntry[] {
|
|
154
|
-
const entries: AcceptEntry[] = [];
|
|
155
|
-
const parts = accept.split(",");
|
|
156
|
-
for (let i = 0; i < parts.length; i++) {
|
|
157
|
-
const part = parts[i]!;
|
|
158
|
-
const segments = part.split(";");
|
|
159
|
-
const mime = segments[0]!.trim();
|
|
160
|
-
if (!mime) continue;
|
|
161
|
-
let q = 1.0;
|
|
162
|
-
for (let j = 1; j < segments.length; j++) {
|
|
163
|
-
const param = segments[j]!.trim();
|
|
164
|
-
if (param.startsWith("q=")) {
|
|
165
|
-
q = Math.max(0, Math.min(1, Number(param.slice(2)) || 0));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
entries.push({ mime, q, order: i });
|
|
169
|
-
}
|
|
170
|
-
// Sort: highest q first, then lowest client order first (stable)
|
|
171
|
-
entries.sort((a, b) => b.q - a.q || a.order - b.order);
|
|
172
|
-
return entries;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Sentinel response type for RSC routes in negotiation candidates
|
|
176
|
-
const RSC_RESPONSE_TYPE = "__rsc__";
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Pick the best negotiate variant by walking the client's sorted Accept list.
|
|
180
|
-
* For each accepted MIME type (in q-value/order priority), check if any
|
|
181
|
-
* candidate serves that type. Wildcards (*\/*) match the first candidate.
|
|
182
|
-
* Falls back to the first candidate if nothing matches.
|
|
183
|
-
*/
|
|
184
|
-
function pickNegotiateVariant(
|
|
185
|
-
acceptEntries: AcceptEntry[],
|
|
186
|
-
candidates: Array<{ routeKey: string; responseType: string }>,
|
|
187
|
-
): { routeKey: string; responseType: string } {
|
|
188
|
-
// Build a MIME -> candidate lookup for O(1) matching
|
|
189
|
-
const byCandidateMime = new Map<string, { routeKey: string; responseType: string }>();
|
|
190
|
-
for (const c of candidates) {
|
|
191
|
-
const mime = c.responseType === RSC_RESPONSE_TYPE ? "text/html" : RESPONSE_TYPE_MIME[c.responseType];
|
|
192
|
-
if (mime && !byCandidateMime.has(mime)) {
|
|
193
|
-
byCandidateMime.set(mime, c);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
for (const entry of acceptEntries) {
|
|
198
|
-
if (entry.q === 0) continue;
|
|
199
|
-
// Wildcard matches first candidate
|
|
200
|
-
if (entry.mime === "*/*") return candidates[0]!;
|
|
201
|
-
// Type wildcard (e.g. "text/*") — match first candidate with that type
|
|
202
|
-
if (entry.mime.endsWith("/*")) {
|
|
203
|
-
const typePrefix = entry.mime.slice(0, entry.mime.indexOf("/"));
|
|
204
|
-
for (const [mime, candidate] of byCandidateMime) {
|
|
205
|
-
if (mime.startsWith(typePrefix + "/")) return candidate;
|
|
206
|
-
}
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
const match = byCandidateMime.get(entry.mime);
|
|
210
|
-
if (match) return match;
|
|
211
|
-
}
|
|
212
|
-
// No match — use first candidate as default
|
|
213
|
-
return candidates[0]!;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Props passed to the root layout component
|
|
218
|
-
*/
|
|
219
|
-
export interface RootLayoutProps {
|
|
220
|
-
children: ReactNode;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Router configuration options
|
|
225
|
-
*/
|
|
226
|
-
/**
|
|
227
|
-
* Brand marker for identifying router instances at build time.
|
|
228
|
-
* Used by the Vite plugin to auto-discover routers from module exports.
|
|
229
|
-
*/
|
|
230
|
-
export const RSC_ROUTER_BRAND: "__rsc_router__" = "__rsc_router__";
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Global registry of all router instances created via createRouter().
|
|
234
|
-
* Each router is keyed by its id (auto-generated or user-provided).
|
|
235
|
-
* Used by the Vite plugin at build time to discover routers and extract
|
|
236
|
-
* manifests, prefix trees, and pre-render candidates.
|
|
237
|
-
*/
|
|
238
|
-
export const RouterRegistry: Map<string, RSCRouter<any, any>> = new Map();
|
|
239
|
-
|
|
240
|
-
let routerAutoId = 0;
|
|
241
|
-
|
|
242
|
-
export interface RSCRouterOptions<TEnv = any> {
|
|
243
|
-
/**
|
|
244
|
-
* Unique identifier for this router instance.
|
|
245
|
-
* Used to namespace static output files and route maps.
|
|
246
|
-
* Auto-generated if not provided.
|
|
247
|
-
*/
|
|
248
|
-
id?: string;
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Enable performance metrics collection
|
|
252
|
-
* When enabled, metrics are output to console and available via Server-Timing header
|
|
253
|
-
*/
|
|
254
|
-
debugPerformance?: boolean;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Allow the `?__debug_manifest` query parameter to return route manifest data as JSON.
|
|
258
|
-
* In development mode this is always enabled regardless of this setting.
|
|
259
|
-
* Defaults to true. Set to false to disable in production.
|
|
260
|
-
* @internal
|
|
261
|
-
*/
|
|
262
|
-
allowDebugManifest?: boolean;
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Document component that wraps the entire application.
|
|
266
|
-
*
|
|
267
|
-
* This component provides the HTML structure for your app and wraps
|
|
268
|
-
* both normal route content AND error states, preventing the app shell
|
|
269
|
-
* from unmounting during errors (avoids FOUC).
|
|
270
|
-
*
|
|
271
|
-
* Must be a client component ("use client") that accepts { children }.
|
|
272
|
-
*
|
|
273
|
-
* If not provided, a default document with basic HTML structure is used:
|
|
274
|
-
* `<html><head><meta charset/viewport></head><body>{children}</body></html>`
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* ```typescript
|
|
278
|
-
* // components/Document.tsx
|
|
279
|
-
* "use client";
|
|
280
|
-
* export function Document({ children }: { children: ReactNode }) {
|
|
281
|
-
* return (
|
|
282
|
-
* <html lang="en">
|
|
283
|
-
* <head>
|
|
284
|
-
* <link rel="stylesheet" href="/styles.css" />
|
|
285
|
-
* </head>
|
|
286
|
-
* <body>
|
|
287
|
-
* <nav>...</nav>
|
|
288
|
-
* {children}
|
|
289
|
-
* </body>
|
|
290
|
-
* </html>
|
|
291
|
-
* );
|
|
292
|
-
* }
|
|
293
|
-
*
|
|
294
|
-
* // router.tsx
|
|
295
|
-
* const router = createRouter<AppEnv>({
|
|
296
|
-
* document: Document,
|
|
297
|
-
* });
|
|
298
|
-
* ```
|
|
299
|
-
*/
|
|
300
|
-
document?: ComponentType<RootLayoutProps>;
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Default error boundary fallback used when no error boundary is defined in the route tree
|
|
304
|
-
* If not provided, errors will propagate and crash the request
|
|
305
|
-
*/
|
|
306
|
-
defaultErrorBoundary?: ReactNode | ErrorBoundaryHandler;
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Default not-found boundary fallback used when no notFoundBoundary is defined in the route tree
|
|
310
|
-
* If not provided, DataNotFoundError will be treated as a regular error
|
|
311
|
-
*/
|
|
312
|
-
defaultNotFoundBoundary?: ReactNode | NotFoundBoundaryHandler;
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Component to render when no route matches the requested URL.
|
|
316
|
-
*
|
|
317
|
-
* This is rendered within your document/app shell with a 404 status code.
|
|
318
|
-
* Use this for a custom 404 page that maintains your app's look and feel.
|
|
319
|
-
*
|
|
320
|
-
* If not provided, a default "Page not found" component is rendered.
|
|
321
|
-
*
|
|
322
|
-
* Can be a static ReactNode or a function receiving the pathname.
|
|
323
|
-
*
|
|
324
|
-
* @example
|
|
325
|
-
* ```typescript
|
|
326
|
-
* // Simple static component
|
|
327
|
-
* const router = createRouter<AppEnv>({
|
|
328
|
-
* document: Document,
|
|
329
|
-
* notFound: <NotFound404 />,
|
|
330
|
-
* });
|
|
331
|
-
*
|
|
332
|
-
* // Dynamic component with pathname
|
|
333
|
-
* const router = createRouter<AppEnv>({
|
|
334
|
-
* document: Document,
|
|
335
|
-
* notFound: ({ pathname }) => (
|
|
336
|
-
* <div>
|
|
337
|
-
* <h1>404 - Not Found</h1>
|
|
338
|
-
* <p>No page exists at {pathname}</p>
|
|
339
|
-
* <a href="/">Go home</a>
|
|
340
|
-
* </div>
|
|
341
|
-
* ),
|
|
342
|
-
* });
|
|
343
|
-
* ```
|
|
344
|
-
*/
|
|
345
|
-
notFound?: ReactNode | ((props: { pathname: string }) => ReactNode);
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Callback invoked when an error occurs during request handling.
|
|
349
|
-
*
|
|
350
|
-
* This callback is for notification/logging purposes - it cannot modify
|
|
351
|
-
* the error handling flow. Use errorBoundary() in route definitions to
|
|
352
|
-
* customize error UI.
|
|
353
|
-
*
|
|
354
|
-
* The callback receives comprehensive context about the error including:
|
|
355
|
-
* - The error itself
|
|
356
|
-
* - Phase where it occurred (routing, middleware, loader, handler, etc.)
|
|
357
|
-
* - Request info (URL, method, params)
|
|
358
|
-
* - Route info (routeKey, segmentId)
|
|
359
|
-
* - Environment/bindings
|
|
360
|
-
* - Duration from request start
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* ```typescript
|
|
364
|
-
* const router = createRouter<AppEnv>({
|
|
365
|
-
* onError: (context) => {
|
|
366
|
-
* // Send to error tracking service
|
|
367
|
-
* Sentry.captureException(context.error, {
|
|
368
|
-
* tags: {
|
|
369
|
-
* phase: context.phase,
|
|
370
|
-
* route: context.routeKey,
|
|
371
|
-
* },
|
|
372
|
-
* extra: {
|
|
373
|
-
* url: context.url.toString(),
|
|
374
|
-
* params: context.params,
|
|
375
|
-
* duration: context.duration,
|
|
376
|
-
* },
|
|
377
|
-
* });
|
|
378
|
-
* },
|
|
379
|
-
* });
|
|
380
|
-
* ```
|
|
381
|
-
*/
|
|
382
|
-
onError?: OnErrorCallback<TEnv>;
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Cache store for segment caching.
|
|
386
|
-
*
|
|
387
|
-
* When provided, enables route-level caching via cache() boundaries.
|
|
388
|
-
* The store handles persistence (memory, KV, Redis, etc.).
|
|
389
|
-
*
|
|
390
|
-
* Can be a static config or a function receiving env for runtime bindings.
|
|
391
|
-
*
|
|
392
|
-
* @example Static config
|
|
393
|
-
* ```typescript
|
|
394
|
-
* import { MemorySegmentCacheStore } from "rsc-router/rsc";
|
|
395
|
-
*
|
|
396
|
-
* const router = createRouter({
|
|
397
|
-
* cache: {
|
|
398
|
-
* store: new MemorySegmentCacheStore({ defaults: { ttl: 60 } }),
|
|
399
|
-
* },
|
|
400
|
-
* });
|
|
401
|
-
* ```
|
|
402
|
-
*
|
|
403
|
-
* @example Dynamic config with env (e.g., Cloudflare Workers with ExecutionContext)
|
|
404
|
-
* ```typescript
|
|
405
|
-
* const router = createRouter<AppEnv>({
|
|
406
|
-
* cache: (env) => ({
|
|
407
|
-
* store: new CFCacheStore({
|
|
408
|
-
* defaults: { ttl: 60 },
|
|
409
|
-
* ctx: env.ctx, // ExecutionContext for non-blocking writes
|
|
410
|
-
* }),
|
|
411
|
-
* }),
|
|
412
|
-
* });
|
|
413
|
-
* ```
|
|
414
|
-
*/
|
|
415
|
-
cache?:
|
|
416
|
-
| { store: SegmentCacheStore; enabled?: boolean }
|
|
417
|
-
| ((env: TEnv & { ctx?: ExecutionContext }) => {
|
|
418
|
-
store: SegmentCacheStore;
|
|
419
|
-
enabled?: boolean;
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Theme configuration for automatic theme management.
|
|
424
|
-
*
|
|
425
|
-
* When provided, enables:
|
|
426
|
-
* - ctx.theme and ctx.setTheme() in route handlers
|
|
427
|
-
* - useTheme() hook for client components
|
|
428
|
-
* - FOUC prevention via inline script in MetaTags
|
|
429
|
-
* - Automatic ThemeProvider wrapping in NavigationProvider
|
|
430
|
-
*
|
|
431
|
-
* @example
|
|
432
|
-
* ```typescript
|
|
433
|
-
* const router = createRouter<AppEnv>({
|
|
434
|
-
* theme: {
|
|
435
|
-
* defaultTheme: "system",
|
|
436
|
-
* themes: ["light", "dark"],
|
|
437
|
-
* }
|
|
438
|
-
* });
|
|
439
|
-
*
|
|
440
|
-
* // In route handler:
|
|
441
|
-
* route("settings", (ctx) => {
|
|
442
|
-
* const theme = ctx.theme; // "light" | "dark" | "system"
|
|
443
|
-
* ctx.setTheme("dark"); // Sets cookie
|
|
444
|
-
* return <SettingsPage />;
|
|
445
|
-
* });
|
|
446
|
-
*
|
|
447
|
-
* // In client component:
|
|
448
|
-
* import { useTheme } from "@rangojs/router/theme";
|
|
449
|
-
*
|
|
450
|
-
* function ThemeToggle() {
|
|
451
|
-
* const { theme, setTheme, themes } = useTheme();
|
|
452
|
-
* return <select value={theme} onChange={e => setTheme(e.target.value)}>
|
|
453
|
-
* {themes.map(t => <option key={t}>{t}</option>)}
|
|
454
|
-
* </select>;
|
|
455
|
-
* }
|
|
456
|
-
* ```
|
|
457
|
-
*
|
|
458
|
-
* Use `theme: true` to enable with all defaults.
|
|
459
|
-
*/
|
|
460
|
-
theme?: import("./theme/types.js").ThemeConfig | true;
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* URL patterns to register with the router.
|
|
464
|
-
*
|
|
465
|
-
* Alternative to calling `.routes()` method - allows passing patterns
|
|
466
|
-
* directly in the config for a more concise setup.
|
|
467
|
-
*
|
|
468
|
-
* @example
|
|
469
|
-
* ```typescript
|
|
470
|
-
* import { urls } from "@rangojs/router/server";
|
|
471
|
-
*
|
|
472
|
-
* const urlpatterns = urls(({ path, layout }) => [
|
|
473
|
-
* path("/", HomePage, { name: "home" }),
|
|
474
|
-
* path("/about", AboutPage, { name: "about" }),
|
|
475
|
-
* ]);
|
|
476
|
-
*
|
|
477
|
-
* const router = createRouter<AppEnv>({
|
|
478
|
-
* document: Document,
|
|
479
|
-
* urls: urlpatterns,
|
|
480
|
-
* });
|
|
481
|
-
* ```
|
|
482
|
-
*/
|
|
483
|
-
urls?: UrlPatterns<TEnv, any>;
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* Nonce provider for Content Security Policy (CSP).
|
|
487
|
-
*
|
|
488
|
-
* Can be:
|
|
489
|
-
* - A function that returns a nonce string
|
|
490
|
-
* - A function that returns `true` to auto-generate a nonce
|
|
491
|
-
* - Undefined to disable nonce (default)
|
|
492
|
-
*
|
|
493
|
-
* The nonce will be applied to inline scripts injected by the RSC payload.
|
|
494
|
-
* It's also available to middleware via `ctx.get('nonce')`.
|
|
495
|
-
*
|
|
496
|
-
* @example Auto-generate nonce
|
|
497
|
-
* ```tsx
|
|
498
|
-
* createRouter({
|
|
499
|
-
* nonce: () => true,
|
|
500
|
-
* });
|
|
501
|
-
* ```
|
|
502
|
-
*
|
|
503
|
-
* @example Custom nonce from request context
|
|
504
|
-
* ```tsx
|
|
505
|
-
* createRouter({
|
|
506
|
-
* nonce: (request, env) => env.nonce,
|
|
507
|
-
* });
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
nonce?: NonceProvider<TEnv>;
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* RSC version string included in metadata.
|
|
514
|
-
* The browser sends this back on partial requests to detect version mismatches.
|
|
515
|
-
*
|
|
516
|
-
* Defaults to the auto-generated VERSION from `@rangojs/router:version` virtual module.
|
|
517
|
-
* Only set this if you need a custom versioning strategy.
|
|
518
|
-
*
|
|
519
|
-
* @default VERSION from @rangojs/router:version
|
|
520
|
-
*/
|
|
521
|
-
version?: string;
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Enable connection warmup to keep TCP+TLS alive after idle periods.
|
|
525
|
-
*
|
|
526
|
-
* When enabled, the client sends a HEAD request after the user returns
|
|
527
|
-
* from an idle period (60s+), prewarming the TLS connection before
|
|
528
|
-
* the next navigation.
|
|
529
|
-
*
|
|
530
|
-
* @default true
|
|
531
|
-
*/
|
|
532
|
-
warmup?: boolean;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* Merge route patterns with response types into a single route map.
|
|
537
|
-
* Routes with response types get { path, response } objects; others stay as strings.
|
|
538
|
-
*/
|
|
539
|
-
type MergeRoutesWithResponses<
|
|
540
|
-
TRoutes extends Record<string, string>,
|
|
541
|
-
TResponses,
|
|
542
|
-
> = {
|
|
543
|
-
[K in keyof TRoutes]: K extends keyof NonNullable<TResponses>
|
|
544
|
-
? unknown extends NonNullable<TResponses>[K]
|
|
545
|
-
? TRoutes[K] // RSC route — TData defaults to unknown, keep as plain string
|
|
546
|
-
: { readonly path: TRoutes[K]; readonly response: NonNullable<TResponses>[K] }
|
|
547
|
-
: TRoutes[K]
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Extract the URL pattern from a route entry (string or { path, response } object)
|
|
552
|
-
*/
|
|
553
|
-
type PatternOfEntry<V> =
|
|
554
|
-
V extends string ? V
|
|
555
|
-
: V extends { readonly path: infer P extends string } ? P
|
|
556
|
-
: never;
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Type-level detection of conflicting route keys.
|
|
560
|
-
* Extracts keys that exist in both TExisting and TNew but with different URL patterns.
|
|
561
|
-
* Returns `never` if no conflicts exist.
|
|
562
|
-
* Compares patterns (not full entries) to handle both string and { path, response } values.
|
|
563
|
-
*
|
|
564
|
-
* @example
|
|
565
|
-
* ```typescript
|
|
566
|
-
* ConflictingKeys<{ a: "/a" }, { a: "/b" }> // "a" (conflict - same key, different URLs)
|
|
567
|
-
* ConflictingKeys<{ a: "/a" }, { a: "/a" }> // never (no conflict - same key and URL)
|
|
568
|
-
* ConflictingKeys<{ a: "/a" }, { b: "/b" }> // never (no conflict - different keys)
|
|
569
|
-
* ```
|
|
570
|
-
*/
|
|
571
|
-
type ConflictingKeys<
|
|
572
|
-
TExisting extends Record<string, unknown>,
|
|
573
|
-
TNew extends Record<string, unknown>,
|
|
574
|
-
> = {
|
|
575
|
-
[K in keyof TExisting & keyof TNew]: PatternOfEntry<TExisting[K]> extends PatternOfEntry<TNew[K]>
|
|
576
|
-
? PatternOfEntry<TNew[K]> extends PatternOfEntry<TExisting[K]>
|
|
577
|
-
? never // Same pattern, no conflict
|
|
578
|
-
: K // Different patterns, conflict
|
|
579
|
-
: K; // Different patterns, conflict
|
|
580
|
-
}[keyof TExisting & keyof TNew];
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* Error type returned when route keys conflict.
|
|
584
|
-
* Methods require an impossible `never` parameter so TypeScript errors at the call site.
|
|
585
|
-
*/
|
|
586
|
-
type RouteConflictError<TConflicts extends string> = {
|
|
587
|
-
__error: `Route key conflict! Key "${TConflicts}" already exists with a different URL pattern.`;
|
|
588
|
-
hint: "Route keys must be globally unique. Use prefixed names like 'blog.index' instead of 'index'.";
|
|
589
|
-
conflictingKeys: TConflicts;
|
|
590
|
-
// These methods require `never` so calling them produces an error at the call site
|
|
591
|
-
routes: (
|
|
592
|
-
__conflict: `Fix route key conflict: "${TConflicts}" is already defined with a different URL pattern`,
|
|
593
|
-
) => never;
|
|
594
|
-
map: (
|
|
595
|
-
__conflict: `Fix route key conflict: "${TConflicts}" is already defined with a different URL pattern`,
|
|
596
|
-
) => never;
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Simplified route helpers for inline route definitions.
|
|
601
|
-
* Uses TRoutes (Record<string, string>) instead of RouteDefinition.
|
|
602
|
-
*
|
|
603
|
-
* Note: Some helpers use `any` for context types as a trade-off for simpler usage.
|
|
604
|
-
* The main type safety is in the `route` helper which enforces valid route names.
|
|
605
|
-
* For full type safety, use the standard map() API with separate handler files.
|
|
606
|
-
*/
|
|
607
|
-
type InlineRouteHelpers<TRoutes extends Record<string, string>, TEnv> = {
|
|
608
|
-
/**
|
|
609
|
-
* Define a route handler for a specific route pattern
|
|
610
|
-
*/
|
|
611
|
-
route: <K extends keyof TRoutes & string>(
|
|
612
|
-
name: K,
|
|
613
|
-
handler:
|
|
614
|
-
| ((ctx: HandlerContext<{}, TEnv>) => ReactNode | Promise<ReactNode>)
|
|
615
|
-
| ReactNode,
|
|
616
|
-
) => AllUseItems;
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Define a layout that wraps child routes
|
|
620
|
-
*/
|
|
621
|
-
layout: (
|
|
622
|
-
component:
|
|
623
|
-
| ReactNode
|
|
624
|
-
| ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>),
|
|
625
|
-
use?: () => AllUseItems[],
|
|
626
|
-
) => AllUseItems;
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Define parallel routes
|
|
630
|
-
*/
|
|
631
|
-
parallel: (
|
|
632
|
-
slots: Record<
|
|
633
|
-
`@${string}`,
|
|
634
|
-
| ReactNode
|
|
635
|
-
| ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>)
|
|
636
|
-
>,
|
|
637
|
-
use?: () => AllUseItems[],
|
|
638
|
-
) => AllUseItems;
|
|
639
|
-
|
|
640
|
-
/**
|
|
641
|
-
* Define route middleware
|
|
642
|
-
*/
|
|
643
|
-
middleware: (
|
|
644
|
-
fn: (ctx: any, next: () => Promise<void>) => Promise<void>,
|
|
645
|
-
) => AllUseItems;
|
|
85
|
+
// Extracted content negotiation utilities
|
|
86
|
+
import { flattenNamedRoutes } from "./router/content-negotiation.js";
|
|
646
87
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Define error boundaries
|
|
664
|
-
*/
|
|
665
|
-
errorBoundary: (
|
|
666
|
-
handler: ReactNode | ((props: { error: Error }) => ReactNode),
|
|
667
|
-
) => AllUseItems;
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* Define not found boundaries
|
|
671
|
-
*/
|
|
672
|
-
notFoundBoundary: (
|
|
673
|
-
handler: ReactNode | ((props: { pathname: string }) => ReactNode),
|
|
674
|
-
) => AllUseItems;
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* Define intercept routes
|
|
678
|
-
*/
|
|
679
|
-
intercept: (
|
|
680
|
-
name: string,
|
|
681
|
-
handler:
|
|
682
|
-
| ReactNode
|
|
683
|
-
| ((ctx: HandlerContext<any, TEnv>) => ReactNode | Promise<ReactNode>),
|
|
684
|
-
use?: () => AllUseItems[],
|
|
685
|
-
) => AllUseItems;
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Define when conditions for intercepts
|
|
689
|
-
*/
|
|
690
|
-
when: (condition: (ctx: any) => boolean | Promise<boolean>) => AllUseItems;
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Define cache configuration
|
|
694
|
-
*/
|
|
695
|
-
cache: (
|
|
696
|
-
config: { ttl?: number; swr?: number } | false,
|
|
697
|
-
use?: () => AllUseItems[],
|
|
698
|
-
) => AllUseItems;
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
* Router builder for chaining .use() and .map()
|
|
703
|
-
* TRoutes accumulates all registered route types through the chain
|
|
704
|
-
* TLocalRoutes contains the routes for the current .routes() call (for inline handler typing)
|
|
705
|
-
*/
|
|
706
|
-
interface RouteBuilder<
|
|
707
|
-
T extends RouteDefinition,
|
|
708
|
-
TEnv,
|
|
709
|
-
TRoutes extends Record<string, unknown>,
|
|
710
|
-
TLocalRoutes extends Record<string, string> = Record<string, string>,
|
|
711
|
-
> {
|
|
712
|
-
/**
|
|
713
|
-
* Add middleware scoped to this mount
|
|
714
|
-
* Called between .routes() and .map()
|
|
715
|
-
*
|
|
716
|
-
* @example
|
|
717
|
-
* ```typescript
|
|
718
|
-
* .routes("/admin", adminRoutes)
|
|
719
|
-
* .use(authMiddleware) // All of /admin/*
|
|
720
|
-
* .use("/danger/*", superAuth) // Only /admin/danger/*
|
|
721
|
-
* .map(() => import("./admin"))
|
|
722
|
-
* ```
|
|
723
|
-
*/
|
|
724
|
-
use(
|
|
725
|
-
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
726
|
-
middleware?: MiddlewareFn<TEnv>,
|
|
727
|
-
): RouteBuilder<T, TEnv, TRoutes, TLocalRoutes>;
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Map routes to handlers
|
|
731
|
-
*
|
|
732
|
-
* Supports two patterns:
|
|
733
|
-
*
|
|
734
|
-
* 1. Lazy loading (code-split):
|
|
735
|
-
* ```typescript
|
|
736
|
-
* .routes(homeRoutes)
|
|
737
|
-
* .map(() => import("./handlers/home"))
|
|
738
|
-
* ```
|
|
739
|
-
*
|
|
740
|
-
* 2. Inline definition:
|
|
741
|
-
* ```typescript
|
|
742
|
-
* .routes({ index: "/", about: "/about" })
|
|
743
|
-
* .map(({ route }) => [
|
|
744
|
-
* route("index", () => <HomePage />),
|
|
745
|
-
* route("about", () => <AboutPage />),
|
|
746
|
-
* ])
|
|
747
|
-
* ```
|
|
748
|
-
*/
|
|
749
|
-
// Inline definition overload - handler receives helpers (must be first for correct inference)
|
|
750
|
-
// Uses TLocalRoutes so route names don't need the prefix
|
|
751
|
-
map<
|
|
752
|
-
H extends (
|
|
753
|
-
helpers: InlineRouteHelpers<TLocalRoutes, TEnv>,
|
|
754
|
-
) => Array<AllUseItems>,
|
|
755
|
-
>(
|
|
756
|
-
handler: H,
|
|
757
|
-
): RSCRouter<TEnv, TRoutes>;
|
|
758
|
-
// Lazy loading overload - verifies imported handlers match route definition
|
|
759
|
-
map(
|
|
760
|
-
handler: () =>
|
|
761
|
-
| Array<AllUseItems>
|
|
762
|
-
| Promise<{ default: RouteHandlers<TLocalRoutes> }>
|
|
763
|
-
| Promise<RouteHandlers<TLocalRoutes>>,
|
|
764
|
-
): RSCRouter<TEnv, TRoutes>;
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* Accumulated route map for typeof extraction
|
|
768
|
-
* Used for module augmentation: `type AppRoutes = typeof _router.routeMap`
|
|
769
|
-
*/
|
|
770
|
-
readonly routeMap: TRoutes;
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* RSC Router interface
|
|
775
|
-
* TRoutes accumulates all registered route types through the builder chain
|
|
776
|
-
*/
|
|
777
|
-
export interface RSCRouter<
|
|
778
|
-
TEnv = any,
|
|
779
|
-
TRoutes extends Record<string, unknown> = Record<string, string>,
|
|
780
|
-
> {
|
|
781
|
-
/**
|
|
782
|
-
* Brand marker for build-time discovery.
|
|
783
|
-
* The Vite plugin uses this to identify router instances in module exports.
|
|
784
|
-
*/
|
|
785
|
-
readonly __brand: typeof RSC_ROUTER_BRAND;
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* Unique identifier for this router instance.
|
|
789
|
-
* Used to namespace static output and isolate route maps between routers.
|
|
790
|
-
*/
|
|
791
|
-
readonly id: string;
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* Register routes with a prefix
|
|
795
|
-
* Route keys stay unchanged, only URL patterns get the prefix applied.
|
|
796
|
-
* This enables composable route modules that work regardless of mount point.
|
|
797
|
-
*
|
|
798
|
-
* @throws Compile-time error if route keys conflict with previously registered routes
|
|
799
|
-
*/
|
|
800
|
-
routes<const TPrefix extends string, const T extends Record<string, string>>(
|
|
801
|
-
prefix: TPrefix,
|
|
802
|
-
routes: T,
|
|
803
|
-
): ConflictingKeys<TRoutes, PrefixRoutePatterns<T, TPrefix>> extends never
|
|
804
|
-
? RouteBuilder<
|
|
805
|
-
RouteDefinition,
|
|
806
|
-
TEnv,
|
|
807
|
-
TRoutes & PrefixRoutePatterns<T, TPrefix>,
|
|
808
|
-
T
|
|
809
|
-
>
|
|
810
|
-
: RouteConflictError<
|
|
811
|
-
ConflictingKeys<TRoutes, PrefixRoutePatterns<T, TPrefix>> & string
|
|
812
|
-
>;
|
|
813
|
-
|
|
814
|
-
/**
|
|
815
|
-
* Register routes without a prefix
|
|
816
|
-
* Route types are accumulated through the chain
|
|
817
|
-
*
|
|
818
|
-
* @throws Compile-time error if route keys conflict with previously registered routes
|
|
819
|
-
*/
|
|
820
|
-
routes<const T extends Record<string, string>>(
|
|
821
|
-
routes: T,
|
|
822
|
-
): ConflictingKeys<TRoutes, T> extends never
|
|
823
|
-
? RouteBuilder<RouteDefinition, TEnv, TRoutes & T, T>
|
|
824
|
-
: RouteConflictError<ConflictingKeys<TRoutes, T> & string>;
|
|
825
|
-
|
|
826
|
-
/**
|
|
827
|
-
* Register routes using Django-style URL patterns
|
|
828
|
-
* This is the new API for @rangojs/router - call once with urls() result
|
|
829
|
-
*
|
|
830
|
-
* @example
|
|
831
|
-
* ```typescript
|
|
832
|
-
* createRouter({})
|
|
833
|
-
* .routes(urlpatterns) // Single call with urls() result
|
|
834
|
-
* ```
|
|
835
|
-
*/
|
|
836
|
-
routes<T extends UrlPatterns<TEnv, any>>(
|
|
837
|
-
patterns: T,
|
|
838
|
-
): RSCRouter<
|
|
839
|
-
TEnv,
|
|
840
|
-
TRoutes &
|
|
841
|
-
(NonNullable<T["_routes"]> extends Record<string, string>
|
|
842
|
-
? MergeRoutesWithResponses<NonNullable<T["_routes"]>, T["_responses"]>
|
|
843
|
-
: Record<string, string>)
|
|
844
|
-
>;
|
|
845
|
-
|
|
846
|
-
/**
|
|
847
|
-
* Add global middleware that runs on all routes
|
|
848
|
-
* Position matters: middleware before any .routes() is global
|
|
849
|
-
*
|
|
850
|
-
* @example
|
|
851
|
-
* ```typescript
|
|
852
|
-
* createRouter({ document: RootLayout })
|
|
853
|
-
* .use(loggerMiddleware) // All routes
|
|
854
|
-
* .use("/api/*", rateLimiter) // Pattern match
|
|
855
|
-
* .routes(homeRoutes)
|
|
856
|
-
* .map(() => import("./home"))
|
|
857
|
-
* ```
|
|
858
|
-
*/
|
|
859
|
-
use(
|
|
860
|
-
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
861
|
-
middleware?: MiddlewareFn<TEnv>,
|
|
862
|
-
): RSCRouter<TEnv, TRoutes>;
|
|
863
|
-
|
|
864
|
-
/**
|
|
865
|
-
* Type-safe URL builder for registered routes
|
|
866
|
-
* Types are inferred from the accumulated route registrations
|
|
867
|
-
* Route keys stay unchanged regardless of mount prefix.
|
|
868
|
-
*
|
|
869
|
-
* @example
|
|
870
|
-
* ```typescript
|
|
871
|
-
* // Given: .routes("/shop", { cart: "/cart", detail: "/product/:slug" })
|
|
872
|
-
* router.reverse("cart"); // "/shop/cart"
|
|
873
|
-
* router.reverse("detail", { slug: "widget" }); // "/shop/product/widget"
|
|
874
|
-
* ```
|
|
875
|
-
*/
|
|
876
|
-
reverse: ReverseFunction<TRoutes>;
|
|
877
|
-
|
|
878
|
-
/**
|
|
879
|
-
* Accumulated route map for typeof extraction
|
|
880
|
-
* Used for module augmentation: `type AppRoutes = typeof _router.routeMap`
|
|
881
|
-
*
|
|
882
|
-
* @example
|
|
883
|
-
* ```typescript
|
|
884
|
-
* const _router = createRouter<AppEnv>()
|
|
885
|
-
* .routes(homeRoutes).map(() => import('./home'))
|
|
886
|
-
* .routes('/shop', shopRoutes).map(() => import('./shop'));
|
|
887
|
-
*
|
|
888
|
-
* type AppRoutes = typeof _router.routeMap;
|
|
889
|
-
*
|
|
890
|
-
* declare global {
|
|
891
|
-
* namespace RSCRouter {
|
|
892
|
-
* interface RegisteredRoutes extends AppRoutes {}
|
|
893
|
-
* }
|
|
894
|
-
* }
|
|
895
|
-
* ```
|
|
896
|
-
*/
|
|
897
|
-
readonly routeMap: TRoutes;
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
* Root layout component that wraps the entire application
|
|
901
|
-
* Access this to pass to renderSegments
|
|
902
|
-
*/
|
|
903
|
-
readonly rootLayout?: ComponentType<RootLayoutProps>;
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Error callback for monitoring/alerting
|
|
907
|
-
* Called when errors occur in loaders, actions, or routes
|
|
908
|
-
*/
|
|
909
|
-
readonly onError?: RSCRouterOptions<TEnv>["onError"];
|
|
910
|
-
|
|
911
|
-
/**
|
|
912
|
-
* Cache configuration (for internal use by RSC handler)
|
|
913
|
-
*/
|
|
914
|
-
readonly cache?: RSCRouterOptions<TEnv>["cache"];
|
|
915
|
-
|
|
916
|
-
/**
|
|
917
|
-
* Not found component to render when no route matches (for internal use by RSC handler)
|
|
918
|
-
*/
|
|
919
|
-
readonly notFound?: RSCRouterOptions<TEnv>["notFound"];
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* Resolved theme configuration (null if theme not enabled)
|
|
923
|
-
* Used by NavigationProvider to include ThemeProvider and by MetaTags to render theme script
|
|
924
|
-
*/
|
|
925
|
-
readonly themeConfig: import("./theme/types.js").ResolvedThemeConfig | null;
|
|
926
|
-
|
|
927
|
-
/**
|
|
928
|
-
* Whether connection warmup is enabled.
|
|
929
|
-
* When true, the client sends HEAD /?_rsc_warmup after idle periods
|
|
930
|
-
* and the server responds with 204 No Content.
|
|
931
|
-
*/
|
|
932
|
-
readonly warmupEnabled: boolean;
|
|
933
|
-
|
|
934
|
-
/**
|
|
935
|
-
* Whether ?__debug_manifest is allowed in production.
|
|
936
|
-
* Always enabled in development.
|
|
937
|
-
* @internal
|
|
938
|
-
*/
|
|
939
|
-
readonly allowDebugManifest: boolean;
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
* App-level middleware entries (for internal use by RSC handler)
|
|
943
|
-
* These wrap the entire request/response cycle
|
|
944
|
-
*/
|
|
945
|
-
readonly middleware: MiddlewareEntry<TEnv>[];
|
|
946
|
-
|
|
947
|
-
/**
|
|
948
|
-
* Nonce provider for CSP (for internal use by createHandler)
|
|
949
|
-
*/
|
|
950
|
-
readonly nonce?: NonceProvider<TEnv>;
|
|
951
|
-
|
|
952
|
-
/**
|
|
953
|
-
* RSC version string (for internal use by createHandler)
|
|
954
|
-
*/
|
|
955
|
-
readonly version?: string;
|
|
956
|
-
|
|
957
|
-
/**
|
|
958
|
-
* URL patterns reference for build-time manifest generation
|
|
959
|
-
* @internal
|
|
960
|
-
*/
|
|
961
|
-
readonly urlpatterns?: UrlPatterns<TEnv, any>;
|
|
962
|
-
|
|
963
|
-
match(request: Request, context: TEnv): Promise<MatchResult>;
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* Preview match - returns route middleware without segment resolution.
|
|
967
|
-
* Also returns responseType and handler for response routes (non-RSC short-circuit).
|
|
968
|
-
*/
|
|
969
|
-
previewMatch(
|
|
970
|
-
request: Request,
|
|
971
|
-
context: TEnv,
|
|
972
|
-
): Promise<{
|
|
973
|
-
routeMiddleware?: Array<{
|
|
974
|
-
handler: import("./router/middleware.js").MiddlewareFn;
|
|
975
|
-
params: Record<string, string>;
|
|
976
|
-
}>;
|
|
977
|
-
responseType?: string;
|
|
978
|
-
handler?: Function;
|
|
979
|
-
params?: Record<string, string>;
|
|
980
|
-
negotiated?: boolean;
|
|
981
|
-
} | null>;
|
|
982
|
-
|
|
983
|
-
matchPartial(
|
|
984
|
-
request: Request,
|
|
985
|
-
context: TEnv,
|
|
986
|
-
actionContext?: {
|
|
987
|
-
actionId?: string;
|
|
988
|
-
actionUrl?: URL;
|
|
989
|
-
actionResult?: any;
|
|
990
|
-
formData?: FormData;
|
|
991
|
-
},
|
|
992
|
-
): Promise<MatchResult | null>;
|
|
993
|
-
|
|
994
|
-
/**
|
|
995
|
-
* Match an error to the nearest error boundary and return error segments
|
|
996
|
-
*
|
|
997
|
-
* Used when an action or other operation fails and we need to render
|
|
998
|
-
* the error boundary UI. Finds the nearest errorBoundary in the route tree
|
|
999
|
-
* for the current URL and renders it with the error info.
|
|
1000
|
-
*
|
|
1001
|
-
* @param request - The current request (used to match the route)
|
|
1002
|
-
* @param context - Environment context
|
|
1003
|
-
* @param error - The error that occurred
|
|
1004
|
-
* @param segmentType - Type of segment where error occurred (default: "route")
|
|
1005
|
-
* @returns MatchResult with error segment, or null if no error boundary found
|
|
1006
|
-
*/
|
|
1007
|
-
matchError(
|
|
1008
|
-
request: Request,
|
|
1009
|
-
context: TEnv,
|
|
1010
|
-
error: unknown,
|
|
1011
|
-
segmentType?: ErrorInfo["segmentType"],
|
|
1012
|
-
): Promise<MatchResult | null>;
|
|
1013
|
-
|
|
1014
|
-
/**
|
|
1015
|
-
* @internal
|
|
1016
|
-
* Debug utility to serialize the manifest for inspection
|
|
1017
|
-
* Returns a JSON-friendly representation of all routes and layouts
|
|
1018
|
-
*/
|
|
1019
|
-
debugManifest(): Promise<SerializedManifest>;
|
|
1020
|
-
|
|
1021
|
-
/**
|
|
1022
|
-
* Handle an RSC request.
|
|
1023
|
-
*
|
|
1024
|
-
* Uses the router's configuration (nonce, version, cache) automatically.
|
|
1025
|
-
* The handler is lazily created on first call.
|
|
1026
|
-
*
|
|
1027
|
-
* @example Cloudflare Workers
|
|
1028
|
-
* ```tsx
|
|
1029
|
-
* import { router } from "./router";
|
|
1030
|
-
*
|
|
1031
|
-
* export default { fetch: router.fetch };
|
|
1032
|
-
* ```
|
|
1033
|
-
*
|
|
1034
|
-
* @example Direct export
|
|
1035
|
-
* ```tsx
|
|
1036
|
-
* const router = createRouter({
|
|
1037
|
-
* document: Document,
|
|
1038
|
-
* urls: urlpatterns,
|
|
1039
|
-
* nonce: () => true,
|
|
1040
|
-
* });
|
|
1041
|
-
*
|
|
1042
|
-
* export const fetch = router.fetch;
|
|
1043
|
-
* ```
|
|
1044
|
-
*/
|
|
1045
|
-
fetch(
|
|
1046
|
-
request: Request,
|
|
1047
|
-
env: TEnv & { ctx?: ExecutionContext },
|
|
1048
|
-
): Promise<Response>;
|
|
1049
|
-
}
|
|
88
|
+
// Extracted router types and registry
|
|
89
|
+
import {
|
|
90
|
+
RSC_ROUTER_BRAND,
|
|
91
|
+
RouterRegistry,
|
|
92
|
+
nextRouterAutoId,
|
|
93
|
+
} from "./router/router-registry.js";
|
|
94
|
+
import type {
|
|
95
|
+
RSCRouterOptions,
|
|
96
|
+
RootLayoutProps,
|
|
97
|
+
} from "./router/router-options.js";
|
|
98
|
+
import type {
|
|
99
|
+
RSCRouter,
|
|
100
|
+
RSCRouterInternal,
|
|
101
|
+
RouterRequestInput,
|
|
102
|
+
} from "./router/router-interfaces.js";
|
|
1050
103
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
*/
|
|
104
|
+
// Extracted closure functions
|
|
105
|
+
import {
|
|
106
|
+
findLazyIncludes,
|
|
107
|
+
evaluateLazyEntry as _evaluateLazyEntry,
|
|
108
|
+
type LazyEvalDeps,
|
|
109
|
+
} from "./router/lazy-includes.js";
|
|
110
|
+
import { createFindMatch } from "./router/find-match.js";
|
|
111
|
+
import {
|
|
112
|
+
matchForPrerender as _matchForPrerender,
|
|
113
|
+
renderStaticSegment as _renderStaticSegment,
|
|
114
|
+
} from "./router/prerender-match.js";
|
|
115
|
+
|
|
116
|
+
// Re-export public types and values from extracted modules
|
|
117
|
+
export { RSC_ROUTER_BRAND, RouterRegistry } from "./router/router-registry.js";
|
|
118
|
+
export type {
|
|
119
|
+
RSCRouterOptions,
|
|
120
|
+
RootLayoutProps,
|
|
121
|
+
SSRStreamMode,
|
|
122
|
+
SSROptions,
|
|
123
|
+
ResolveStreamingContext,
|
|
124
|
+
} from "./router/router-options.js";
|
|
125
|
+
export type {
|
|
126
|
+
RSCRouter,
|
|
127
|
+
RSCRouterInternal,
|
|
128
|
+
RouterRequestInput,
|
|
129
|
+
} from "./router/router-interfaces.js";
|
|
130
|
+
export { toInternal } from "./router/router-interfaces.js";
|
|
1079
131
|
|
|
1080
132
|
export function createRouter<TEnv = any>(
|
|
1081
133
|
options: RSCRouterOptions<TEnv> = {},
|
|
1082
134
|
): RSCRouter<TEnv, {}> {
|
|
1083
135
|
const {
|
|
1084
136
|
id: userProvidedId,
|
|
137
|
+
$$id: injectedId,
|
|
138
|
+
basename: basenameOption,
|
|
1085
139
|
debugPerformance = false,
|
|
1086
140
|
document: documentOption,
|
|
1087
141
|
defaultErrorBoundary,
|
|
@@ -1089,15 +143,84 @@ export function createRouter<TEnv = any>(
|
|
|
1089
143
|
notFound,
|
|
1090
144
|
onError,
|
|
1091
145
|
cache,
|
|
146
|
+
cacheProfiles: cacheProfilesOption,
|
|
1092
147
|
theme: themeOption,
|
|
1093
148
|
urls: urlsOption,
|
|
149
|
+
$$routeNames: staticRouteNames,
|
|
150
|
+
$$sourceFile: injectedSourceFile,
|
|
1094
151
|
nonce,
|
|
1095
152
|
version,
|
|
153
|
+
prefetchCacheTTL: prefetchCacheTTLOption,
|
|
1096
154
|
warmup: warmupOption,
|
|
1097
|
-
allowDebugManifest: allowDebugManifestOption =
|
|
155
|
+
allowDebugManifest: allowDebugManifestOption = false,
|
|
156
|
+
telemetry: telemetrySink,
|
|
157
|
+
ssr: ssrOption,
|
|
158
|
+
timeout: timeoutShorthand,
|
|
159
|
+
timeouts: timeoutsOption,
|
|
160
|
+
onTimeout,
|
|
161
|
+
originCheck: originCheckOption,
|
|
1098
162
|
} = options;
|
|
1099
163
|
|
|
1100
|
-
|
|
164
|
+
// Normalize basename: ensure leading slash, strip trailing slash.
|
|
165
|
+
// A bare "/" is equivalent to no basename.
|
|
166
|
+
const basename =
|
|
167
|
+
basenameOption && basenameOption.replace(/^\/+|\/+$/g, "")
|
|
168
|
+
? "/" + basenameOption.replace(/^\/+|\/+$/g, "")
|
|
169
|
+
: undefined;
|
|
170
|
+
|
|
171
|
+
// Resolve telemetry sink (no-op when not configured)
|
|
172
|
+
const telemetry = resolveSink(telemetrySink);
|
|
173
|
+
|
|
174
|
+
// Resolve cache profiles: merge user config with guaranteed default profile.
|
|
175
|
+
// This resolved map is both stored on the router (for per-request context)
|
|
176
|
+
// and written to the global registry (for DSL-time cache("profileName")).
|
|
177
|
+
const resolvedCacheProfiles = resolveCacheProfiles(cacheProfilesOption);
|
|
178
|
+
setCacheProfiles(resolvedCacheProfiles);
|
|
179
|
+
|
|
180
|
+
// Source file: prefer Vite-injected path (zero cost), fall back to
|
|
181
|
+
// stack trace parsing for non-Vite environments (e.g. tests).
|
|
182
|
+
let __sourceFile: string | undefined = injectedSourceFile;
|
|
183
|
+
if (!__sourceFile) {
|
|
184
|
+
try {
|
|
185
|
+
const stack = new Error().stack;
|
|
186
|
+
if (stack) {
|
|
187
|
+
const lines = stack.split("\n");
|
|
188
|
+
for (const line of lines) {
|
|
189
|
+
const match = line.match(/\((.+?\.(ts|tsx|js|jsx)):\d+:\d+\)/);
|
|
190
|
+
if (
|
|
191
|
+
match &&
|
|
192
|
+
!match[1].endsWith("/router.ts") &&
|
|
193
|
+
!match[1].includes("@rangojs/router") &&
|
|
194
|
+
!match[1].includes("node_modules")
|
|
195
|
+
) {
|
|
196
|
+
__sourceFile = match[1].startsWith("file:")
|
|
197
|
+
? match[1].slice(5)
|
|
198
|
+
: match[1];
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
} catch {}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Router ID priority: explicit id > Vite-injected $$id > counter fallback.
|
|
207
|
+
// $$id is a hash of filename+line injected by the Vite transform at compile
|
|
208
|
+
// time, so it's stable across build/runtime regardless of module evaluation
|
|
209
|
+
// order (unlike the counter which depends on import order).
|
|
210
|
+
const routerId =
|
|
211
|
+
userProvidedId ?? injectedId ?? `router_${nextRouterAutoId()}`;
|
|
212
|
+
|
|
213
|
+
// Resolve prefetch cache TTL (default: 300 seconds / 5 minutes)
|
|
214
|
+
// Clamp to a non-negative integer for valid Cache-Control max-age.
|
|
215
|
+
const rawTTL =
|
|
216
|
+
prefetchCacheTTLOption !== undefined ? prefetchCacheTTLOption : 300;
|
|
217
|
+
const prefetchCacheTTLSeconds =
|
|
218
|
+
rawTTL === false ? 0 : Math.max(0, Math.floor(rawTTL));
|
|
219
|
+
const prefetchCacheTTL = prefetchCacheTTLSeconds * 1000;
|
|
220
|
+
const prefetchCacheControl: string | false =
|
|
221
|
+
prefetchCacheTTLSeconds === 0
|
|
222
|
+
? false
|
|
223
|
+
: `private, max-age=${prefetchCacheTTLSeconds}`;
|
|
1101
224
|
|
|
1102
225
|
// Resolve warmup enabled flag (default: true)
|
|
1103
226
|
const warmupEnabled = warmupOption !== false;
|
|
@@ -1107,15 +230,29 @@ export function createRouter<TEnv = any>(
|
|
|
1107
230
|
? resolveThemeConfig(themeOption)
|
|
1108
231
|
: null;
|
|
1109
232
|
|
|
233
|
+
// Resolve timeout config (merge shorthand + structured)
|
|
234
|
+
const resolvedTimeouts = resolveTimeouts(timeoutShorthand, timeoutsOption);
|
|
235
|
+
|
|
1110
236
|
/**
|
|
1111
237
|
* Wrapper for invokeOnError that binds the router's onError callback.
|
|
1112
238
|
* Uses the shared utility from router/error-handling.ts for consistent behavior.
|
|
239
|
+
*
|
|
240
|
+
* Deduplicates via per-request WeakSet stored on the ALS request context.
|
|
241
|
+
* A closure-level WeakSet would silently swallow errors if the same object
|
|
242
|
+
* instance is thrown across separate requests (e.g. a singleton error).
|
|
1113
243
|
*/
|
|
1114
244
|
function callOnError(
|
|
1115
245
|
error: unknown,
|
|
1116
246
|
phase: ErrorPhase,
|
|
1117
247
|
context: Parameters<typeof invokeOnError<TEnv>>[3],
|
|
1118
248
|
): void {
|
|
249
|
+
if (error != null && typeof error === "object") {
|
|
250
|
+
const reportedErrors = _getRequestContext()?._reportedErrors;
|
|
251
|
+
if (reportedErrors) {
|
|
252
|
+
if (reportedErrors.has(error)) return;
|
|
253
|
+
reportedErrors.add(error);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
1119
256
|
invokeOnError(onError, error, phase, context, "Router");
|
|
1120
257
|
}
|
|
1121
258
|
|
|
@@ -1158,6 +295,18 @@ export function createRouter<TEnv = any>(
|
|
|
1158
295
|
handler = patternOrMiddleware;
|
|
1159
296
|
}
|
|
1160
297
|
|
|
298
|
+
// Prevent "use cache" functions from being used as middleware.
|
|
299
|
+
// They return data/JSX and do not call next() — silently accepting
|
|
300
|
+
// them would be a confusing no-op.
|
|
301
|
+
if (isCachedFunction(handler)) {
|
|
302
|
+
throw new Error(
|
|
303
|
+
`A "use cache" function cannot be used as middleware. ` +
|
|
304
|
+
`Cached functions return data and do not participate in the ` +
|
|
305
|
+
`middleware chain. Remove the "use cache" directive or use a ` +
|
|
306
|
+
`regular middleware function instead.`,
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
1161
310
|
// If mount-scoped, prepend mount prefix to pattern
|
|
1162
311
|
let fullPattern = pattern;
|
|
1163
312
|
if (mountPrefix && pattern) {
|
|
@@ -1187,20 +336,55 @@ export function createRouter<TEnv = any>(
|
|
|
1187
336
|
});
|
|
1188
337
|
}
|
|
1189
338
|
|
|
1190
|
-
// Track all registered routes with their prefixes for reverse()
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
339
|
+
// Track all registered routes with their prefixes for reverse().
|
|
340
|
+
// Seed from injected NamedRoutes so reverse() works at module load time
|
|
341
|
+
// for routes that come from lazy includes.
|
|
342
|
+
const mergedRouteMap: Record<string, string> =
|
|
343
|
+
flattenNamedRoutes(staticRouteNames);
|
|
344
|
+
|
|
345
|
+
// Track names that came from the static seed so we can silently overwrite
|
|
346
|
+
// them during routes() registration. The gen file may be stale during HMR,
|
|
347
|
+
// so conflicts between seeded and runtime-registered values are expected.
|
|
348
|
+
const seededNames = new Set(Object.keys(mergedRouteMap));
|
|
349
|
+
|
|
350
|
+
// Lazy precomputed entries lookup: rebuilt when per-router data arrives.
|
|
351
|
+
// In production multi-router setups, per-router data is loaded lazily via
|
|
352
|
+
// ensureRouterManifest(). At createRouter() time the data isn't available yet,
|
|
353
|
+
// so we defer building the Map until first use and invalidate when the
|
|
354
|
+
// per-router source changes.
|
|
355
|
+
let precomputedByPrefix: Map<string, Record<string, string>> | null = null;
|
|
356
|
+
let precomputedSource:
|
|
357
|
+
| Array<{ staticPrefix: string; routes: Record<string, string> }>
|
|
358
|
+
| null
|
|
359
|
+
| undefined;
|
|
360
|
+
|
|
361
|
+
function getPrecomputedByPrefix(): Map<
|
|
362
|
+
string,
|
|
363
|
+
Record<string, string>
|
|
364
|
+
> | null {
|
|
365
|
+
const current =
|
|
366
|
+
getRouterPrecomputedEntries(routerId) ?? getPrecomputedEntries();
|
|
367
|
+
if (current !== precomputedSource) {
|
|
368
|
+
precomputedSource = current;
|
|
369
|
+
precomputedByPrefix = current
|
|
370
|
+
? new Map(current.map((e) => [e.staticPrefix, e.routes]))
|
|
371
|
+
: null;
|
|
372
|
+
}
|
|
373
|
+
return precomputedByPrefix;
|
|
374
|
+
}
|
|
1201
375
|
|
|
1202
|
-
// Wrapper to pass debugPerformance to external createMetricsStore
|
|
1203
|
-
|
|
376
|
+
// Wrapper to pass debugPerformance to external createMetricsStore.
|
|
377
|
+
// Also checks per-request flag set by ctx.debugPerformance() in middleware.
|
|
378
|
+
const getMetricsStore = () => {
|
|
379
|
+
const reqCtx = _getRequestContext();
|
|
380
|
+
const enabled = debugPerformance || !!reqCtx?._debugPerformance;
|
|
381
|
+
if (!enabled) return undefined;
|
|
382
|
+
if (!reqCtx) {
|
|
383
|
+
return createMetricsStore(true);
|
|
384
|
+
}
|
|
385
|
+
reqCtx._metricsStore ??= createMetricsStore(true);
|
|
386
|
+
return reqCtx._metricsStore;
|
|
387
|
+
};
|
|
1204
388
|
|
|
1205
389
|
// Wrapper to pass defaults to error/notFound boundary finders
|
|
1206
390
|
const findNearestErrorBoundary = (entry: EntryData | null) =>
|
|
@@ -1211,17 +395,46 @@ export function createRouter<TEnv = any>(
|
|
|
1211
395
|
|
|
1212
396
|
// Helper to get handleStore from request context
|
|
1213
397
|
const getHandleStore = (): HandleStore | undefined => {
|
|
1214
|
-
return
|
|
398
|
+
return _getRequestContext()?._handleStore;
|
|
1215
399
|
};
|
|
1216
400
|
|
|
1217
|
-
// Track a pending handler promise (non-blocking)
|
|
1218
|
-
|
|
401
|
+
// Track a pending handler promise (non-blocking).
|
|
402
|
+
// Attaches a side-effect .catch() to report streaming handler errors to onError
|
|
403
|
+
// without altering the rejection chain (React's streaming error boundary still handles it).
|
|
404
|
+
const trackHandler = <T>(
|
|
405
|
+
promise: Promise<T>,
|
|
406
|
+
errorContext?: {
|
|
407
|
+
segmentId?: string;
|
|
408
|
+
segmentType?: string;
|
|
409
|
+
},
|
|
410
|
+
): Promise<T> => {
|
|
1219
411
|
const store = getHandleStore();
|
|
1220
|
-
|
|
412
|
+
const tracked = store ? store.track(promise) : promise;
|
|
413
|
+
|
|
414
|
+
// Report streaming handler errors to onError as a side-effect.
|
|
415
|
+
// The rejection still propagates to the RSC stream for client error boundaries.
|
|
416
|
+
// Captures request context eagerly (closure) so the catch handler has full context.
|
|
417
|
+
const reqCtx = _getRequestContext();
|
|
418
|
+
if (reqCtx && onError) {
|
|
419
|
+
tracked.catch((error) => {
|
|
420
|
+
callOnError(error, "handler", {
|
|
421
|
+
request: reqCtx.request,
|
|
422
|
+
url: reqCtx.url,
|
|
423
|
+
routeKey: reqCtx._routeName,
|
|
424
|
+
params: reqCtx.params as Record<string, string>,
|
|
425
|
+
env: reqCtx.env as TEnv,
|
|
426
|
+
segmentId: errorContext?.segmentId,
|
|
427
|
+
segmentType: errorContext?.segmentType as any,
|
|
428
|
+
handledByBoundary: true,
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return tracked;
|
|
1221
434
|
};
|
|
1222
435
|
|
|
1223
436
|
// Wrapper for wrapLoaderWithErrorHandling that uses router's error boundary finder
|
|
1224
|
-
// Includes onError callback for loader error notification
|
|
437
|
+
// Includes onError callback for loader error notification and telemetry emission.
|
|
1225
438
|
function wrapLoaderPromise<T>(
|
|
1226
439
|
promise: Promise<T>,
|
|
1227
440
|
entry: EntryData,
|
|
@@ -1237,7 +450,25 @@ export function createRouter<TEnv = any>(
|
|
|
1237
450
|
requestStartTime?: number;
|
|
1238
451
|
},
|
|
1239
452
|
): Promise<LoaderDataResult<T>> {
|
|
1240
|
-
|
|
453
|
+
const loaderStart = telemetrySink ? performance.now() : 0;
|
|
454
|
+
const loaderRequestId = telemetrySink
|
|
455
|
+
? errorContext?.request
|
|
456
|
+
? getRequestId(errorContext.request)
|
|
457
|
+
: undefined
|
|
458
|
+
: undefined;
|
|
459
|
+
if (telemetrySink) {
|
|
460
|
+
const loaderName = segmentId.split(".").pop() || "unknown";
|
|
461
|
+
safeEmit(telemetry, {
|
|
462
|
+
type: "loader.start",
|
|
463
|
+
timestamp: loaderStart,
|
|
464
|
+
requestId: loaderRequestId,
|
|
465
|
+
segmentId,
|
|
466
|
+
loaderName,
|
|
467
|
+
pathname,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const result = wrapLoaderWithErrorHandling(
|
|
1241
472
|
promise,
|
|
1242
473
|
entry,
|
|
1243
474
|
segmentId,
|
|
@@ -1260,9 +491,42 @@ export function createRouter<TEnv = any>(
|
|
|
1260
491
|
handledByBoundary: ctx.handledByBoundary,
|
|
1261
492
|
requestStartTime: errorContext.requestStartTime,
|
|
1262
493
|
});
|
|
494
|
+
if (telemetrySink) {
|
|
495
|
+
const errorObj =
|
|
496
|
+
error instanceof Error ? error : new Error(String(error));
|
|
497
|
+
safeEmit(telemetry, {
|
|
498
|
+
type: "loader.error",
|
|
499
|
+
timestamp: performance.now(),
|
|
500
|
+
requestId: loaderRequestId,
|
|
501
|
+
segmentId: ctx.segmentId,
|
|
502
|
+
loaderName: ctx.loaderName,
|
|
503
|
+
pathname,
|
|
504
|
+
error: errorObj,
|
|
505
|
+
handledByBoundary: ctx.handledByBoundary,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
1263
508
|
}
|
|
1264
509
|
: undefined,
|
|
1265
510
|
);
|
|
511
|
+
|
|
512
|
+
// Emit loader.end after the promise settles (fire-and-forget)
|
|
513
|
+
if (telemetrySink) {
|
|
514
|
+
const loaderName = segmentId.split(".").pop() || "unknown";
|
|
515
|
+
result.then((r) => {
|
|
516
|
+
safeEmit(telemetry, {
|
|
517
|
+
type: "loader.end",
|
|
518
|
+
timestamp: performance.now(),
|
|
519
|
+
requestId: loaderRequestId,
|
|
520
|
+
segmentId,
|
|
521
|
+
loaderName,
|
|
522
|
+
pathname,
|
|
523
|
+
durationMs: performance.now() - loaderStart,
|
|
524
|
+
ok: r.ok,
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return result;
|
|
1266
530
|
}
|
|
1267
531
|
|
|
1268
532
|
// Dependencies object for extracted segment resolution functions.
|
|
@@ -1272,6 +536,7 @@ export function createRouter<TEnv = any>(
|
|
|
1272
536
|
trackHandler,
|
|
1273
537
|
findNearestErrorBoundary,
|
|
1274
538
|
findNearestNotFoundBoundary,
|
|
539
|
+
notFoundComponent: notFound,
|
|
1275
540
|
callOnError,
|
|
1276
541
|
};
|
|
1277
542
|
|
|
@@ -1283,438 +548,46 @@ export function createRouter<TEnv = any>(
|
|
|
1283
548
|
findInterceptForRoute(routeKey, parentEntry, selectorContext, isAction),
|
|
1284
549
|
callOnError,
|
|
1285
550
|
findNearestErrorBoundary,
|
|
551
|
+
// Use per-router manifest when available, otherwise the static named map
|
|
552
|
+
// seeded into mergedRouteMap at router creation.
|
|
553
|
+
getRouteMap: () => getRouterManifest(routerId) ?? mergedRouteMap,
|
|
1286
554
|
};
|
|
1287
555
|
|
|
1288
|
-
//
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
)
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
function resolveLoadersOnlyWithRevalidation(
|
|
1310
|
-
entries: EntryData[],
|
|
1311
|
-
context: HandlerContext<any, TEnv>,
|
|
1312
|
-
clientSegmentIds: Set<string>,
|
|
1313
|
-
prevParams: Record<string, string>,
|
|
1314
|
-
request: Request,
|
|
1315
|
-
prevUrl: URL,
|
|
1316
|
-
nextUrl: URL,
|
|
1317
|
-
routeKey: string,
|
|
1318
|
-
actionContext?: { actionId?: string; actionUrl?: URL; actionResult?: any; formData?: FormData },
|
|
1319
|
-
) {
|
|
1320
|
-
return _resolveLoadersOnlyWithRevalidation(
|
|
1321
|
-
entries, context, clientSegmentIds, prevParams, request,
|
|
1322
|
-
prevUrl, nextUrl, routeKey, segmentDeps, actionContext,
|
|
1323
|
-
);
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
function buildEntryRevalidateMap(entries: EntryData[]) {
|
|
1327
|
-
return _buildEntryRevalidateMap(entries);
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
function resolveAllSegmentsWithRevalidation(
|
|
1331
|
-
entries: EntryData[],
|
|
1332
|
-
routeKey: string,
|
|
1333
|
-
params: Record<string, string>,
|
|
1334
|
-
context: HandlerContext<any, TEnv>,
|
|
1335
|
-
clientSegmentSet: Set<string>,
|
|
1336
|
-
prevParams: Record<string, string>,
|
|
1337
|
-
request: Request,
|
|
1338
|
-
prevUrl: URL,
|
|
1339
|
-
nextUrl: URL,
|
|
1340
|
-
loaderPromises: Map<string, Promise<any>>,
|
|
1341
|
-
actionContext: { actionId?: string; actionUrl?: URL; actionResult?: any; formData?: FormData } | undefined,
|
|
1342
|
-
interceptResult: { intercept: InterceptEntry; entry: EntryData } | null,
|
|
1343
|
-
localRouteName: string,
|
|
1344
|
-
pathname: string,
|
|
1345
|
-
) {
|
|
1346
|
-
return _resolveAllSegmentsWithRevalidation(
|
|
1347
|
-
entries, routeKey, params, context, clientSegmentSet, prevParams, request,
|
|
1348
|
-
prevUrl, nextUrl, loaderPromises, actionContext, interceptResult,
|
|
1349
|
-
localRouteName, pathname, segmentDeps,
|
|
1350
|
-
);
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
function findInterceptForRoute(
|
|
1354
|
-
targetRouteKey: string,
|
|
1355
|
-
fromEntry: EntryData | null,
|
|
1356
|
-
selectorContext: InterceptSelectorContext | null = null,
|
|
1357
|
-
isAction: boolean = false,
|
|
1358
|
-
) {
|
|
1359
|
-
return _findInterceptForRoute(targetRouteKey, fromEntry, selectorContext, isAction);
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
function resolveInterceptEntry(
|
|
1363
|
-
interceptEntry: InterceptEntry,
|
|
1364
|
-
parentEntry: EntryData,
|
|
1365
|
-
params: Record<string, string>,
|
|
1366
|
-
context: HandlerContext<any, TEnv>,
|
|
1367
|
-
belongsToRoute: boolean = true,
|
|
1368
|
-
revalidationContext?: any,
|
|
1369
|
-
) {
|
|
1370
|
-
return _resolveInterceptEntry(
|
|
1371
|
-
interceptEntry, parentEntry, params, context, belongsToRoute,
|
|
1372
|
-
segmentDeps, revalidationContext,
|
|
1373
|
-
);
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
function resolveInterceptLoadersOnly(
|
|
1377
|
-
interceptEntry: InterceptEntry,
|
|
1378
|
-
parentEntry: EntryData,
|
|
1379
|
-
params: Record<string, string>,
|
|
1380
|
-
context: HandlerContext<any, TEnv>,
|
|
1381
|
-
belongsToRoute: boolean = true,
|
|
1382
|
-
revalidationContext: any,
|
|
1383
|
-
) {
|
|
1384
|
-
return _resolveInterceptLoadersOnly(
|
|
1385
|
-
interceptEntry, parentEntry, params, context, belongsToRoute,
|
|
1386
|
-
segmentDeps, revalidationContext,
|
|
1387
|
-
);
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
// Detect lazy includes in handler result and create placeholder entries
|
|
1391
|
-
// Lazy includes are IncludeItem with lazy: true and _lazyContext
|
|
1392
|
-
// Moved to outer scope so it can be reused by evaluateLazyEntry for nested includes
|
|
1393
|
-
function findLazyIncludes(items: AllUseItems[]): Array<{
|
|
1394
|
-
prefix: string;
|
|
1395
|
-
patterns: UrlPatterns<TEnv>;
|
|
1396
|
-
context: {
|
|
1397
|
-
urlPrefix: string;
|
|
1398
|
-
namePrefix: string | undefined;
|
|
1399
|
-
parent: unknown;
|
|
1400
|
-
};
|
|
1401
|
-
}> {
|
|
1402
|
-
const lazyItems: Array<{
|
|
1403
|
-
prefix: string;
|
|
1404
|
-
patterns: UrlPatterns<TEnv>;
|
|
1405
|
-
context: {
|
|
1406
|
-
urlPrefix: string;
|
|
1407
|
-
namePrefix: string | undefined;
|
|
1408
|
-
parent: unknown;
|
|
1409
|
-
};
|
|
1410
|
-
}> = [];
|
|
1411
|
-
|
|
1412
|
-
for (const item of items) {
|
|
1413
|
-
if (!item) continue;
|
|
1414
|
-
if (item.type === "include") {
|
|
1415
|
-
const includeItem = item as IncludeItem;
|
|
1416
|
-
if (includeItem.lazy === true && includeItem._lazyContext) {
|
|
1417
|
-
lazyItems.push({
|
|
1418
|
-
prefix: includeItem.prefix,
|
|
1419
|
-
patterns: includeItem.patterns as UrlPatterns<TEnv>,
|
|
1420
|
-
context: includeItem._lazyContext,
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
// Recursively check nested items (in layouts, etc.)
|
|
1425
|
-
if ((item as any).uses && Array.isArray((item as any).uses)) {
|
|
1426
|
-
lazyItems.push(...findLazyIncludes((item as any).uses));
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
return lazyItems;
|
|
1431
|
-
}
|
|
556
|
+
// Create segment resolution wrappers bound to segmentDeps
|
|
557
|
+
const {
|
|
558
|
+
resolveAllSegments,
|
|
559
|
+
resolveLoadersOnly,
|
|
560
|
+
resolveLoadersOnlyWithRevalidation,
|
|
561
|
+
buildEntryRevalidateMap,
|
|
562
|
+
resolveAllSegmentsWithRevalidation,
|
|
563
|
+
findInterceptForRoute,
|
|
564
|
+
resolveInterceptEntry,
|
|
565
|
+
resolveInterceptLoadersOnly,
|
|
566
|
+
} = createSegmentWrappers<TEnv>(segmentDeps);
|
|
567
|
+
|
|
568
|
+
// Lazy evaluation deps — captures closure state for extracted evaluateLazyEntry
|
|
569
|
+
const lazyEvalDeps: LazyEvalDeps<TEnv> = {
|
|
570
|
+
routesEntries,
|
|
571
|
+
mergedRouteMap,
|
|
572
|
+
nextMountIndex: () => mountIndex++,
|
|
573
|
+
getPrecomputedByPrefix,
|
|
574
|
+
routerId,
|
|
575
|
+
};
|
|
1432
576
|
|
|
1433
|
-
/**
|
|
1434
|
-
* Evaluate a lazy entry's patterns and populate its routes
|
|
1435
|
-
* This runs the lazy patterns handler and updates the entry in-place
|
|
1436
|
-
* Also detects nested lazy includes and registers them as new entries
|
|
1437
|
-
*/
|
|
1438
577
|
function evaluateLazyEntry(entry: RouteEntry<TEnv>): void {
|
|
1439
|
-
|
|
1440
|
-
return;
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
// Check for pre-computed routes from build-time data.
|
|
1444
|
-
// Only leaf nodes (no nested includes) are precomputed, so entries with
|
|
1445
|
-
// nested lazy includes fall through to the handler below.
|
|
1446
|
-
if (precomputedByPrefix) {
|
|
1447
|
-
const routes = precomputedByPrefix.get(entry.staticPrefix);
|
|
1448
|
-
if (routes) {
|
|
1449
|
-
entry.lazyEvaluated = true;
|
|
1450
|
-
entry.routes = routes as ResolvedRouteMap<any>;
|
|
1451
|
-
for (const [name, pattern] of Object.entries(routes)) {
|
|
1452
|
-
mergedRouteMap[name] = pattern;
|
|
1453
|
-
}
|
|
1454
|
-
registerRouteMap(mergedRouteMap);
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
// Mark as evaluated immediately to prevent concurrent evaluation.
|
|
1460
|
-
// JS is single-threaded but handlers.handler() could theoretically yield,
|
|
1461
|
-
// and the while-loop in findMatch retries after evaluation.
|
|
1462
|
-
entry.lazyEvaluated = true;
|
|
1463
|
-
|
|
1464
|
-
const lazyPatterns = entry.lazyPatterns as UrlPatterns<TEnv>;
|
|
1465
|
-
const lazyContext = entry.lazyContext;
|
|
1466
|
-
|
|
1467
|
-
// Create a new context for evaluating the lazy patterns
|
|
1468
|
-
const manifest = new Map<string, EntryData>();
|
|
1469
|
-
const patterns = new Map<string, string>();
|
|
1470
|
-
const patternsByPrefix = new Map<string, Map<string, string>>();
|
|
1471
|
-
const trailingSlashMap = new Map<string, TrailingSlashMode>();
|
|
1472
|
-
|
|
1473
|
-
// Capture the handler result to detect nested lazy includes
|
|
1474
|
-
let handlerResult: AllUseItems[] = [];
|
|
1475
|
-
|
|
1476
|
-
RSCRouterContext.run(
|
|
1477
|
-
{
|
|
1478
|
-
manifest,
|
|
1479
|
-
patterns,
|
|
1480
|
-
patternsByPrefix,
|
|
1481
|
-
trailingSlash: trailingSlashMap,
|
|
1482
|
-
namespace: "lazy",
|
|
1483
|
-
parent: (lazyContext?.parent as EntryData | null) ?? null,
|
|
1484
|
-
counters: {},
|
|
1485
|
-
},
|
|
1486
|
-
() => {
|
|
1487
|
-
// Run the lazy patterns handler with the original context prefixes
|
|
1488
|
-
// The prefix comes from the IncludeItem stored in lazyPatterns
|
|
1489
|
-
const includePrefix = (entry as any)._lazyPrefix || "";
|
|
1490
|
-
const fullPrefix = (lazyContext?.urlPrefix || "") + includePrefix;
|
|
1491
|
-
|
|
1492
|
-
if (fullPrefix || lazyContext?.namePrefix) {
|
|
1493
|
-
runWithPrefixes(fullPrefix, lazyContext?.namePrefix, () => {
|
|
1494
|
-
handlerResult = lazyPatterns.handler() as AllUseItems[];
|
|
1495
|
-
});
|
|
1496
|
-
} else {
|
|
1497
|
-
handlerResult = lazyPatterns.handler() as AllUseItems[];
|
|
1498
|
-
}
|
|
1499
|
-
},
|
|
1500
|
-
);
|
|
1501
|
-
|
|
1502
|
-
// Populate the entry's routes from the patterns
|
|
1503
|
-
const routesObject: Record<string, string> = {};
|
|
1504
|
-
for (const [name, pattern] of patterns.entries()) {
|
|
1505
|
-
routesObject[name] = pattern;
|
|
1506
|
-
// Also add to merged route map for reverse() support
|
|
1507
|
-
const existingPattern = mergedRouteMap[name];
|
|
1508
|
-
if (existingPattern !== undefined && existingPattern !== pattern) {
|
|
1509
|
-
console.warn(
|
|
1510
|
-
`[@rangojs/router] Route name conflict: "${name}" already maps to "${existingPattern}", ` +
|
|
1511
|
-
`overwriting with "${pattern}" (from lazy include). Use unique route names to avoid this.`,
|
|
1512
|
-
);
|
|
1513
|
-
}
|
|
1514
|
-
mergedRouteMap[name] = pattern;
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
// Update the entry in-place
|
|
1518
|
-
entry.routes = routesObject as ResolvedRouteMap<any>;
|
|
1519
|
-
|
|
1520
|
-
// Note: Do NOT clear lazyPatterns/lazyContext here.
|
|
1521
|
-
// loadManifest() needs them on every request to re-run the handler
|
|
1522
|
-
// in the correct AsyncLocalStorage context (Store.manifest).
|
|
1523
|
-
|
|
1524
|
-
// Update trailing slash config if available
|
|
1525
|
-
if (trailingSlashMap.size > 0) {
|
|
1526
|
-
entry.trailingSlash = Object.fromEntries(trailingSlashMap);
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
// Detect nested lazy includes and register them as new entries
|
|
1530
|
-
const nestedLazyIncludes = findLazyIncludes(handlerResult);
|
|
1531
|
-
for (const lazyInclude of nestedLazyIncludes) {
|
|
1532
|
-
// Compute the full URL prefix (combining parent prefix if any)
|
|
1533
|
-
const fullPrefix = lazyInclude.context.urlPrefix
|
|
1534
|
-
? lazyInclude.context.urlPrefix + lazyInclude.prefix
|
|
1535
|
-
: lazyInclude.prefix;
|
|
1536
|
-
|
|
1537
|
-
const nestedEntry: RouteEntry<TEnv> & { _lazyPrefix?: string } = {
|
|
1538
|
-
prefix: "",
|
|
1539
|
-
staticPrefix: extractStaticPrefix(fullPrefix),
|
|
1540
|
-
routes: {} as ResolvedRouteMap<any>, // Empty until first match
|
|
1541
|
-
trailingSlash: entry.trailingSlash,
|
|
1542
|
-
handler: (lazyInclude.patterns as UrlPatterns<TEnv>).handler,
|
|
1543
|
-
mountIndex: entry.mountIndex,
|
|
1544
|
-
// Lazy evaluation fields
|
|
1545
|
-
lazy: true,
|
|
1546
|
-
lazyPatterns: lazyInclude.patterns,
|
|
1547
|
-
lazyContext: lazyInclude.context,
|
|
1548
|
-
lazyEvaluated: false,
|
|
1549
|
-
// Store the include prefix for evaluation
|
|
1550
|
-
_lazyPrefix: lazyInclude.prefix,
|
|
1551
|
-
};
|
|
1552
|
-
// Insert nested lazy entry before any entry whose staticPrefix is a
|
|
1553
|
-
// prefix of (but shorter than) this lazy entry's staticPrefix.
|
|
1554
|
-
// This ensures more specific lazy includes are matched before
|
|
1555
|
-
// less specific eager entries (e.g., "/href/nested" before "/href/:id").
|
|
1556
|
-
const nestedPrefix = nestedEntry.staticPrefix;
|
|
1557
|
-
let insertIndex = routesEntries.length;
|
|
1558
|
-
if (nestedPrefix) {
|
|
1559
|
-
for (let i = 0; i < routesEntries.length; i++) {
|
|
1560
|
-
const existing = routesEntries[i]!;
|
|
1561
|
-
if (
|
|
1562
|
-
nestedPrefix.startsWith(existing.staticPrefix) &&
|
|
1563
|
-
nestedPrefix.length > existing.staticPrefix.length
|
|
1564
|
-
) {
|
|
1565
|
-
insertIndex = i;
|
|
1566
|
-
break;
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
routesEntries.splice(insertIndex, 0, nestedEntry);
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
// Re-register route map for runtime reverse() usage
|
|
1574
|
-
registerRouteMap(mergedRouteMap);
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
// Single-entry cache for findMatch to avoid redundant matching within the same request.
|
|
1578
|
-
// previewMatch and match both call findMatch with the same pathname — this ensures
|
|
1579
|
-
// the route matching work (which may check thousands of routes) only happens once.
|
|
1580
|
-
let lastFindMatchPathname: string | null = null;
|
|
1581
|
-
let lastFindMatchResult: RouteMatchResult<TEnv> | null = null;
|
|
1582
|
-
|
|
1583
|
-
// Wrapper for findMatch that uses routesEntries
|
|
1584
|
-
// Handles lazy evaluation by evaluating lazy entries on first match.
|
|
1585
|
-
// Phase 1: try O(path_length) trie match.
|
|
1586
|
-
// Phase 2: fall back to regex iteration.
|
|
1587
|
-
function findMatch(
|
|
1588
|
-
pathname: string,
|
|
1589
|
-
ms?: MetricsStore,
|
|
1590
|
-
): RouteMatchResult<TEnv> | null {
|
|
1591
|
-
// Return cached result if same pathname (avoids double-match per request)
|
|
1592
|
-
if (lastFindMatchPathname === pathname) {
|
|
1593
|
-
return lastFindMatchResult;
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
// Helper to push sub-metrics
|
|
1597
|
-
const pushMetric = ms
|
|
1598
|
-
? (label: string, start: number) => {
|
|
1599
|
-
ms.metrics.push({
|
|
1600
|
-
label,
|
|
1601
|
-
duration: performance.now() - start,
|
|
1602
|
-
startTime: start - ms.requestStart,
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
: undefined;
|
|
1606
|
-
|
|
1607
|
-
// Phase 1: Try trie match (O(path_length))
|
|
1608
|
-
const routeTrie = getRouteTrie();
|
|
1609
|
-
if (routeTrie) {
|
|
1610
|
-
const trieStart = performance.now();
|
|
1611
|
-
const trieResult = tryTrieMatch(routeTrie, pathname);
|
|
1612
|
-
pushMetric?.("match:trie", trieStart);
|
|
1613
|
-
|
|
1614
|
-
if (trieResult) {
|
|
1615
|
-
// Find the RouteEntry that contains this route.
|
|
1616
|
-
// Multiple entries can share the same staticPrefix (e.g., several
|
|
1617
|
-
// include("/", patterns) calls all produce staticPrefix=""). Evaluate
|
|
1618
|
-
// each candidate and pick the one whose routes include the matched key.
|
|
1619
|
-
const entryStart = performance.now();
|
|
1620
|
-
let entry: RouteEntry<TEnv> | undefined;
|
|
1621
|
-
let fallbackEntry: RouteEntry<TEnv> | undefined;
|
|
1622
|
-
|
|
1623
|
-
for (const e of routesEntries) {
|
|
1624
|
-
if (e.staticPrefix !== trieResult.sp) continue;
|
|
1625
|
-
if (!fallbackEntry) fallbackEntry = e;
|
|
1626
|
-
evaluateLazyEntry(e);
|
|
1627
|
-
if (
|
|
1628
|
-
e.routes &&
|
|
1629
|
-
trieResult.routeKey in (e.routes as Record<string, unknown>)
|
|
1630
|
-
) {
|
|
1631
|
-
entry = e;
|
|
1632
|
-
break;
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
// If no entry had the route in its routes map, use the first matching
|
|
1637
|
-
// entry as fallback (handles main entry with inline routes not yet
|
|
1638
|
-
// reflected in its routes object).
|
|
1639
|
-
if (!entry) entry = fallbackEntry;
|
|
1640
|
-
|
|
1641
|
-
// If entry not found (nested include not yet discovered), evaluate parent
|
|
1642
|
-
if (!entry) {
|
|
1643
|
-
const parent = routesEntries.find(
|
|
1644
|
-
(e) =>
|
|
1645
|
-
trieResult.sp.startsWith(e.staticPrefix) &&
|
|
1646
|
-
e.staticPrefix !== trieResult.sp,
|
|
1647
|
-
);
|
|
1648
|
-
if (parent) {
|
|
1649
|
-
const lazyStart = performance.now();
|
|
1650
|
-
evaluateLazyEntry(parent);
|
|
1651
|
-
pushMetric?.("match:lazy-eval", lazyStart);
|
|
1652
|
-
}
|
|
1653
|
-
entry = routesEntries.find((e) => e.staticPrefix === trieResult.sp);
|
|
1654
|
-
}
|
|
1655
|
-
pushMetric?.("match:entry-resolve", entryStart);
|
|
1656
|
-
|
|
1657
|
-
if (entry) {
|
|
1658
|
-
lastFindMatchPathname = pathname;
|
|
1659
|
-
lastFindMatchResult = {
|
|
1660
|
-
entry,
|
|
1661
|
-
routeKey: trieResult.routeKey,
|
|
1662
|
-
params: trieResult.params,
|
|
1663
|
-
optionalParams: new Set(trieResult.optionalParams || []),
|
|
1664
|
-
redirectTo: trieResult.redirectTo,
|
|
1665
|
-
ancestry: trieResult.ancestry,
|
|
1666
|
-
...(trieResult.pr ? { pr: true } : {}),
|
|
1667
|
-
...(trieResult.pt ? { pt: true } : {}),
|
|
1668
|
-
...(trieResult.responseType ? { responseType: trieResult.responseType } : {}),
|
|
1669
|
-
...(trieResult.negotiateVariants ? { negotiateVariants: trieResult.negotiateVariants } : {}),
|
|
1670
|
-
...(trieResult.rscFirst ? { rscFirst: true } : {}),
|
|
1671
|
-
};
|
|
1672
|
-
return lastFindMatchResult;
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
// Phase 2: Fall back to existing matching (regex iteration)
|
|
1678
|
-
const regexStart = performance.now();
|
|
1679
|
-
let result = findRouteMatch(pathname, routesEntries);
|
|
1680
|
-
|
|
1681
|
-
// If we hit a lazy entry that needs evaluation, evaluate and retry.
|
|
1682
|
-
// Cap iterations to prevent infinite loops from pathological nesting.
|
|
1683
|
-
const MAX_LAZY_ITERATIONS = 100;
|
|
1684
|
-
let iterations = 0;
|
|
1685
|
-
while (isLazyEvaluationNeeded(result)) {
|
|
1686
|
-
if (++iterations > MAX_LAZY_ITERATIONS) {
|
|
1687
|
-
console.error(
|
|
1688
|
-
`[@rangojs/router] Exceeded ${MAX_LAZY_ITERATIONS} lazy evaluation iterations ` +
|
|
1689
|
-
`for pathname "${pathname}". This likely indicates circular lazy includes.`,
|
|
1690
|
-
);
|
|
1691
|
-
lastFindMatchPathname = pathname;
|
|
1692
|
-
lastFindMatchResult = null;
|
|
1693
|
-
return null;
|
|
1694
|
-
}
|
|
1695
|
-
evaluateLazyEntry(result.lazyEntry);
|
|
1696
|
-
result = findRouteMatch(pathname, routesEntries);
|
|
1697
|
-
}
|
|
1698
|
-
pushMetric?.("match:regex-fallback", regexStart);
|
|
1699
|
-
|
|
1700
|
-
lastFindMatchPathname = pathname;
|
|
1701
|
-
lastFindMatchResult = result;
|
|
1702
|
-
return result;
|
|
578
|
+
_evaluateLazyEntry(entry, lazyEvalDeps);
|
|
1703
579
|
}
|
|
1704
580
|
|
|
581
|
+
// Create findMatch with single-entry cache, bound to router state
|
|
582
|
+
const findMatch = createFindMatch<TEnv>({
|
|
583
|
+
routesEntries,
|
|
584
|
+
evaluateLazyEntry,
|
|
585
|
+
routerId,
|
|
586
|
+
});
|
|
1705
587
|
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
* Uses generator middleware pipeline for clean separation of concerns:
|
|
1710
|
-
* - cache-lookup: Check cache first
|
|
1711
|
-
* - segment-resolution: Resolve segments on cache miss
|
|
1712
|
-
* - cache-store: Store results in cache
|
|
1713
|
-
* - background-revalidation: SWR revalidation
|
|
1714
|
-
*/
|
|
1715
|
-
async function match(request: Request, env: TEnv): Promise<MatchResult> {
|
|
1716
|
-
// Build RouterContext with all closure functions needed by middleware
|
|
1717
|
-
const routerCtx: RouterContext<TEnv> = {
|
|
588
|
+
// Build a RouterContext once — shared by match, matchPartial, matchForPrerender
|
|
589
|
+
function buildRouterContext(): RouterContext<TEnv> {
|
|
590
|
+
return {
|
|
1718
591
|
findMatch,
|
|
1719
592
|
loadManifest,
|
|
1720
593
|
traverseBack,
|
|
@@ -1735,528 +608,301 @@ export function createRouter<TEnv = any>(
|
|
|
1735
608
|
resolveLoadersOnlyWithRevalidation,
|
|
1736
609
|
resolveInterceptLoadersOnly,
|
|
1737
610
|
resolveLoadersOnly,
|
|
611
|
+
telemetry: telemetrySink,
|
|
1738
612
|
};
|
|
1739
|
-
|
|
1740
|
-
return runWithRouterContext(routerCtx, async () => {
|
|
1741
|
-
const result = await createMatchContextForFull(request, env);
|
|
1742
|
-
|
|
1743
|
-
// Handle redirect case
|
|
1744
|
-
if ("type" in result && result.type === "redirect") {
|
|
1745
|
-
return {
|
|
1746
|
-
segments: [],
|
|
1747
|
-
matched: [],
|
|
1748
|
-
diff: [],
|
|
1749
|
-
params: {},
|
|
1750
|
-
redirect: result.redirectUrl,
|
|
1751
|
-
};
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
const ctx = result as MatchContext<TEnv>;
|
|
1755
|
-
|
|
1756
|
-
try {
|
|
1757
|
-
const state = createPipelineState();
|
|
1758
|
-
const pipeline = createMatchPartialPipeline(ctx, state);
|
|
1759
|
-
return await collectMatchResult(pipeline, ctx, state);
|
|
1760
|
-
} catch (error) {
|
|
1761
|
-
if (error instanceof Response) throw error;
|
|
1762
|
-
// Report unhandled errors during full match pipeline
|
|
1763
|
-
callOnError(error, "routing", {
|
|
1764
|
-
request,
|
|
1765
|
-
url: ctx.url,
|
|
1766
|
-
env,
|
|
1767
|
-
isPartial: false,
|
|
1768
|
-
handledByBoundary: false,
|
|
1769
|
-
});
|
|
1770
|
-
throw sanitizeError(error);
|
|
1771
|
-
}
|
|
1772
|
-
});
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
async function matchError(
|
|
1776
|
-
request: Request,
|
|
1777
|
-
_context: TEnv,
|
|
1778
|
-
error: unknown,
|
|
1779
|
-
segmentType: ErrorInfo["segmentType"] = "route",
|
|
1780
|
-
): Promise<MatchResult | null> {
|
|
1781
|
-
return _matchError(request, _context, error, matchApiDeps, defaultErrorBoundary, segmentType);
|
|
1782
613
|
}
|
|
1783
614
|
|
|
615
|
+
// Prerender/static match deps (bind closure state for extracted functions)
|
|
616
|
+
const prerenderDeps = {
|
|
617
|
+
findMatch,
|
|
618
|
+
buildRouterContext,
|
|
619
|
+
mergedRouteMap,
|
|
620
|
+
resolveAllSegments,
|
|
621
|
+
};
|
|
1784
622
|
|
|
1785
|
-
async function
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
async function createMatchContextForPartial(
|
|
1793
|
-
request: Request,
|
|
1794
|
-
env: TEnv,
|
|
1795
|
-
actionContext?: { actionId?: string; actionUrl?: URL; actionResult?: any; formData?: FormData },
|
|
623
|
+
async function matchForPrerender(
|
|
624
|
+
pathname: string,
|
|
625
|
+
params: Record<string, string>,
|
|
626
|
+
buildVars?: Record<string, any>,
|
|
627
|
+
isPassthroughRoute?: boolean,
|
|
628
|
+
buildEnv?: TEnv,
|
|
629
|
+
devMode?: boolean,
|
|
1796
630
|
) {
|
|
1797
|
-
return
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
/**
|
|
1801
|
-
* Match partial request with revalidation
|
|
1802
|
-
*
|
|
1803
|
-
* Uses generator middleware pipeline for clean separation of concerns:
|
|
1804
|
-
* - cache-lookup: Check cache first
|
|
1805
|
-
* - segment-resolution: Resolve segments on cache miss
|
|
1806
|
-
* - intercept-resolution: Handle intercept routes
|
|
1807
|
-
* - cache-store: Store results in cache
|
|
1808
|
-
* - background-revalidation: SWR revalidation
|
|
1809
|
-
*/
|
|
1810
|
-
async function matchPartial(
|
|
1811
|
-
request: Request,
|
|
1812
|
-
context: TEnv,
|
|
1813
|
-
actionContext?: ActionContext,
|
|
1814
|
-
): Promise<MatchResult | null> {
|
|
1815
|
-
// Build RouterContext with all closure functions needed by middleware
|
|
1816
|
-
const routerCtx: RouterContext<TEnv> = {
|
|
1817
|
-
findMatch,
|
|
1818
|
-
loadManifest,
|
|
1819
|
-
traverseBack,
|
|
1820
|
-
createHandlerContext,
|
|
1821
|
-
setupLoaderAccess,
|
|
1822
|
-
setupLoaderAccessSilent,
|
|
1823
|
-
getContext,
|
|
1824
|
-
getMetricsStore,
|
|
1825
|
-
createCacheScope,
|
|
1826
|
-
findInterceptForRoute,
|
|
1827
|
-
resolveAllSegmentsWithRevalidation,
|
|
1828
|
-
resolveInterceptEntry,
|
|
1829
|
-
evaluateRevalidation,
|
|
1830
|
-
getRequestContext,
|
|
1831
|
-
resolveAllSegments,
|
|
1832
|
-
createHandleStore,
|
|
1833
|
-
buildEntryRevalidateMap,
|
|
1834
|
-
resolveLoadersOnlyWithRevalidation,
|
|
1835
|
-
resolveInterceptLoadersOnly,
|
|
1836
|
-
};
|
|
1837
|
-
|
|
1838
|
-
return runWithRouterContext(routerCtx, async () => {
|
|
1839
|
-
const ctx = await createMatchContextForPartial(
|
|
1840
|
-
request,
|
|
1841
|
-
context,
|
|
1842
|
-
actionContext,
|
|
1843
|
-
);
|
|
1844
|
-
if (!ctx) return null;
|
|
1845
|
-
|
|
1846
|
-
try {
|
|
1847
|
-
const state = createPipelineState();
|
|
1848
|
-
const pipeline = createMatchPartialPipeline(ctx, state);
|
|
1849
|
-
return await collectMatchResult(pipeline, ctx, state);
|
|
1850
|
-
} catch (error) {
|
|
1851
|
-
if (error instanceof Response) throw error;
|
|
1852
|
-
// Report unhandled errors during partial match pipeline
|
|
1853
|
-
callOnError(error, actionContext ? "action" : "revalidation", {
|
|
1854
|
-
request,
|
|
1855
|
-
url: ctx.url,
|
|
1856
|
-
env: context,
|
|
1857
|
-
actionId: actionContext?.actionId,
|
|
1858
|
-
isPartial: true,
|
|
1859
|
-
handledByBoundary: false,
|
|
1860
|
-
});
|
|
1861
|
-
throw sanitizeError(error);
|
|
1862
|
-
}
|
|
1863
|
-
});
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
|
-
/**
|
|
1867
|
-
* Preview match - returns route middleware without segment resolution.
|
|
1868
|
-
* Also returns responseType and handler for response routes (non-RSC short-circuit).
|
|
1869
|
-
*/
|
|
1870
|
-
async function previewMatch(
|
|
1871
|
-
request: Request,
|
|
1872
|
-
_context: TEnv,
|
|
1873
|
-
): Promise<{
|
|
1874
|
-
routeMiddleware?: Array<{
|
|
1875
|
-
handler: import("./router/middleware.js").MiddlewareFn;
|
|
1876
|
-
params: Record<string, string>;
|
|
1877
|
-
}>;
|
|
1878
|
-
responseType?: string;
|
|
1879
|
-
handler?: Function;
|
|
1880
|
-
params?: Record<string, string>;
|
|
1881
|
-
negotiated?: boolean;
|
|
1882
|
-
} | null> {
|
|
1883
|
-
const url = new URL(request.url);
|
|
1884
|
-
const pathname = url.pathname;
|
|
1885
|
-
|
|
1886
|
-
// Quick route matching
|
|
1887
|
-
const matched = findMatch(pathname);
|
|
1888
|
-
if (!matched) {
|
|
1889
|
-
return null;
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
// Skip redirect check - will be handled in full match
|
|
1893
|
-
if (matched.redirectTo) {
|
|
1894
|
-
return { routeMiddleware: undefined };
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
// Load manifest (without segment resolution)
|
|
1898
|
-
const manifestEntry = await loadManifest(
|
|
1899
|
-
matched.entry,
|
|
1900
|
-
matched.routeKey,
|
|
631
|
+
return _matchForPrerender(
|
|
1901
632
|
pathname,
|
|
1902
|
-
|
|
1903
|
-
|
|
633
|
+
params,
|
|
634
|
+
prerenderDeps,
|
|
635
|
+
buildVars,
|
|
636
|
+
isPassthroughRoute,
|
|
637
|
+
buildEnv,
|
|
638
|
+
devMode,
|
|
1904
639
|
);
|
|
640
|
+
}
|
|
1905
641
|
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
642
|
+
async function renderStaticSegment(
|
|
643
|
+
handler: Function,
|
|
644
|
+
handlerId: string,
|
|
645
|
+
routeName?: string,
|
|
646
|
+
buildEnv?: TEnv,
|
|
647
|
+
devMode?: boolean,
|
|
648
|
+
) {
|
|
649
|
+
return _renderStaticSegment<TEnv>(
|
|
650
|
+
handler,
|
|
651
|
+
handlerId,
|
|
652
|
+
mergedRouteMap,
|
|
653
|
+
routeName,
|
|
654
|
+
buildEnv,
|
|
655
|
+
devMode,
|
|
1911
656
|
);
|
|
1912
|
-
|
|
1913
|
-
// Check for response type (from trie match or manifest entry)
|
|
1914
|
-
const responseType = matched.responseType ||
|
|
1915
|
-
(manifestEntry.type === "route" ? manifestEntry.responseType : undefined);
|
|
1916
|
-
|
|
1917
|
-
// Content negotiation: when negotiate variants exist, pick the best
|
|
1918
|
-
// handler based on the Accept header. Uses q-values and client order
|
|
1919
|
-
// as tiebreaker (matching Express/Hono behavior). RSC routes participate
|
|
1920
|
-
// as text/html candidates so browsers naturally get HTML without
|
|
1921
|
-
// special-casing.
|
|
1922
|
-
if (matched.negotiateVariants && matched.negotiateVariants.length > 0) {
|
|
1923
|
-
const acceptEntries = parseAcceptTypes(request.headers.get("accept") || "");
|
|
1924
|
-
|
|
1925
|
-
// Build candidate list preserving definition order.
|
|
1926
|
-
// For wildcard (*/*) and no-Accept fallback, the first candidate wins.
|
|
1927
|
-
const variants = matched.negotiateVariants;
|
|
1928
|
-
let candidates: Array<{ routeKey: string; responseType: string }>;
|
|
1929
|
-
if (responseType) {
|
|
1930
|
-
// Primary is response-type — include it as a candidate
|
|
1931
|
-
candidates = [...variants, { routeKey: matched.routeKey, responseType }];
|
|
1932
|
-
} else {
|
|
1933
|
-
// Primary is RSC — insert as text/html candidate in definition order
|
|
1934
|
-
const rscCandidate = { routeKey: matched.routeKey, responseType: RSC_RESPONSE_TYPE };
|
|
1935
|
-
candidates = matched.rscFirst
|
|
1936
|
-
? [rscCandidate, ...variants]
|
|
1937
|
-
: [...variants, rscCandidate];
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
const variant = pickNegotiateVariant(acceptEntries, candidates);
|
|
1941
|
-
|
|
1942
|
-
// If the winner is RSC, fall through to default RSC handling
|
|
1943
|
-
if (variant.responseType === RSC_RESPONSE_TYPE) {
|
|
1944
|
-
// Fall through — RSC won negotiation
|
|
1945
|
-
} else if (responseType && variant.routeKey === matched.routeKey) {
|
|
1946
|
-
// Fall through — response-type primary won, already set
|
|
1947
|
-
} else {
|
|
1948
|
-
const negotiateEntry = await loadManifest(
|
|
1949
|
-
matched.entry,
|
|
1950
|
-
variant.routeKey,
|
|
1951
|
-
pathname,
|
|
1952
|
-
undefined,
|
|
1953
|
-
false,
|
|
1954
|
-
);
|
|
1955
|
-
return {
|
|
1956
|
-
routeMiddleware: routeMiddleware.length > 0 ? routeMiddleware : undefined,
|
|
1957
|
-
responseType: variant.responseType,
|
|
1958
|
-
handler: negotiateEntry.type === "route" ? negotiateEntry.handler : undefined,
|
|
1959
|
-
params: matched.params,
|
|
1960
|
-
negotiated: true,
|
|
1961
|
-
};
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
// If we passed through the negotiation block (variants exist), mark as
|
|
1966
|
-
// negotiated so the handler sets Vary: Accept on the response.
|
|
1967
|
-
const hasVariants = matched.negotiateVariants && matched.negotiateVariants.length > 0;
|
|
1968
|
-
return {
|
|
1969
|
-
routeMiddleware: routeMiddleware.length > 0 ? routeMiddleware : undefined,
|
|
1970
|
-
...(responseType ? {
|
|
1971
|
-
responseType,
|
|
1972
|
-
handler: manifestEntry.type === "route" ? manifestEntry.handler : undefined,
|
|
1973
|
-
params: matched.params,
|
|
1974
|
-
} : {}),
|
|
1975
|
-
...(hasVariants ? { negotiated: true } : {}),
|
|
1976
|
-
};
|
|
1977
657
|
}
|
|
1978
658
|
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
// Merge routes into the reverse map
|
|
1990
|
-
// Keys stay unchanged for composability - only URL patterns get prefixed
|
|
1991
|
-
const routeEntries = routes as Record<string, string>;
|
|
1992
|
-
for (const [key, pattern] of Object.entries(routeEntries)) {
|
|
1993
|
-
// Build prefixed pattern: "/shop" + "/cart" -> "/shop/cart"
|
|
1994
|
-
const prefixedPattern =
|
|
1995
|
-
prefix && pattern !== "/"
|
|
1996
|
-
? `${prefix}${pattern}`
|
|
1997
|
-
: prefix && pattern === "/"
|
|
1998
|
-
? prefix
|
|
1999
|
-
: pattern;
|
|
2000
|
-
|
|
2001
|
-
// Runtime validation: warn if key already exists with different pattern
|
|
2002
|
-
const existingPattern = mergedRouteMap[key];
|
|
2003
|
-
if (
|
|
2004
|
-
existingPattern !== undefined &&
|
|
2005
|
-
existingPattern !== prefixedPattern
|
|
2006
|
-
) {
|
|
2007
|
-
console.warn(
|
|
2008
|
-
`[rsc-router] Route key conflict: "${key}" already maps to "${existingPattern}", ` +
|
|
2009
|
-
`overwriting with "${prefixedPattern}". Use unique key names to avoid this.`,
|
|
2010
|
-
);
|
|
2011
|
-
}
|
|
2012
|
-
|
|
2013
|
-
// Use original key - enables reusable route modules
|
|
2014
|
-
mergedRouteMap[key] = prefixedPattern;
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
|
-
// Auto-register route map for runtime reverse() usage
|
|
2018
|
-
registerRouteMap(mergedRouteMap);
|
|
2019
|
-
|
|
2020
|
-
// Extract trailing slash config if present (attached by route())
|
|
2021
|
-
const trailingSlashConfig = (routes as any).__trailingSlash as
|
|
2022
|
-
| Record<string, TrailingSlashMode>
|
|
2023
|
-
| undefined;
|
|
2024
|
-
|
|
2025
|
-
// Create builder object so .use() can return it
|
|
2026
|
-
const builder: RouteBuilder<RouteDefinition, TEnv, any, TNewRoutes> = {
|
|
2027
|
-
use(
|
|
2028
|
-
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
2029
|
-
middleware?: MiddlewareFn<TEnv>,
|
|
2030
|
-
) {
|
|
2031
|
-
// Mount-scoped middleware - prefix is the mount prefix
|
|
2032
|
-
addMiddleware(patternOrMiddleware, middleware, prefix || null);
|
|
2033
|
-
return builder;
|
|
2034
|
-
},
|
|
2035
|
-
|
|
2036
|
-
map(
|
|
2037
|
-
handler:
|
|
2038
|
-
| ((
|
|
2039
|
-
helpers: InlineRouteHelpers<TNewRoutes, TEnv>,
|
|
2040
|
-
) => Array<AllUseItems>)
|
|
2041
|
-
| (() =>
|
|
2042
|
-
| Array<AllUseItems>
|
|
2043
|
-
| Promise<{ default: () => Array<AllUseItems> }>
|
|
2044
|
-
| Promise<() => Array<AllUseItems>>),
|
|
2045
|
-
) {
|
|
2046
|
-
// Store handler as-is - detection happens at call time based on return type
|
|
2047
|
-
// Both patterns use the same signature:
|
|
2048
|
-
// - Inline: ({ route }) => [...] - receives helpers, returns Array
|
|
2049
|
-
// - Lazy: () => import(...) - ignores helpers, returns Promise
|
|
2050
|
-
routesEntries.push({
|
|
2051
|
-
prefix,
|
|
2052
|
-
staticPrefix: extractStaticPrefix(prefix),
|
|
2053
|
-
routes: routes as ResolvedRouteMap<any>,
|
|
2054
|
-
trailingSlash: trailingSlashConfig,
|
|
2055
|
-
handler: handler as any,
|
|
2056
|
-
mountIndex: currentMountIndex,
|
|
2057
|
-
});
|
|
2058
|
-
// Return router with accumulated types
|
|
2059
|
-
// At runtime this is the same object, but TypeScript tracks the accumulated route types
|
|
2060
|
-
return router as any;
|
|
2061
|
-
},
|
|
2062
|
-
|
|
2063
|
-
// Expose accumulated route map for typeof extraction
|
|
2064
|
-
get routeMap() {
|
|
2065
|
-
return mergedRouteMap as TNewRoutes;
|
|
2066
|
-
},
|
|
2067
|
-
};
|
|
659
|
+
// Create match handler functions bound to router state
|
|
660
|
+
const matchHandlers = createMatchHandlers<TEnv>({
|
|
661
|
+
buildRouterContext,
|
|
662
|
+
callOnError,
|
|
663
|
+
matchApiDeps,
|
|
664
|
+
defaultErrorBoundary,
|
|
665
|
+
findMatch,
|
|
666
|
+
findInterceptForRoute,
|
|
667
|
+
telemetry: telemetrySink,
|
|
668
|
+
});
|
|
2068
669
|
|
|
2069
|
-
|
|
2070
|
-
}
|
|
670
|
+
const { match, matchPartial, matchError, previewMatch } = matchHandlers;
|
|
2071
671
|
|
|
2072
672
|
/**
|
|
2073
673
|
* Router instance
|
|
2074
674
|
* The type system tracks accumulated routes through the builder chain
|
|
2075
675
|
* Initial TRoutes is {} (empty) to avoid poisoning accumulated types with Record<string, string>
|
|
2076
676
|
*/
|
|
2077
|
-
const router:
|
|
677
|
+
const router: RSCRouterInternal<TEnv, {}> = {
|
|
2078
678
|
__brand: RSC_ROUTER_BRAND,
|
|
2079
679
|
id: routerId,
|
|
680
|
+
basename,
|
|
2080
681
|
|
|
2081
|
-
routes(
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
// Check if argument is UrlPatterns (new Django-style API)
|
|
2089
|
-
// Detect by checking for handler and definitions properties
|
|
2090
|
-
if (
|
|
2091
|
-
typeof prefixOrRoutes === "object" &&
|
|
2092
|
-
prefixOrRoutes !== null &&
|
|
2093
|
-
"handler" in prefixOrRoutes &&
|
|
2094
|
-
"definitions" in prefixOrRoutes &&
|
|
2095
|
-
typeof (prefixOrRoutes as UrlPatterns<TEnv>).handler === "function"
|
|
2096
|
-
) {
|
|
2097
|
-
const urlPatterns = prefixOrRoutes as UrlPatterns<TEnv>;
|
|
2098
|
-
// Store reference for runtime manifest generation
|
|
2099
|
-
storedUrlPatterns = urlPatterns;
|
|
2100
|
-
const currentMountIndex = mountIndex++;
|
|
2101
|
-
|
|
2102
|
-
// Create manifest and patterns maps for route registration
|
|
2103
|
-
const manifest = new Map<string, EntryData>();
|
|
2104
|
-
const patterns = new Map<string, string>();
|
|
2105
|
-
const patternsByPrefix = new Map<string, Map<string, string>>();
|
|
2106
|
-
const trailingSlashMap = new Map<string, TrailingSlashMode>();
|
|
2107
|
-
|
|
2108
|
-
// Run the handler once to extract patterns for route matching
|
|
2109
|
-
// Note: loadManifest will re-run the handler to register entries in its context
|
|
2110
|
-
// Lazy includes are detected in the return value and handled separately
|
|
2111
|
-
let handlerResult: AllUseItems[] = [];
|
|
2112
|
-
RSCRouterContext.run(
|
|
2113
|
-
{
|
|
2114
|
-
manifest,
|
|
2115
|
-
patterns,
|
|
2116
|
-
patternsByPrefix,
|
|
2117
|
-
trailingSlash: trailingSlashMap,
|
|
2118
|
-
namespace: "root",
|
|
2119
|
-
parent: null,
|
|
2120
|
-
counters: {},
|
|
2121
|
-
},
|
|
2122
|
-
() => {
|
|
2123
|
-
// Execute the handler to collect patterns
|
|
2124
|
-
handlerResult = urlPatterns.handler() as AllUseItems[];
|
|
2125
|
-
},
|
|
2126
|
-
);
|
|
682
|
+
routes(patternsOrBuilder: UrlPatterns<TEnv> | UrlBuilder<TEnv>): any {
|
|
683
|
+
// Wrap builder functions in urls() automatically
|
|
684
|
+
const urlPatterns: UrlPatterns<TEnv> =
|
|
685
|
+
typeof patternsOrBuilder === "function"
|
|
686
|
+
? (urls(patternsOrBuilder) as UrlPatterns<TEnv>)
|
|
687
|
+
: patternsOrBuilder;
|
|
2127
688
|
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
trailingSlashMap.size > 0
|
|
2132
|
-
? Object.fromEntries(trailingSlashMap)
|
|
2133
|
-
: undefined;
|
|
2134
|
-
|
|
2135
|
-
// Create separate RouteEntry for each URL prefix group
|
|
2136
|
-
// This enables prefix-based short-circuit optimization
|
|
2137
|
-
if (patternsByPrefix.size > 0) {
|
|
2138
|
-
for (const [prefix, prefixPatterns] of patternsByPrefix.entries()) {
|
|
2139
|
-
const routesObject: Record<string, string> = {};
|
|
2140
|
-
for (const [name, pattern] of prefixPatterns.entries()) {
|
|
2141
|
-
routesObject[name] = pattern;
|
|
2142
|
-
}
|
|
689
|
+
// Store reference for runtime manifest generation
|
|
690
|
+
storedUrlPatterns = urlPatterns;
|
|
691
|
+
const currentMountIndex = mountIndex++;
|
|
2143
692
|
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
693
|
+
// Create manifest and patterns maps for route registration
|
|
694
|
+
const manifest = new Map<string, EntryData>();
|
|
695
|
+
const routePatterns = new Map<string, string>();
|
|
696
|
+
const patternsByPrefix = new Map<string, Map<string, string>>();
|
|
697
|
+
const trailingSlashMap = new Map<string, TrailingSlashMode>();
|
|
698
|
+
|
|
699
|
+
// Run the handler once to extract patterns for route matching.
|
|
700
|
+
// Note: loadManifest will re-run the handler to register entries in its context.
|
|
701
|
+
// Lazy includes are detected in the return value and handled separately.
|
|
702
|
+
//
|
|
703
|
+
// Pattern extraction must use the same mountIndex and MapRootLayout root
|
|
704
|
+
// parent as loadManifest so that shortCodes produced here match those at
|
|
705
|
+
// runtime. include() captures the current parent and counters; if those
|
|
706
|
+
// shortCodes diverge from the runtime tree the segment reconciliation on
|
|
707
|
+
// the client will see a full mismatch and remount the entire page.
|
|
708
|
+
const syntheticMapRoot: EntryData = {
|
|
709
|
+
type: "layout",
|
|
710
|
+
id: `#synthetic-maproot-M${currentMountIndex}`,
|
|
711
|
+
shortCode: `M${currentMountIndex}L0`,
|
|
712
|
+
parent: null,
|
|
713
|
+
handler: MapRootLayout,
|
|
714
|
+
middleware: [],
|
|
715
|
+
revalidate: [],
|
|
716
|
+
errorBoundary: [],
|
|
717
|
+
notFoundBoundary: [],
|
|
718
|
+
layout: [],
|
|
719
|
+
parallel: {},
|
|
720
|
+
intercept: [],
|
|
721
|
+
loader: [],
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
let handlerResult: AllUseItems[] = [];
|
|
725
|
+
RSCRouterContext.run(
|
|
726
|
+
{
|
|
727
|
+
manifest,
|
|
728
|
+
patterns: routePatterns,
|
|
729
|
+
patternsByPrefix,
|
|
730
|
+
trailingSlash: trailingSlashMap,
|
|
731
|
+
namespace: "root",
|
|
732
|
+
parent: syntheticMapRoot,
|
|
733
|
+
counters: {},
|
|
734
|
+
mountIndex: currentMountIndex,
|
|
735
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
736
|
+
// basename sets the initial URL prefix so all path() patterns
|
|
737
|
+
// are registered with the prefix (e.g. "/admin" + "/users" = "/admin/users").
|
|
738
|
+
// No namePrefix — route names stay unprefixed.
|
|
739
|
+
...(basename ? { urlPrefix: basename } : {}),
|
|
740
|
+
},
|
|
741
|
+
() => {
|
|
742
|
+
handlerResult = urlPatterns.handler() as AllUseItems[];
|
|
743
|
+
},
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
// Convert trailingSlash map to object for the router
|
|
747
|
+
const trailingSlashConfig =
|
|
748
|
+
trailingSlashMap.size > 0
|
|
749
|
+
? Object.fromEntries(trailingSlashMap)
|
|
750
|
+
: undefined;
|
|
751
|
+
|
|
752
|
+
// Collect route keys that have prerender handlers (for non-trie match path)
|
|
753
|
+
let prerenderRouteKeys: Set<string> | undefined;
|
|
754
|
+
let passthroughRouteKeys: Set<string> | undefined;
|
|
755
|
+
for (const [name, entry] of manifest.entries()) {
|
|
756
|
+
if (entry.type === "route" && entry.isPrerender) {
|
|
757
|
+
if (!prerenderRouteKeys) prerenderRouteKeys = new Set();
|
|
758
|
+
prerenderRouteKeys.add(name);
|
|
759
|
+
if (entry.isPassthrough === true) {
|
|
760
|
+
if (!passthroughRouteKeys) passthroughRouteKeys = new Set();
|
|
761
|
+
passthroughRouteKeys.add(name);
|
|
2155
762
|
}
|
|
2156
|
-
}
|
|
2157
|
-
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// Create separate RouteEntry for each URL prefix group
|
|
767
|
+
// This enables prefix-based short-circuit optimization
|
|
768
|
+
if (patternsByPrefix.size > 0) {
|
|
769
|
+
for (const [prefix, prefixPatterns] of patternsByPrefix.entries()) {
|
|
2158
770
|
const routesObject: Record<string, string> = {};
|
|
2159
|
-
for (const [name, pattern] of
|
|
771
|
+
for (const [name, pattern] of prefixPatterns.entries()) {
|
|
2160
772
|
routesObject[name] = pattern;
|
|
2161
773
|
}
|
|
2162
774
|
|
|
2163
775
|
routesEntries.push({
|
|
776
|
+
// prefix is "" because patterns already include the URL prefix
|
|
777
|
+
// (e.g., "/site/:locale/user1/:id" not just "/user1/:id")
|
|
2164
778
|
prefix: "",
|
|
2165
|
-
staticPrefix
|
|
779
|
+
// staticPrefix is the actual prefix for short-circuit optimization
|
|
780
|
+
staticPrefix: extractStaticPrefix(prefix),
|
|
2166
781
|
routes: routesObject as ResolvedRouteMap<any>,
|
|
2167
782
|
trailingSlash: trailingSlashConfig,
|
|
2168
783
|
handler: urlPatterns.handler,
|
|
2169
784
|
mountIndex: currentMountIndex,
|
|
785
|
+
routerId,
|
|
786
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
787
|
+
...(prerenderRouteKeys ? { prerenderRouteKeys } : {}),
|
|
788
|
+
...(passthroughRouteKeys ? { passthroughRouteKeys } : {}),
|
|
2170
789
|
});
|
|
2171
790
|
}
|
|
791
|
+
} else {
|
|
792
|
+
// Fallback: no prefix grouping, use flat patterns map
|
|
793
|
+
const routesObject: Record<string, string> = {};
|
|
794
|
+
for (const [name, pattern] of routePatterns.entries()) {
|
|
795
|
+
routesObject[name] = pattern;
|
|
796
|
+
}
|
|
2172
797
|
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
}
|
|
2183
|
-
|
|
798
|
+
routesEntries.push({
|
|
799
|
+
prefix: "",
|
|
800
|
+
staticPrefix: "",
|
|
801
|
+
routes: routesObject as ResolvedRouteMap<any>,
|
|
802
|
+
trailingSlash: trailingSlashConfig,
|
|
803
|
+
handler: urlPatterns.handler,
|
|
804
|
+
mountIndex: currentMountIndex,
|
|
805
|
+
routerId,
|
|
806
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
807
|
+
...(prerenderRouteKeys ? { prerenderRouteKeys } : {}),
|
|
808
|
+
...(passthroughRouteKeys ? { passthroughRouteKeys } : {}),
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// Build route map from registered patterns
|
|
813
|
+
for (const [name, pattern] of routePatterns.entries()) {
|
|
814
|
+
// Runtime validation: warn if key already exists with different pattern.
|
|
815
|
+
// Skip warning for entries that came from the static seed — the gen file
|
|
816
|
+
// can be stale during HMR, so runtime registration is authoritative.
|
|
817
|
+
const existingPattern = mergedRouteMap[name];
|
|
818
|
+
if (
|
|
819
|
+
existingPattern !== undefined &&
|
|
820
|
+
existingPattern !== pattern &&
|
|
821
|
+
!seededNames.has(name)
|
|
822
|
+
) {
|
|
823
|
+
console.warn(
|
|
824
|
+
`[@rangojs/router] Route name conflict: "${name}" already maps to "${existingPattern}", ` +
|
|
825
|
+
`overwriting with "${pattern}". Use unique route names to avoid this.`,
|
|
826
|
+
);
|
|
2184
827
|
}
|
|
828
|
+
mergedRouteMap[name] = pattern;
|
|
829
|
+
seededNames.delete(name);
|
|
830
|
+
}
|
|
2185
831
|
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
const lazyIncludes = findLazyIncludes(handlerResult);
|
|
832
|
+
// Detect lazy includes in handler result and create placeholder entries
|
|
833
|
+
const lazyIncludes = findLazyIncludes(handlerResult);
|
|
2189
834
|
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
835
|
+
// Create placeholder RouteEntry for each lazy include
|
|
836
|
+
for (const lazyInclude of lazyIncludes) {
|
|
837
|
+
// Compute the full URL prefix (combining parent prefix if any)
|
|
838
|
+
const fullPrefix = lazyInclude.context.urlPrefix
|
|
839
|
+
? lazyInclude.context.urlPrefix + lazyInclude.prefix
|
|
840
|
+
: lazyInclude.prefix;
|
|
2196
841
|
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
}
|
|
842
|
+
const lazyEntry: RouteEntry<TEnv> & { _lazyPrefix?: string } = {
|
|
843
|
+
prefix: "",
|
|
844
|
+
staticPrefix: extractStaticPrefix(fullPrefix),
|
|
845
|
+
routes: {} as ResolvedRouteMap<any>, // Empty until first match
|
|
846
|
+
trailingSlash: trailingSlashConfig,
|
|
847
|
+
handler: urlPatterns.handler,
|
|
848
|
+
mountIndex: mountIndex++,
|
|
849
|
+
routerId,
|
|
850
|
+
// Lazy evaluation fields
|
|
851
|
+
lazy: true,
|
|
852
|
+
lazyPatterns: lazyInclude.patterns,
|
|
853
|
+
lazyContext: lazyInclude.context,
|
|
854
|
+
lazyEvaluated: false,
|
|
855
|
+
_lazyPrefix: lazyInclude.prefix,
|
|
856
|
+
};
|
|
857
|
+
// Insert lazy entry before any entry whose staticPrefix is a
|
|
858
|
+
// prefix of (but shorter than) this lazy entry's staticPrefix.
|
|
859
|
+
// This ensures more specific lazy includes are matched before
|
|
860
|
+
// less specific eager entries (e.g., "/href/nested" before "/href/:id").
|
|
861
|
+
const lazyPrefix = lazyEntry.staticPrefix;
|
|
862
|
+
let insertIndex = routesEntries.length;
|
|
863
|
+
if (lazyPrefix) {
|
|
864
|
+
for (let i = 0; i < routesEntries.length; i++) {
|
|
865
|
+
const existing = routesEntries[i]!;
|
|
866
|
+
if (
|
|
867
|
+
lazyPrefix.startsWith(existing.staticPrefix) &&
|
|
868
|
+
lazyPrefix.length > existing.staticPrefix.length
|
|
869
|
+
) {
|
|
870
|
+
insertIndex = i;
|
|
871
|
+
break;
|
|
2228
872
|
}
|
|
2229
873
|
}
|
|
2230
|
-
routesEntries.splice(insertIndex, 0, lazyEntry);
|
|
2231
874
|
}
|
|
2232
|
-
|
|
2233
|
-
// Auto-register route map for runtime reverse() usage
|
|
2234
|
-
registerRouteMap(mergedRouteMap);
|
|
2235
|
-
|
|
2236
|
-
// Return the router (no .map() needed for UrlPatterns)
|
|
2237
|
-
return router;
|
|
875
|
+
routesEntries.splice(insertIndex, 0, lazyEntry);
|
|
2238
876
|
}
|
|
2239
877
|
|
|
2240
|
-
//
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
}
|
|
2245
|
-
// Otherwise, first argument is routes with empty prefix
|
|
2246
|
-
return createRouteBuilder("", prefixOrRoutes as Record<string, string>);
|
|
878
|
+
// Auto-register route map for runtime reverse() usage
|
|
879
|
+
registerRouteMap(mergedRouteMap);
|
|
880
|
+
|
|
881
|
+
return router;
|
|
2247
882
|
},
|
|
2248
883
|
|
|
2249
884
|
use(
|
|
2250
885
|
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
2251
886
|
middleware?: MiddlewareFn<TEnv>,
|
|
2252
887
|
): any {
|
|
2253
|
-
//
|
|
2254
|
-
|
|
888
|
+
// Auto-prefix pattern with basename so router-level middleware
|
|
889
|
+
// patterns are router-relative (e.g. "/users/*" matches "/app/users/*").
|
|
890
|
+
if (basename && typeof patternOrMiddleware === "string") {
|
|
891
|
+
const pattern = patternOrMiddleware;
|
|
892
|
+
const prefixed =
|
|
893
|
+
pattern === "/*" || pattern === "*"
|
|
894
|
+
? `${basename}/*`
|
|
895
|
+
: `${basename}${pattern}`;
|
|
896
|
+
addMiddleware(prefixed, middleware, null);
|
|
897
|
+
} else {
|
|
898
|
+
addMiddleware(patternOrMiddleware, middleware, null);
|
|
899
|
+
}
|
|
2255
900
|
return router;
|
|
2256
901
|
},
|
|
2257
902
|
|
|
2258
903
|
// Type-safe URL builder using merged route map
|
|
2259
904
|
// Types are tracked through the builder chain via TRoutes parameter
|
|
905
|
+
// Seeded with static route names from the generated file (injected by Vite)
|
|
2260
906
|
reverse: createReverse(mergedRouteMap),
|
|
2261
907
|
|
|
2262
908
|
// Expose accumulated route map for typeof extraction
|
|
@@ -2280,19 +926,62 @@ export function createRouter<TEnv = any>(
|
|
|
2280
926
|
// Expose resolved theme configuration for NavigationProvider and MetaTags
|
|
2281
927
|
themeConfig: resolvedThemeConfig,
|
|
2282
928
|
|
|
929
|
+
// Expose resolved cache profiles for per-request resolution
|
|
930
|
+
cacheProfiles: resolvedCacheProfiles,
|
|
931
|
+
|
|
932
|
+
// Expose prefetch cache settings
|
|
933
|
+
prefetchCacheControl,
|
|
934
|
+
prefetchCacheTTL,
|
|
935
|
+
|
|
2283
936
|
// Expose warmup enabled flag for handler and client
|
|
2284
937
|
warmupEnabled,
|
|
2285
938
|
|
|
939
|
+
// Expose router-wide performance debugging for request-level metrics setup
|
|
940
|
+
debugPerformance,
|
|
941
|
+
|
|
2286
942
|
// Expose debug manifest flag for handler
|
|
2287
943
|
allowDebugManifest: allowDebugManifestOption,
|
|
2288
944
|
|
|
945
|
+
// Expose origin check configuration for handler (default: enabled)
|
|
946
|
+
originCheck: originCheckOption ?? true,
|
|
947
|
+
|
|
948
|
+
// Expose SSR configuration for handler
|
|
949
|
+
ssr: ssrOption,
|
|
950
|
+
|
|
951
|
+
// Expose resolved timeouts for RSC handler
|
|
952
|
+
timeouts: resolvedTimeouts,
|
|
953
|
+
onTimeout,
|
|
954
|
+
|
|
2289
955
|
// Expose global middleware for RSC handler
|
|
2290
956
|
middleware: globalMiddleware,
|
|
2291
957
|
|
|
2292
|
-
match,
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
958
|
+
match: (request: Request, input: RouterRequestInput<TEnv> = {}) => {
|
|
959
|
+
const env = input.env ?? ({} as TEnv);
|
|
960
|
+
return match(request, env);
|
|
961
|
+
},
|
|
962
|
+
matchForPrerender,
|
|
963
|
+
renderStaticSegment,
|
|
964
|
+
matchPartial: (
|
|
965
|
+
request: Request,
|
|
966
|
+
input: RouterRequestInput<TEnv> = {},
|
|
967
|
+
actionContext?: Parameters<typeof matchPartial>[2],
|
|
968
|
+
) => {
|
|
969
|
+
const env = input.env ?? ({} as TEnv);
|
|
970
|
+
return matchPartial(request, env, actionContext);
|
|
971
|
+
},
|
|
972
|
+
matchError: (
|
|
973
|
+
request: Request,
|
|
974
|
+
input: RouterRequestInput<TEnv> | undefined,
|
|
975
|
+
error: unknown,
|
|
976
|
+
segmentType?: Parameters<typeof matchError>[3],
|
|
977
|
+
) => {
|
|
978
|
+
const env = input?.env ?? ({} as TEnv);
|
|
979
|
+
return matchError(request, env, error, segmentType);
|
|
980
|
+
},
|
|
981
|
+
previewMatch: (request: Request, input: RouterRequestInput<TEnv> = {}) => {
|
|
982
|
+
const env = input.env ?? ({} as TEnv);
|
|
983
|
+
return previewMatch(request, env);
|
|
984
|
+
},
|
|
2296
985
|
|
|
2297
986
|
// Expose nonce provider for fetch
|
|
2298
987
|
nonce,
|
|
@@ -2305,89 +994,60 @@ export function createRouter<TEnv = any>(
|
|
|
2305
994
|
return storedUrlPatterns ?? undefined;
|
|
2306
995
|
},
|
|
2307
996
|
|
|
997
|
+
// Expose source file for per-router type generation
|
|
998
|
+
__sourceFile,
|
|
999
|
+
|
|
1000
|
+
// Expose basename for runtime manifest generation
|
|
1001
|
+
__basename: basename,
|
|
1002
|
+
|
|
2308
1003
|
// RSC request handler (lazily created on first call)
|
|
2309
1004
|
fetch: (() => {
|
|
2310
1005
|
// Handler is created on first call and reused
|
|
2311
1006
|
let handler:
|
|
2312
1007
|
| ((
|
|
2313
1008
|
request: Request,
|
|
2314
|
-
|
|
1009
|
+
input: RouterRequestInput<TEnv>,
|
|
2315
1010
|
) => Promise<Response>)
|
|
2316
1011
|
| null = null;
|
|
2317
1012
|
|
|
2318
|
-
return async (
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
1013
|
+
return async (request: Request, input: RouterRequestInput<TEnv> = {}) => {
|
|
1014
|
+
// Trigger lazy import of per-router manifest data before route matching.
|
|
1015
|
+
// No-op if data is already loaded or no loader is registered.
|
|
1016
|
+
await ensureRouterManifest(routerId);
|
|
2322
1017
|
if (!handler) {
|
|
2323
1018
|
// Lazy import deferred to first request to avoid dev mode issues
|
|
2324
1019
|
const { createRSCHandler } = await import("./rsc/handler.js");
|
|
1020
|
+
// Cast: handler.ts still accepts (request, env) — will be updated
|
|
1021
|
+
// separately to accept RouterRequestInput.
|
|
2325
1022
|
handler = createRSCHandler({
|
|
2326
1023
|
router: router as any,
|
|
2327
1024
|
cache,
|
|
2328
1025
|
nonce,
|
|
2329
1026
|
version,
|
|
2330
|
-
})
|
|
1027
|
+
}) as (
|
|
1028
|
+
request: Request,
|
|
1029
|
+
input: RouterRequestInput<TEnv>,
|
|
1030
|
+
) => Promise<Response>;
|
|
2331
1031
|
}
|
|
2332
|
-
return handler(request,
|
|
1032
|
+
return handler!(request, input);
|
|
2333
1033
|
};
|
|
2334
1034
|
})(),
|
|
2335
1035
|
|
|
2336
|
-
//
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
for (const entry of routesEntries) {
|
|
2341
|
-
const Store = {
|
|
2342
|
-
manifest,
|
|
2343
|
-
namespace: `debug.M${entry.mountIndex}`,
|
|
2344
|
-
parent: null as EntryData | null,
|
|
2345
|
-
counters: {} as Record<string, number>,
|
|
2346
|
-
mountIndex: entry.mountIndex,
|
|
2347
|
-
patterns: new Map<string, string>(),
|
|
2348
|
-
trailingSlash: new Map<string, TrailingSlashMode>(),
|
|
2349
|
-
};
|
|
2350
|
-
|
|
2351
|
-
await getContext().runWithStore(
|
|
2352
|
-
Store,
|
|
2353
|
-
`debug.M${entry.mountIndex}`,
|
|
2354
|
-
null,
|
|
2355
|
-
async () => {
|
|
2356
|
-
const helpers = createRouteHelpers();
|
|
2357
|
-
|
|
2358
|
-
// Wrap handler execution in root layout (same as loadManifest)
|
|
2359
|
-
let promiseResult: Promise<any> | null = null;
|
|
2360
|
-
helpers.layout(MapRootLayout, () => {
|
|
2361
|
-
const result = entry.handler();
|
|
2362
|
-
if (result instanceof Promise) {
|
|
2363
|
-
promiseResult = result;
|
|
2364
|
-
return [];
|
|
2365
|
-
}
|
|
2366
|
-
return result;
|
|
2367
|
-
});
|
|
2368
|
-
|
|
2369
|
-
if (promiseResult !== null) {
|
|
2370
|
-
const load = await (promiseResult as Promise<any>);
|
|
2371
|
-
if (load && typeof load === "object" && "default" in load) {
|
|
2372
|
-
const useItems = load.default;
|
|
2373
|
-
if (typeof useItems === "function") {
|
|
2374
|
-
useItems(helpers);
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
},
|
|
2379
|
-
);
|
|
2380
|
-
}
|
|
1036
|
+
// Low-level route matching for request classification
|
|
1037
|
+
findMatch: (pathname: string, metricsStore?: any) =>
|
|
1038
|
+
findMatch(pathname, metricsStore),
|
|
2381
1039
|
|
|
2382
|
-
|
|
2383
|
-
|
|
1040
|
+
// Debug utility for manifest inspection
|
|
1041
|
+
debugManifest: () => buildDebugManifest<TEnv>(routesEntries),
|
|
2384
1042
|
};
|
|
2385
1043
|
|
|
2386
1044
|
// Register router in the global registry for build-time discovery
|
|
2387
1045
|
RouterRegistry.set(routerId, router);
|
|
2388
1046
|
|
|
2389
1047
|
// If urls option was provided, auto-register them
|
|
2390
|
-
if (urlsOption) {
|
|
1048
|
+
if (typeof urlsOption === "function") {
|
|
1049
|
+
return router.routes(urlsOption) as RSCRouter<TEnv, {}>;
|
|
1050
|
+
} else if (urlsOption) {
|
|
2391
1051
|
return router.routes(urlsOption) as RSCRouter<TEnv, {}>;
|
|
2392
1052
|
}
|
|
2393
1053
|
|