@ecopages/core 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +3 -3
- package/src/adapters/node/create-app.d.ts +40 -11
- package/src/adapters/node/create-app.js +95 -69
- package/src/adapters/node/dev-session.js +0 -1
- package/src/adapters/node/http-request-bridge.d.ts +4 -0
- package/src/adapters/node/http-request-bridge.js +9 -1
- package/src/adapters/node/runtime-host.d.ts +28 -6
- package/src/adapters/node/runtime-host.js +35 -9
- package/src/adapters/node/server-adapter.d.ts +10 -35
- package/src/adapters/node/server-adapter.js +21 -58
- package/src/adapters/shared/hmr/hmr-manager.d.ts +21 -7
- package/src/adapters/shared/hmr/hmr-manager.js +58 -70
- package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
- package/src/adapters/shared/http/api-request-pipeline.js +7 -7
- package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
- package/src/adapters/shared/http/dist-file-handler.js +172 -0
- package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
- package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
- package/src/adapters/shared/runtime/bind-runtime-server.js +8 -12
- package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
- package/src/adapters/shared/runtime/port-manager.d.ts +8 -11
- package/src/adapters/shared/runtime/port-manager.js +19 -30
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
- package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
- package/src/adapters/shared/runtime/server-static-builder.js +3 -3
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
- package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
- package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
- package/src/assets/app-browser-client-build.js +1 -2
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
- package/src/assets/browser-asset-output.d.ts +19 -0
- package/src/assets/browser-asset-output.js +30 -0
- package/src/assets/hashed-browser-asset.d.ts +8 -6
- package/src/assets/hashed-browser-asset.js +8 -6
- package/src/build/build-adapter.d.ts +2 -19
- package/src/build/build-adapter.js +0 -21
- package/src/build/build-graph.js +2 -2
- package/src/build/cache/cache-keys.d.ts +0 -3
- package/src/build/cache/cache-keys.js +0 -14
- package/src/build/cache/pages-unified-graph-build.js +2 -17
- package/src/build/contracts/build-contracts.d.ts +0 -3
- package/src/build/preserve-import-meta-transform.js +2 -2
- package/src/build/rolldown/app-package-declarations.js +3 -3
- package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
- package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
- package/src/build/rolldown/rolldown-build-adapter.js +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
- package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
- package/src/build/runtime/build-queue.d.ts +8 -13
- package/src/build/runtime/build-queue.js +6 -17
- package/src/build/server/app-module-loader.service.d.ts +1 -1
- package/src/build/server/app-module-loader.service.js +0 -2
- package/src/build/server/page-module-import.service.d.ts +2 -3
- package/src/build/server/page-module-import.service.js +3 -4
- package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
- package/src/build/server-bundle-deploy-manifest.js +15 -1
- package/src/build/server-bundle-publication.js +4 -5
- package/src/build.d.ts +2 -2
- package/src/build.js +2 -2
- package/src/config/assembly/app-runtime.d.ts +2 -2
- package/src/config/assembly/app-runtime.js +2 -2
- package/src/config/assembly/finalize-config.d.ts +4 -4
- package/src/config/assembly/finalize-config.js +4 -5
- package/src/config/config-module-files.js +2 -3
- package/src/config/internal-types.d.ts +0 -7
- package/src/config/user-config-types.d.ts +0 -4
- package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
- package/src/diagnostics/request-pipeline-metrics.js +4 -4
- package/src/diagnostics/startup-trace.js +2 -5
- package/src/errors/http-error.d.ts +2 -2
- package/src/errors/http-error.js +4 -4
- package/src/hmr/client/hmr-runtime.js +16 -7
- package/src/hmr/client/module-update.d.ts +7 -0
- package/src/hmr/client/module-update.js +21 -4
- package/src/hmr/hmr-strategy.d.ts +0 -3
- package/src/hmr/hmr-strategy.js +0 -3
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
- package/src/hmr/strategies/js-hmr-strategy.js +3 -6
- package/src/html-pages/html-page-module-scripts.js +4 -3
- package/src/html-pages/html-page-renderer.js +2 -3
- package/src/plugins/alias-resolver-cache.d.ts +4 -3
- package/src/plugins/alias-resolver-cache.js +4 -3
- package/src/plugins/component-import-discovery.js +4 -4
- package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
- package/src/plugins/eco-component-meta-plugin.js +66 -10
- package/src/plugins/foreign-jsx-override-plugin.js +4 -3
- package/src/plugins/tsconfig-import-resolver.js +12 -12
- package/src/route-renderer/error-pages/default-error-pages.js +2 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
- package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
- package/src/route-renderer/orchestration/integration-renderer.js +13 -14
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -23
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -29
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
- package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
- package/src/route-renderer/page-loading/page-module-loader.js +1 -1
- package/src/route-renderer/route-renderer.d.ts +2 -5
- package/src/route-renderer/route-renderer.js +2 -4
- package/src/router/client/link-navigation-policy.d.ts +4 -1
- package/src/router/client/link-navigation-policy.js +20 -6
- package/src/router/server/route-registry.d.ts +0 -1
- package/src/router/server/route-registry.js +3 -13
- package/src/router/server/segment-path-matcher.d.ts +12 -0
- package/src/router/server/segment-path-matcher.js +30 -0
- package/src/static-site-generator/static-site-generator.d.ts +0 -5
- package/src/static-site-generator/static-site-generator.js +2 -15
- package/src/types/contracts.d.ts +17 -27
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/format-error-chain.d.ts +9 -0
- package/src/utils/format-error-chain.js +20 -0
- package/src/utils/invariant.d.ts +6 -1
- package/src/utils/invariant.js +7 -2
- package/src/watchers/project-watcher.d.ts +20 -1
- package/src/watchers/project-watcher.js +40 -9
- package/src/watchers/workspace-package-watch-roots.js +5 -5
- package/src/adapters/README.md +0 -58
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
- package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
- package/src/adapters/shared/runtime/runtime-host.js +0 -1
- package/src/assets/README.md +0 -35
- package/src/build/README.md +0 -298
- package/src/build/server/README.md +0 -50
- package/src/cache/README.md +0 -5
- package/src/client/README.md +0 -5
- package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
- package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
- package/src/client/scroll.test.browser.d.ts +0 -1
- package/src/client/scroll.test.browser.js +0 -31
- package/src/client/view-transitions.test.browser.d.ts +0 -1
- package/src/client/view-transitions.test.browser.js +0 -53
- package/src/config/README.md +0 -58
- package/src/config/constants.d.ts +0 -1
- package/src/config/constants.js +0 -1
- package/src/dev/README.md +0 -61
- package/src/dev/invalidation/README.md +0 -11
- package/src/dev-toolbar/README.md +0 -66
- package/src/diagnostics/README.md +0 -11
- package/src/eco/README.md +0 -776
- package/src/errors/README.md +0 -5
- package/src/global/README.md +0 -5
- package/src/hmr/README.md +0 -64
- package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
- package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
- package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
- package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
- package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
- package/src/hmr/entrypoint-dependency-graph.js +0 -27
- package/src/hmr/hmr-file-change-prep.d.ts +0 -9
- package/src/hmr/hmr-file-change-prep.js +0 -11
- package/src/html/README.md +0 -15
- package/src/html-pages/README.md +0 -104
- package/src/islands/README.md +0 -44
- package/src/page-cache/README.md +0 -17
- package/src/plugins/README.md +0 -53
- package/src/route-renderer/GRAPH.md +0 -142
- package/src/route-renderer/README.md +0 -160
- package/src/route-renderer/error-pages/README.md +0 -11
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
- package/src/router/README.md +0 -160
- package/src/router/client/link-intent.test.browser.d.ts +0 -1
- package/src/router/client/link-intent.test.browser.js +0 -33
- package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
- package/src/router/client/link-navigation-policy.test.browser.js +0 -142
- package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
- package/src/router/client/navigation-commit.test.browser.js +0 -116
- package/src/router/client/navigation-document.test.browser.d.ts +0 -1
- package/src/router/client/navigation-document.test.browser.js +0 -77
- package/src/router/client/navigation-head.test.browser.d.ts +0 -1
- package/src/router/client/navigation-head.test.browser.js +0 -101
- package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
- package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
- package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
- package/src/router/client/navigation-view-transition.test.browser.js +0 -189
- package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
- package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
- package/src/static-site-generator/README.md +0 -67
- package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
- package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
- package/src/types/README.md +0 -5
- package/src/utils/README.md +0 -7
- package/src/validation/README.md +0 -9
- package/src/watchers/README.md +0 -15
- package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
- package/src/watchers/project-watcher.test-helpers.js +0 -108
package/src/router/README.md
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# Router Layer
|
|
2
|
-
|
|
3
|
-
**Layer:** Rendering.
|
|
4
|
-
|
|
5
|
-
This directory contains route discovery, matching, and browser-side navigation infrastructure.
|
|
6
|
-
|
|
7
|
-
## Purpose
|
|
8
|
-
|
|
9
|
-
The router layer determines what route is being handled and how the client runtime coordinates navigation.
|
|
10
|
-
|
|
11
|
-
It is responsible for:
|
|
12
|
-
|
|
13
|
-
- filesystem route discovery and classification (`exact`, `dynamic`, `catch-all`)
|
|
14
|
-
- matching incoming request URLs to canonical template routes
|
|
15
|
-
- server-side static-path expansion for dynamic template routes
|
|
16
|
-
- client-side navigation ownership and cross-runtime handoff
|
|
17
|
-
- keeping route discovery separate from rendering execution
|
|
18
|
-
|
|
19
|
-
## Directory Structure
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
router/
|
|
23
|
-
├── server/ # Server-side route discovery and matching
|
|
24
|
-
│ ├── route-registry.ts # Owns template routes, request matching, static expansion, and reload
|
|
25
|
-
│ └── segment-path-matcher.ts # Shared segment matching for every server route kind
|
|
26
|
-
└── client/ # Browser-side navigation coordination
|
|
27
|
-
├── navigation-coordinator.ts # Singleton runtime coordinator
|
|
28
|
-
├── navigation-commit.ts # Shared client navigation commit pipeline
|
|
29
|
-
├── navigation-document.ts # Shared page fetch, HTML cache, and base-aware parsing
|
|
30
|
-
├── navigation-head.ts # Shared page head reconciliation
|
|
31
|
-
├── navigation-lifecycle.ts # Shared document lifecycle events
|
|
32
|
-
├── navigation-pipeline.ts # Public client navigation entry
|
|
33
|
-
├── navigation-replay.ts # Shared queued-navigation decision
|
|
34
|
-
├── navigation-view-transition.ts # Shared named-transition wrapper
|
|
35
|
-
└── link-intent.ts # Shared anchor detection and intent recovery helpers
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## `server/`
|
|
39
|
-
|
|
40
|
-
### `RouteRegistry`
|
|
41
|
-
|
|
42
|
-
Owns the canonical set of filesystem-discovered template routes for one application.
|
|
43
|
-
|
|
44
|
-
File patterns determine route kind:
|
|
45
|
-
|
|
46
|
-
| Pattern | Kind | Example |
|
|
47
|
-
| --------------- | ----------- | ----------------- |
|
|
48
|
-
| `page.tsx` | `exact` | `/about` |
|
|
49
|
-
| `[slug].tsx` | `dynamic` | `/blog/[slug]` |
|
|
50
|
-
| `[...slug].tsx` | `catch-all` | `/docs/[...slug]` |
|
|
51
|
-
|
|
52
|
-
Route paths drop the longest registered extension the file ends with, so `about.kita.tsx` becomes `/about` and `v1.2.html` becomes `/v1.2`. Route kinds come from the path inside the pages directory, so brackets in the project path do not make routes dynamic.
|
|
53
|
-
|
|
54
|
-
Discovery rejects two Page files that produce the same template route (for example `about.html` with `about.tsx` or `about/index.html`) and dynamic filenames such as `[slug].html` whose owning Integration sets `acceptsParams` to `false` (HTML Pages do, because they have no `staticPaths` source).
|
|
55
|
-
|
|
56
|
-
The registry stores canonical template routes only. It compiles request-time matching metadata during `init()` and `reload()`, but it does not execute `staticPaths()` during discovery.
|
|
57
|
-
|
|
58
|
-
Build-time static expansion is a separate operation. The registry invokes `staticPaths()` lazily through an injected page-module adapter and returns concrete static path expansions for the static generator.
|
|
59
|
-
|
|
60
|
-
The public interface is intentionally small:
|
|
61
|
-
|
|
62
|
-
- `templateRoutes` — ordered readonly template routes
|
|
63
|
-
- `init()` / `reload()` — rebuild discovery state and match metadata
|
|
64
|
-
- `matchRequest(requestUrl)` — request-time matching result with requested pathname, matched template route, params, and query
|
|
65
|
-
- `listStaticPathExpansions()` — build-time expansion for dynamic routes
|
|
66
|
-
- `listStaticGenerationRoutes()` — build-time route planning for static generation across exact and expanded routes
|
|
67
|
-
|
|
68
|
-
Match priority:
|
|
69
|
-
|
|
70
|
-
1. `exact` — the normalized, decoded pathname segments must equal the route segments.
|
|
71
|
-
2. `dynamic` — the route and pathname must have the same number of segments; literal segments must match exactly, and each parameter segment matches one segment.
|
|
72
|
-
3. `catch-all` — the prefix segments must match the pathname. When multiple
|
|
73
|
-
catch-all routes match, shared prefix segments are compared from left to right
|
|
74
|
-
so an earlier static segment wins over a dynamic one; when those patterns tie,
|
|
75
|
-
the route with the longer prefix wins, then pathname order provides a
|
|
76
|
-
deterministic tie-breaker.
|
|
77
|
-
|
|
78
|
-
The shared segment matcher uses `normalizePathname`, which adds a leading slash and removes trailing slashes except for `/`. It preserves repeated slashes inside a pathname; matching ignores the empty segments between them. The matcher splits paths on `/` before decoding each segment once, so an encoded slash stays inside its original segment. Malformed percent escapes raise an HTTP 400 error (subject to `app.onError` handling), even when no registered route matches.
|
|
79
|
-
|
|
80
|
-
Supported dynamic route syntax and captured values:
|
|
81
|
-
|
|
82
|
-
| Route kind | Named parameters | Catch-all or wildcard | Handler-facing value |
|
|
83
|
-
| ---------- | ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
84
|
-
| Filesystem | `[name]` | `[...name]` | Named parameter is a string; catch-all is a string array. |
|
|
85
|
-
| API | `:name` or `[name]` | `[...name]` or `*` | Named parameters are strings; catch-all params are arrays of decoded segments. `*` has no named value. |
|
|
86
|
-
| Explicit | `:name` or `[name]` | `:...name` or `[...name]` | Named parameters and catch-alls are strings; catch-all segments are joined with `/`. |
|
|
87
|
-
| WebSocket | `:name` | None | Named parameters are strings. |
|
|
88
|
-
|
|
89
|
-
Repeated query keys retain all values in order: `?tag=docs&tag=api` becomes `{ tag: ['docs', 'api'] }`. A query key with one value remains a string. Pages, API handlers, route matching, and static route info share `PageParams` and `PageQuery` value shapes.
|
|
90
|
-
|
|
91
|
-
API and WebSocket matching still prioritize more specific routes. Filesystem routes keep their existing exact, dynamic, and catch-all ordering; explicit routes keep declaration order.
|
|
92
|
-
|
|
93
|
-
## `client/`
|
|
94
|
-
|
|
95
|
-
### View transitions (`@ecopages/core/client`)
|
|
96
|
-
|
|
97
|
-
Shared helpers used by `@ecopages/browser-router` and `@ecopages/react-router`:
|
|
98
|
-
|
|
99
|
-
- `applyViewTransitionNames` / `clearViewTransitionNames` — named `data-view-transition` morph / fade styles (`eco-vt-dynamic-styles`).
|
|
100
|
-
- `ensureRootViewTransitionStyles` — persisted CSS (`eco-vt-root-styles`, `data-eco-persist`) with `html { view-transition-name: none }` when VT is enabled.
|
|
101
|
-
- `navigationHasNamedViewTransitions` — detects named `data-view-transition` markup on either page.
|
|
102
|
-
|
|
103
|
-
Each later navigation supersedes cleanup from earlier transitions, including when it skips animation. A failed or uncommitted page swap clears transition names.
|
|
104
|
-
|
|
105
|
-
### Client navigation pipeline (`@ecopages/core/client`)
|
|
106
|
-
|
|
107
|
-
`commitNavigationPage()` owns shared document work: it dispatches lifecycle hooks, waits for new stylesheets, reconciles the head, wraps the adapter's swap in a named view transition, activates scripts, and invokes the router's scroll callback after the swap. Browser-router always morphs the incoming body. Persisted nodes remain attached when the incoming page keeps their ancestor structure compatible, whether view transitions are enabled or the page has rerun scripts. With rerun scripts, matching non-persisted elements refresh before activation except for the body, persisted elements, their ancestor path, and descendants of custom elements on that path; those descendants stay in place so the connected host's handlers remain active. Handler-bound child markup must remain structurally compatible, or the custom element must rebind when its child markup changes, because replacing a child does not reconnect the host. Handlers installed on any retained nodes must be registered idempotently. React-router supplies a React render and its scroll callback. Both use the same fetch, parse, cache, script identity, persist attribute, and queued-click policy. Head reconciliation removes head elements the incoming page lacks unless they carry the persist attribute. Browser-router prefetches into the shared HTML cache and reads it on click; React-router always fetches fresh HTML and only writes to the cache. A later commit that removes a staged stylesheet also settles its load wait so the superseded navigation can finish promptly. Rerun scripts match by `data-eco-script-id`, HTML `id`, original `src`, or inline contents. When matching by relative `src`, identity stays stable across different page base URLs, while external modules execute from the incoming page's resolved URL. The `runNavigationViewTransition()` update callback may return `false` when it does not commit; a void result counts as committed.
|
|
108
|
-
|
|
109
|
-
The named exports from this entry are supported APIs for browser runtime authors. They cover document loading and cache control (`fetchNavigationPage`, `parseNavigationDocument`, `cacheNavigationHtml`, `getCachedNavigationHtml`, `invalidateNavigationHtml`, and `clearNavigationHtmlCache`), prefetch and replay policy (`shouldPrefetchLink`, `isSamePageHref`, and `decideQueuedNavigationReplay`), staged document updates (`prepareNavigationHead`, `activatePreparedNavigationScripts`, and `commitNavigationPage`), script activation (`activateNavigationScripts`, `activateScriptsInOrder`, and `collectBodyScripts`), named view transitions (`runNavigationViewTransition`), and the shared persist attribute (`ECO_PERSIST_ATTRIBUTE`). Their associated option and result types are exported alongside them.
|
|
110
|
-
|
|
111
|
-
### Navigation Coordinator (`navigation-coordinator.ts`)
|
|
112
|
-
|
|
113
|
-
A singleton browser-side runtime stored on `window.__ECO_PAGES__.navigation`.
|
|
114
|
-
|
|
115
|
-
Access it with:
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
import { getEcoNavigationRuntime } from '@ecopages/core/client';
|
|
119
|
-
const runtime = getEcoNavigationRuntime();
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
The coordinator is framework-agnostic. Browser runtimes (e.g. `browser-router`, `react-router`) register themselves and the coordinator arbitrates:
|
|
123
|
-
|
|
124
|
-
- **Ownership** — which runtime currently drives SPA navigation (`claimOwnership`, `releaseOwnership`).
|
|
125
|
-
- **Document owner marker** — an HTML attribute (`data-eco-document-owner`) written into rendered markup so the coordinator can `adoptDocumentOwner` on the incoming page.
|
|
126
|
-
- **Navigation transactions** — each navigation begins a transaction with an `AbortSignal`; superseded navigations are automatically cancelled.
|
|
127
|
-
- **Cross-runtime handoff** — `requestHandoff` passes a pre-fetched `Document` to the target runtime without tearing down the current page prematurely.
|
|
128
|
-
- **Reload** — `reloadCurrentPage` delegates to whichever runtime currently owns the document.
|
|
129
|
-
|
|
130
|
-
### Navigation Lifecycle (`navigation-lifecycle.ts`)
|
|
131
|
-
|
|
132
|
-
Shared document lifecycle events emitted by browser runtimes after a client navigation commits.
|
|
133
|
-
|
|
134
|
-
Access it with:
|
|
135
|
-
|
|
136
|
-
```ts
|
|
137
|
-
import { completeNavigationLifecycle, dispatchBeforeSwap, type EcoNavigationEvent } from '@ecopages/core/client';
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
The shared navigation pipeline emits these events around the router-specific swap. Use `completeNavigationLifecycle` when implementing a custom runtime. Listeners use the DOM contract:
|
|
141
|
-
|
|
142
|
-
- `eco:before-swap` — pre-commit hook with `newDocument` and `reload()`
|
|
143
|
-
- `eco:after-swap` — post-commit signal after the runtime has applied the new page
|
|
144
|
-
- `eco:page-load` — scheduled on the next animation frame after `eco:after-swap`
|
|
145
|
-
|
|
146
|
-
Scripts listening to client navigation events (`eco:after-swap`, `eco:page-load`) should be registered as client scripts (e.g., using `scripts: ['./component.script.ts']`) or guarded by `isServer` from `@ecopages/radiant/is-server` when used in Radiant projects where `document` is defined during SSR.
|
|
147
|
-
|
|
148
|
-
### Link Intent (`link-intent.ts`)
|
|
149
|
-
|
|
150
|
-
Shared helpers for locating anchors and recovering stale navigation intent.
|
|
151
|
-
|
|
152
|
-
- `getAnchorFromNavigationEvent(event, linkSelector)` — finds the nearest matching anchor in the event's composed path, including across Shadow DOM boundaries.
|
|
153
|
-
- `recoverPendingNavigationHref(intent, hasInFlightNavigation, now, maxAgeMs?)` — resolves a previously captured pointer or hover target when the DOM changes before the click lands. Intents expire after `maxAgeMs` (default 1000 ms).
|
|
154
|
-
|
|
155
|
-
## Relationship To Rendering
|
|
156
|
-
|
|
157
|
-
The router layer answers **which route should run**.
|
|
158
|
-
The route-renderer layer answers **how that route gets rendered**.
|
|
159
|
-
|
|
160
|
-
Keeping those seams separate avoids mixing route ownership, module loading, and component orchestration into one service.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getAnchorFromNavigationEvent } from './link-intent.js';
|
|
3
|
-
describe('getAnchorFromNavigationEvent', () => {
|
|
4
|
-
it('returns the anchor when the event target is a text node inside it', () => {
|
|
5
|
-
const anchor = document.createElement('a');
|
|
6
|
-
anchor.href = '/fast';
|
|
7
|
-
anchor.setAttribute('data-eco-link', 'true');
|
|
8
|
-
const textNode = document.createTextNode('fast-link');
|
|
9
|
-
anchor.append(textNode);
|
|
10
|
-
document.body.append(anchor);
|
|
11
|
-
const event = new MouseEvent('click', { bubbles: true, cancelable: true, composed: true });
|
|
12
|
-
Object.defineProperty(event, 'target', {
|
|
13
|
-
configurable: true,
|
|
14
|
-
value: textNode,
|
|
15
|
-
});
|
|
16
|
-
expect(getAnchorFromNavigationEvent(event, 'a[data-eco-link]')).toBe(anchor);
|
|
17
|
-
});
|
|
18
|
-
it('returns the closest matching anchor for nested element targets', () => {
|
|
19
|
-
const anchor = document.createElement('a');
|
|
20
|
-
anchor.href = '/fast';
|
|
21
|
-
anchor.setAttribute('data-eco-link', 'true');
|
|
22
|
-
const span = document.createElement('span');
|
|
23
|
-
span.textContent = 'fast-link';
|
|
24
|
-
anchor.append(span);
|
|
25
|
-
document.body.append(anchor);
|
|
26
|
-
const event = new MouseEvent('click', { bubbles: true, cancelable: true, composed: true });
|
|
27
|
-
Object.defineProperty(event, 'target', {
|
|
28
|
-
configurable: true,
|
|
29
|
-
value: span,
|
|
30
|
-
});
|
|
31
|
-
expect(getAnchorFromNavigationEvent(event, 'a[data-eco-link]')).toBe(anchor);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import { getLinkNavigationDecision, getNavigableHrefFromClick, isSamePageHashNavigationHref, shouldPrefetchLink, } from './link-navigation-policy.js';
|
|
3
|
-
function createLink(href, attributes = {}) {
|
|
4
|
-
const link = document.createElement('a');
|
|
5
|
-
if (href !== null)
|
|
6
|
-
link.setAttribute('href', href);
|
|
7
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
8
|
-
link.setAttribute(key, value);
|
|
9
|
-
}
|
|
10
|
-
document.body.append(link);
|
|
11
|
-
return link;
|
|
12
|
-
}
|
|
13
|
-
function createMouseEvent(modifiers = {}) {
|
|
14
|
-
return new MouseEvent('click', { bubbles: true, cancelable: true, button: 0, ...modifiers });
|
|
15
|
-
}
|
|
16
|
-
const policy = {
|
|
17
|
-
reloadAttribute: 'data-eco-reload',
|
|
18
|
-
noPrefetchAttribute: 'data-eco-no-prefetch',
|
|
19
|
-
};
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
document.body.replaceChildren();
|
|
22
|
-
history.replaceState({}, '', '/');
|
|
23
|
-
});
|
|
24
|
-
const intercepted = (href) => ({ shouldIntercept: true, href });
|
|
25
|
-
const ignored = (reason) => ({
|
|
26
|
-
shouldIntercept: false,
|
|
27
|
-
reason,
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* The one table for the link interception policy shared by browser-router and react-router.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* Each rejecting row uses an href that no other rule would reject, and the expected decision names
|
|
34
|
-
* the reason, so removing one rule turns its row into a different reason instead of passing.
|
|
35
|
-
* `/export` carries the download rows because `/file.pdf` is also a static asset.
|
|
36
|
-
*/
|
|
37
|
-
const decisionRows = [
|
|
38
|
-
{ name: 'same-origin page link', href: '/page', expected: intercepted('/page') },
|
|
39
|
-
{ name: 'relative path link', href: 'relative/path', expected: intercepted('relative/path') },
|
|
40
|
-
{
|
|
41
|
-
name: 'same-origin absolute URL',
|
|
42
|
-
href: `${window.location.origin}/absolute-path`,
|
|
43
|
-
expected: intercepted(`${window.location.origin}/absolute-path`),
|
|
44
|
-
},
|
|
45
|
-
{ name: 'link with a query string', href: '/page?foo=bar&baz=qux', expected: intercepted('/page?foo=bar&baz=qux') },
|
|
46
|
-
{ name: 'target _self', href: '/page', attributes: { target: '_self' }, expected: intercepted('/page') },
|
|
47
|
-
{ name: 'hash on another page', href: '/other#section', expected: intercepted('/other#section') },
|
|
48
|
-
{
|
|
49
|
-
name: 'default reload attribute once a custom one is set',
|
|
50
|
-
href: '/page',
|
|
51
|
-
attributes: { 'data-eco-reload': '' },
|
|
52
|
-
options: { reloadAttribute: 'data-full-reload' },
|
|
53
|
-
expected: intercepted('/page'),
|
|
54
|
-
},
|
|
55
|
-
{ name: 'meta-click', href: '/page', event: { metaKey: true }, expected: ignored('modified-click') },
|
|
56
|
-
{ name: 'ctrl-click', href: '/page', event: { ctrlKey: true }, expected: ignored('modified-click') },
|
|
57
|
-
{ name: 'shift-click', href: '/page', event: { shiftKey: true }, expected: ignored('modified-click') },
|
|
58
|
-
{ name: 'alt-click', href: '/page', event: { altKey: true }, expected: ignored('modified-click') },
|
|
59
|
-
{ name: 'middle button', href: '/page', event: { button: 1 }, expected: ignored('non-left-click') },
|
|
60
|
-
{ name: 'right button', href: '/page', event: { button: 2 }, expected: ignored('non-left-click') },
|
|
61
|
-
{ name: 'target _blank', href: '/page', attributes: { target: '_blank' }, expected: ignored('external-target') },
|
|
62
|
-
{ name: 'target _parent', href: '/page', attributes: { target: '_parent' }, expected: ignored('external-target') },
|
|
63
|
-
{ name: 'target _top', href: '/page', attributes: { target: '_top' }, expected: ignored('external-target') },
|
|
64
|
-
{ name: 'download', href: '/export', attributes: { download: '' }, expected: ignored('download') },
|
|
65
|
-
{
|
|
66
|
-
name: 'download with a file name',
|
|
67
|
-
href: '/export',
|
|
68
|
-
attributes: { download: 'report.csv' },
|
|
69
|
-
expected: ignored('download'),
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: 'reload attribute',
|
|
73
|
-
href: '/logout',
|
|
74
|
-
attributes: { 'data-eco-reload': '' },
|
|
75
|
-
expected: ignored('explicit-reload'),
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: 'custom reload attribute',
|
|
79
|
-
href: '/logout',
|
|
80
|
-
attributes: { 'data-full-reload': '' },
|
|
81
|
-
options: { reloadAttribute: 'data-full-reload' },
|
|
82
|
-
expected: ignored('explicit-reload'),
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: 'no-prefetch attribute',
|
|
86
|
-
href: '/page',
|
|
87
|
-
attributes: { 'data-eco-no-prefetch': '' },
|
|
88
|
-
expected: ignored('no-prefetch'),
|
|
89
|
-
},
|
|
90
|
-
{ name: 'hash-only link', href: '#section', expected: ignored('invalid-href') },
|
|
91
|
-
{ name: 'javascript: link', href: 'javascript:void(0)', expected: ignored('invalid-href') },
|
|
92
|
-
{ name: 'anchor without href', href: null, expected: ignored('invalid-href') },
|
|
93
|
-
{ name: 'external site', href: 'https://example.com/page', expected: ignored('cross-origin') },
|
|
94
|
-
{ name: 'same host on another port', href: 'http://localhost:9999/page', expected: ignored('cross-origin') },
|
|
95
|
-
{ name: 'mailto: link', href: 'mailto:test@example.com', expected: ignored('cross-origin') },
|
|
96
|
-
{ name: 'tel: link', href: 'tel:+1234567890', expected: ignored('cross-origin') },
|
|
97
|
-
{ name: 'text static asset', href: '/skill.txt', expected: ignored('static-asset') },
|
|
98
|
-
{ name: 'nested markdown asset', href: '/skill/reference/full-stack.md', expected: ignored('static-asset') },
|
|
99
|
-
{ name: 'llms.txt', href: '/llms.txt', expected: ignored('static-asset') },
|
|
100
|
-
{
|
|
101
|
-
name: 'fragment of the current page',
|
|
102
|
-
href: '/docs/page#section',
|
|
103
|
-
pathname: '/docs/page',
|
|
104
|
-
expected: ignored('same-page-hash'),
|
|
105
|
-
},
|
|
106
|
-
];
|
|
107
|
-
describe('getLinkNavigationDecision', () => {
|
|
108
|
-
it.each(decisionRows)('$name', ({ href, attributes, event, options, pathname, expected }) => {
|
|
109
|
-
if (pathname)
|
|
110
|
-
history.replaceState({}, '', pathname);
|
|
111
|
-
const link = createLink(href, attributes);
|
|
112
|
-
expect(getLinkNavigationDecision(createMouseEvent(event), link, { ...policy, ...options })).toEqual(expected);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe('getNavigableHrefFromClick', () => {
|
|
116
|
-
it('returns the href of an intercepted click and null for an ignored one', () => {
|
|
117
|
-
expect(getNavigableHrefFromClick(createMouseEvent(), createLink('/page'), policy)).toBe('/page');
|
|
118
|
-
expect(getNavigableHrefFromClick(createMouseEvent(), createLink('/llms.txt'), policy)).toBeNull();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
describe('isSamePageHashNavigationHref', () => {
|
|
122
|
-
it('returns true for the current page with a fragment', () => {
|
|
123
|
-
history.replaceState({}, '', '/docs/page');
|
|
124
|
-
expect(isSamePageHashNavigationHref('/docs/page#section')).toBe(true);
|
|
125
|
-
expect(isSamePageHashNavigationHref('/docs/page')).toBe(false);
|
|
126
|
-
expect(isSamePageHashNavigationHref('/docs/other#section')).toBe(false);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
describe('shouldPrefetchLink', () => {
|
|
130
|
-
const rows = [
|
|
131
|
-
{ name: 'internal page link', href: '/docs/intro', expected: true },
|
|
132
|
-
{ name: 'static asset', href: '/skill.txt', expected: false },
|
|
133
|
-
{ name: 'no-prefetch opt-out', href: '/page', attributes: { 'data-eco-no-prefetch': '' }, expected: false },
|
|
134
|
-
{ name: 'reload link', href: '/logout', attributes: { 'data-eco-reload': '' }, expected: false },
|
|
135
|
-
{ name: 'cross-origin link', href: 'https://example.com/page', expected: false },
|
|
136
|
-
{ name: 'download', href: '/export', attributes: { download: '' }, expected: false },
|
|
137
|
-
{ name: 'current page', href: '/', expected: false },
|
|
138
|
-
];
|
|
139
|
-
it.each(rows)('$name', ({ href, attributes, expected }) => {
|
|
140
|
-
expect(shouldPrefetchLink(createLink(href, attributes), policy)).toBe(expected);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { ECO_NAVIGATION_LIFECYCLE_EVENTS } from './navigation-lifecycle.js';
|
|
3
|
-
import { commitNavigationPage } from './navigation-pipeline.js';
|
|
4
|
-
function parseDocument(html) {
|
|
5
|
-
return new DOMParser().parseFromString(html, 'text/html');
|
|
6
|
-
}
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
document.head.replaceChildren();
|
|
9
|
-
document.body.replaceChildren();
|
|
10
|
-
});
|
|
11
|
-
describe('commitNavigationPage', () => {
|
|
12
|
-
it('runs shared document work around the router-provided swap', async () => {
|
|
13
|
-
document.head.innerHTML = '<title>Current</title>';
|
|
14
|
-
document.body.innerHTML = '<main>Current page</main>';
|
|
15
|
-
const beforeSwap = vi.fn();
|
|
16
|
-
const afterSwap = vi.fn();
|
|
17
|
-
const pageLoad = vi.fn();
|
|
18
|
-
const order = [];
|
|
19
|
-
document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, beforeSwap);
|
|
20
|
-
document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.AFTER_SWAP, afterSwap);
|
|
21
|
-
document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.PAGE_LOAD, pageLoad);
|
|
22
|
-
try {
|
|
23
|
-
const result = await commitNavigationPage({
|
|
24
|
-
url: new URL('https://example.test/next'),
|
|
25
|
-
direction: 'forward',
|
|
26
|
-
newDocument: parseDocument('<html><head><title>Next</title><script id="next-script">window.__next_script_runs__=1</script></head><body><main>Next page</main></body></html>'),
|
|
27
|
-
isStale: () => false,
|
|
28
|
-
viewTransitionsEnabled: false,
|
|
29
|
-
beforeTransition: () => {
|
|
30
|
-
order.push('prepare');
|
|
31
|
-
},
|
|
32
|
-
beforeCommit: () => {
|
|
33
|
-
order.push('history');
|
|
34
|
-
},
|
|
35
|
-
swap: () => {
|
|
36
|
-
order.push('swap');
|
|
37
|
-
document.body.innerHTML = '<main>Next page</main>';
|
|
38
|
-
},
|
|
39
|
-
onSwapped: () => {
|
|
40
|
-
order.push('owner');
|
|
41
|
-
},
|
|
42
|
-
afterSwap: () => {
|
|
43
|
-
order.push('scroll');
|
|
44
|
-
expect(document.head.querySelector('#next-script')).not.toBeNull();
|
|
45
|
-
},
|
|
46
|
-
afterLifecycle: () => {
|
|
47
|
-
order.push('after-lifecycle');
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
expect(result).toBe('committed');
|
|
51
|
-
expect(order).toEqual(['prepare', 'history', 'swap', 'owner', 'scroll', 'after-lifecycle']);
|
|
52
|
-
expect(document.title).toBe('Next');
|
|
53
|
-
expect(document.body.textContent).toContain('Next page');
|
|
54
|
-
expect(beforeSwap).toHaveBeenCalledOnce();
|
|
55
|
-
expect(afterSwap).toHaveBeenCalledOnce();
|
|
56
|
-
await vi.waitFor(() => expect(pageLoad).toHaveBeenCalledOnce());
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, beforeSwap);
|
|
60
|
-
document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.AFTER_SWAP, afterSwap);
|
|
61
|
-
document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.PAGE_LOAD, pageLoad);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
it('runs the body scripts that wait on a head script after the navigation completes', async () => {
|
|
65
|
-
document.head.innerHTML = '<title>Current</title>';
|
|
66
|
-
document.body.innerHTML = '<main>Current page</main>';
|
|
67
|
-
let completed = false;
|
|
68
|
-
const win = window;
|
|
69
|
-
try {
|
|
70
|
-
await commitNavigationPage({
|
|
71
|
-
url: new URL('https://example.test/next'),
|
|
72
|
-
direction: 'forward',
|
|
73
|
-
newDocument: parseDocument('<html><head><title>Next</title><script src="data:text/javascript,window.__head_first__=1"></script></head><body><main>Next page</main><script>window.__body_saw_head__=window.__head_first__</script></body></html>'),
|
|
74
|
-
isStale: () => completed,
|
|
75
|
-
viewTransitionsEnabled: false,
|
|
76
|
-
swap: () => {
|
|
77
|
-
document.body.innerHTML =
|
|
78
|
-
'<main>Next page</main><script>window.__body_saw_head__=window.__head_first__</script>';
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
completed = true;
|
|
82
|
-
await vi.waitFor(() => expect(win.__body_saw_head__).toBe(1));
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
delete win.__head_first__;
|
|
86
|
-
delete win.__body_saw_head__;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
it('does not prepare or swap a page after a before-swap listener requests reload', async () => {
|
|
90
|
-
document.title = 'Current';
|
|
91
|
-
const reloadRequested = vi.fn();
|
|
92
|
-
const swap = vi.fn();
|
|
93
|
-
const handleBeforeSwap = (event) => {
|
|
94
|
-
event.detail.reload();
|
|
95
|
-
};
|
|
96
|
-
document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, handleBeforeSwap);
|
|
97
|
-
try {
|
|
98
|
-
const result = await commitNavigationPage({
|
|
99
|
-
url: new URL('https://example.test/reload'),
|
|
100
|
-
direction: 'forward',
|
|
101
|
-
newDocument: parseDocument('<html><head><title>Next</title></head><body></body></html>'),
|
|
102
|
-
isStale: () => false,
|
|
103
|
-
viewTransitionsEnabled: false,
|
|
104
|
-
onReloadRequested: reloadRequested,
|
|
105
|
-
swap,
|
|
106
|
-
});
|
|
107
|
-
expect(result).toBe('reload-requested');
|
|
108
|
-
expect(reloadRequested).toHaveBeenCalledOnce();
|
|
109
|
-
expect(swap).not.toHaveBeenCalled();
|
|
110
|
-
expect(document.title).toBe('Current');
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, handleBeforeSwap);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { clearNavigationHtmlCache, fetchNavigationPage, invalidateNavigationHtml, parseNavigationDocument, } from './navigation-document.js';
|
|
3
|
-
afterEach(() => {
|
|
4
|
-
clearNavigationHtmlCache();
|
|
5
|
-
vi.unstubAllGlobals();
|
|
6
|
-
});
|
|
7
|
-
describe('shared navigation document loading', () => {
|
|
8
|
-
it('checks HTML status, keeps the fragment through redirects, and resolves the incoming base', async () => {
|
|
9
|
-
const response = new Response('<html><head><base href="../assets/"></head><body></body></html>', {
|
|
10
|
-
headers: { 'Content-Type': 'text/html; charset=utf-8' },
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(response, 'url', { value: 'https://example.test/docs/current/' });
|
|
13
|
-
const fetchMock = vi.fn(async () => response);
|
|
14
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
15
|
-
const page = await fetchNavigationPage('https://example.test/old/page#install');
|
|
16
|
-
expect(fetchMock).toHaveBeenCalledWith('https://example.test/old/page', expect.objectContaining({ headers: { Accept: 'text/html' } }));
|
|
17
|
-
expect(page?.finalUrl.href).toBe('https://example.test/docs/current/#install');
|
|
18
|
-
expect(page?.document.querySelector('base')?.href).toBe('https://example.test/docs/assets/');
|
|
19
|
-
});
|
|
20
|
-
it('shares cached HTML and the redirect target across router loads', async () => {
|
|
21
|
-
const response = new Response('<html><head></head><body></body></html>', {
|
|
22
|
-
headers: { 'Content-Type': 'text/html' },
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(response, 'url', { value: 'https://example.test/docs/' });
|
|
25
|
-
const fetchMock = vi.fn(async () => response);
|
|
26
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
27
|
-
const firstPage = await fetchNavigationPage('https://example.test/old/#one');
|
|
28
|
-
const cachedPage = await fetchNavigationPage('https://example.test/old/#two');
|
|
29
|
-
expect(fetchMock).toHaveBeenCalledOnce();
|
|
30
|
-
expect(firstPage?.finalUrl.href).toBe('https://example.test/docs/#one');
|
|
31
|
-
expect(cachedPage?.finalUrl.href).toBe('https://example.test/docs/#two');
|
|
32
|
-
});
|
|
33
|
-
it('invalidates every requested URL that redirected to the same page', async () => {
|
|
34
|
-
const fetchMock = vi.fn(async () => {
|
|
35
|
-
const response = new Response('<html><head></head><body></body></html>', {
|
|
36
|
-
headers: { 'Content-Type': 'text/html' },
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(response, 'url', { value: 'https://example.test/b' });
|
|
39
|
-
return response;
|
|
40
|
-
});
|
|
41
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
42
|
-
await fetchNavigationPage('https://example.test/a');
|
|
43
|
-
invalidateNavigationHtml('https://example.test/b');
|
|
44
|
-
await fetchNavigationPage('https://example.test/a');
|
|
45
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
46
|
-
});
|
|
47
|
-
it('refetches when the cache is bypassed', async () => {
|
|
48
|
-
const fetchMock = vi.fn(async () => new Response('<html></html>', { headers: { 'Content-Type': 'text/html' } }));
|
|
49
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
50
|
-
await fetchNavigationPage('https://example.test/page');
|
|
51
|
-
await fetchNavigationPage('https://example.test/page', { bypassCache: true });
|
|
52
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
53
|
-
});
|
|
54
|
-
it('passes low fetch priority through for prefetch requests', async () => {
|
|
55
|
-
const response = new Response('<html><head></head><body></body></html>', {
|
|
56
|
-
headers: { 'Content-Type': 'text/html' },
|
|
57
|
-
});
|
|
58
|
-
const fetchMock = vi.fn(async () => response);
|
|
59
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
60
|
-
await fetchNavigationPage('https://example.test/prefetched', { priority: 'low' });
|
|
61
|
-
expect(fetchMock).toHaveBeenCalledWith('https://example.test/prefetched', expect.objectContaining({ priority: 'low' }));
|
|
62
|
-
});
|
|
63
|
-
it('rejects non-HTML and non-success responses', async () => {
|
|
64
|
-
const fetchMock = vi
|
|
65
|
-
.fn()
|
|
66
|
-
.mockResolvedValueOnce(new Response('missing', { status: 404, headers: { 'Content-Type': 'text/html' } }))
|
|
67
|
-
.mockResolvedValueOnce(new Response('{}', { headers: { 'Content-Type': 'application/json' } }));
|
|
68
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
69
|
-
expect(await fetchNavigationPage('https://example.test/missing')).toBeNull();
|
|
70
|
-
expect(await fetchNavigationPage('https://example.test/data')).toBeNull();
|
|
71
|
-
});
|
|
72
|
-
it('adds a temporary base only when the page has none', () => {
|
|
73
|
-
const document = parseNavigationDocument('<html><head></head><body><a href="child">Child</a></body></html>', new URL('https://example.test/docs/'));
|
|
74
|
-
expect(document.querySelector('base[data-eco-injected]')?.href).toBe('https://example.test/docs/');
|
|
75
|
-
expect(document.querySelector('a')?.getAttribute('href')).toBe('child');
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|