@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

main
md 86 lines 4.46 KB
Rendered Raw
1 # @fixtures/sveltekit-spa
2
3 E2E fixture for `@alchemy.run/frontend-frameworks/sveltekit` exercising the **pure-SPA path**:
4 `ssr = false` in the root `+layout.ts`, the adapter's SPA fallback page, and —
5 the nuance under test — `+server.ts` endpoints that **still run server-side**
6 even though every page is client-rendered.
7
8 Where `packages/frontend-frameworks/fixtures/sveltekit` is SSR-first, this fixture is the inverse:
9
10 - `src/routes/+layout.ts` sets `ssr = false` / `prerender = false` for the
11 whole app.
12 - `notFoundHandling: "single-page-application"` in `e2e.config.ts` drives the
13 in-memory adapter's fallback generation (`builder.generateFallback` →
14 `index.html`) and must flow through to the deployed assets'
15 `not_found_handling` (mirrored in the miniflare preview's `assetConfig`).
16 - A **real user `vite.config.ts`** registers `sveltekit()` with a user
17 `preprocess` that rewrites a marker rendered by the home page — the file
18 must be loaded natively per the user-config principle. There is
19 deliberately NO `svelte.config.js`: kit v3 hard-errors on
20 its presence ("svelte.config.js is no longer used") — ALL configuration,
21 including Svelte `preprocess`/`compilerOptions`, lives in the
22 `sveltekit(...)` call.
23
24 ## Status: ENABLED
25
26 The user-config wave landed (the real `vite.config.ts` below loads natively)
27 and the worker shim implements the SPA not-found deferral, so the suite runs
28 ungated: `bun run test` calls `playwright test` directly (12 tests, `live` +
29 `dev`).
30
31 ## How the SPA fallback reaches the worker (the deferral contract)
32
33 Upstream `@sveltejs/adapter-cloudflare`'s `worker.js` never defers a 404 to
34 the assets layer — kit's `server.respond` renders its own 404 error page for
35 unmatched routes, and the configured `assets.not_found_handling` only
36 applies to requests the worker never sees. Our shim makes the configured
37 `single-page-application` handling reachable (no new option — see
38 `packages/sveltekit/src/WorkerShim.ts`): when the adapter is built with
39 `notFoundHandling: "single-page-application"`, the shim defers to
40 `env.ASSETS.fetch(req)` — where the asset worker applies
41 `not_found_handling` and serves the generated `index.html` fallback — iff
42
43 - `server.respond` returned **404**, and
44 - the request is **navigation-shaped**: `GET`/`HEAD` with `Accept`
45 containing `text/html`, and
46 - **no kit route pattern matches** the pathname — the most conservative
47 available signal that the 404 is kit's router-level "no route" error
48 (upstream has no deferral semantics to mirror, and kit marks router 404s
49 with no header). Endpoints only exist on matched routes, so intentional
50 endpoint 404s are never deferred; a pattern match whose param matchers
51 fail keeps kit's own 404 page.
52
53 `notFoundHandling: "404-page"` and the default keep exact upstream behavior
54 (no deferral). Observable here: a navigation-shaped request for an unknown
55 path returns the `index.html` shell with **200** in live/preview, while a
56 non-navigation request (no `Accept: text/html`) still gets kit's 404.
57
58 ## What the app exercises
59
60 - **Client-side routing** between three routes (`/`, `/widgets`, `/about`)
61 with a planted `window` marker proving no full navigation occurs.
62 - **Deep links**: a direct request for `/widgets` returns the app shell (no
63 widget markup in the raw HTML — asserted via the `sveltekit-spa-shell`
64 marker in `app.html`) and hydrates into the correct view, in both live and
65 dev.
66 - **Universal load, server endpoint** (`/widgets` + `/api/widgets`): the
67 `+page.ts` load runs exclusively in the browser (`ssr = false`), while the
68 `+server.ts` endpoint it fetches runs server-side and reads a
69 `Text.local` binding (`FIXTURE_MESSAGE`) from `platform.env`.
70 - **SPA fallback / not_found_handling**: an unmatched path
71 (`/definitely/not/a/route`) serves the shell and hydrates into kit's
72 client-side 404 error view (`+error.svelte`).
73 - **Direct static asset** serve (`static/robots.txt`).
74 - **User config honored**: the marker preprocessor (declared in the user's
75 `vite.config.ts` `sveltekit(...)` call) is observable in the rendered app.
76 - **Subpath imports**: the widgets page imports `#lib/widgets.js` through
77 `package.json` `imports` (kit v3's replacement for `$lib`).
78
79 ## Commands
80
81 ```sh
82 bun run dev # kit's Vite dev server via the harness (port 3108)
83 bun run build # kit build + in-memory adapt() + rolldown pass -> dist/build.json
84 bun run preview # miniflare over dist/build.json + .svelte-kit/cloudflare assets
85 bun run test # playwright e2e (live + dev)
86 ```