Skip to content

Commit a86f711

Browse files
authored
fix(router): review follow-ups — #567 dual-mode e2e, #569 pre-1.0 API decisions, #570 cleanup (#573)
* test(router): dual-mode e2e for prerender+loading()+passthrough (M16) and redirect under loading() (M9) Adds the dev + production e2e fixtures the M16/M9 unit-tested fixes still lacked (CLAUDE.md mandates dual-mode coverage). Deferred from the stabilization PR; addresses the two main gaps in #567. - prerender-loading: Prerender + loading() + ctx.passthrough(). The loading() boundary defers the build handler so the passthrough sentinel arrives Promise-wrapped; detectPrerenderPassthrough awaits it. getParams lists [baked, skip]: baked is prerendered, skip passes through to the live handler. Production asserts the manifest holds baked but NOT skip (M16 regression guard: count === 1; without the fix skip would bake a corrupt artifact). - loading-redirect: a synchronous redirect() return under loading() short-circuits to a real HTTP redirect. Verified for hard + soft navigation in both modes. Regenerated router.named-routes.gen.ts for the two new includes (urls.gen.ts is legacy/unreferenced and no longer auto-generated, so left untouched). Lower-priority #567 gaps (build-time intercept _currentSegmentId handle drop, server-action-bridge pre-dispatch over-invalidation, document-cache private+s-maxage) need fixes first and are deferred; #567 stays open for them. * chore(router): safe cleanup batch from review (#570) Internal-only, behavior-preserving cleanups; grep-verified safe and gate-green (typecheck, full unit suite, lint, format). - Remove write-only MiddlewareEntry.mountPrefix (read nowhere; scoping folds into fullPattern before the entry is built). Dropped 3 production assignments plus the test fixtures. - Dedupe cookie helpers: delete the test-only middleware-cookies.ts (byte-for-byte dup of request-context's parseCookiesFromHeader/serializeCookieValue), export the canonical copies from request-context for the unit tests, drop the middleware.ts re-export. - Delete the zero-importer src/handles/index.ts barrel (Meta/MetaTags/Breadcrumbs are exported directly from the client/index entries); repoint collect-handle.test. - Drop the MiddlewareCollectableEntry re-export from middleware.ts; its one importer now imports from middleware-types. - Extract hasContextVars() into context-var.ts and use it in the two prerender entry points that duplicated the keys-or-symbols predicate. - renderStaticSegment: throw a TypeError when a Static handler returns a Response (was silently serialized as a corrupt build artifact); the fresh/revalidation paths already throw via handleHandlerResult. Adds a unit test. - ctx.reverse() middleware fallback: widen the signature to (name, params?, search?) to match ScopedReverseFunction and make the error message accurate. - docs: tree-structure.md inTransitionScope also covers error/notFound segments. Deferred, still open in #570: the optionalParams all-or-nothing removal and the loaderPromises param removal both sit on matrix-critical matching/segment-resolution paths and warrant a semantic-matrix run rather than a cleanup sweep. The document-cache "timing-gap caveat" cited at document-cache.ts:45-53 does not exist there (those lines are Cache-Control parsing), so that doc item is a no-op. * feat(router): pre-1.0 public-API surface decisions from review (#569 part 1) Type/naming/export-surface decisions (no behavior change). See #569. - #1 router.use(pattern, mw): add a pattern-generic overload so `.use("/users/:id", (ctx) => ...)` types `ctx.params.id` via ExtractParams. Bare `.use(mw)` stays generic. Added on both Rango and RangoInternal. Pins it with a type-level test (router-use-types.test.ts). - #2 useAction: export a stable public `ActionState` (and `ActionLifecycleState`) from ./client so consumers can name the hook's return type; TrackedActionState stays the @internal impl name (ActionState aliases it). - #4 buildEnv: move off the shared base onto per-preset interfaces. Cloudflare keeps `"auto"` (wrangler getPlatformProxy); Node now rejects `"auto"` at the type level (Exclude<BuildEnvOption,"auto">) instead of only at build time. - #5 poke plugin: rename name "vite-plugin-poke" -> "@rangojs/router:poke" so it matches the @rangojs/router:* family for consumers ordering/filtering by name. - #6 ./build: move realm-crossing pipeline internals (buildRouteTrie, buildPerRouterTrie, TrieNode, TrieLeaf, collectFallbackClientRefs) to a new ./build/internal subpath; ./build keeps the documented public API (generateManifest*, route-type generation, createScanFilter, hashParams). - #8 mergeHandlerUse: document the intentional validation asymmetry (explicit use() items bypass the mount-site allow-list); chosen over enforcing it. Deferred to part 2 (behavior changes): #3 prefetch options, #7 scanFilter wiring, #9 profile-registry trim, #10 redirect-in-action idiom + examples. * feat(router): prefetch source-scope option + redirect-in-action ergonomics (#569 part 2a) - #3 router.prefetch(url, { key: ":source" }): add an options arg so imperative prefetch can source-scope its cache entry, at parity with <Link prefetchKey=":source">. Wired through to prefetchDirect. - #10 redirect() in actions: drop the `as any` on non-form actions by typing them Promise<Response> (saveAndRedirect, actionSimpleRedirect). The form-bound peReturnRedirect keeps a documented intrinsic cast (React's form-action type is () => void | Promise<void>, which can't express a Response return); consumers should prefer `throw redirect(...)`. Strengthened the server-actions skill. Deferred to part 2b: #7 (complete scanFilter — needs a new public plugin option) and #9 (trim profile-registry — runtime cache-resolution refactor). * feat(router): complete scanFilter discovery option + trim profile registry (#569 part 2b) - #7 complete the scanFilter feature. Adds a public rango() option `discovery: { include, exclude }` (glob, root-relative; mirrors the CLI's --include/--exclude). The consume side was already wired (findRouterFiles(state.projectRoot, state.scanFilter) at 3 sites); this threads the option through PluginOptions and compiles it via createScanFilter into state.scanFilter in configResolved, once projectRoot is known. Filters which files route discovery / static type-gen scan. Tests in generate-route-types.test.ts (include restricts, exclude removes). - #9 trim the profile registry. Removed the global mutable `_profiles`, `setCacheProfiles`, and `getCacheProfile` — all dead: `getCacheProfile` had no production reader (its own JSDoc said so), and `setCacheProfiles` only populated the unread global. Kept the load-bearing `resolveCacheProfiles`, which createRouter() already uses to thread a per-request profile map (the "use cache: <profile>" path reads it request-scoped via ctx._cacheProfiles). Dropped the router.ts setCacheProfiles() call; repointed the tests to resolveCacheProfiles (and reframed the "global replace" test as per-router map independence). #569 is now fully implemented (all 10 decisions). * fix(router): keep build internals on ./build (revert #569.6) + throw in return-form redirect actions (#569.10) CI on #573 caught a regression from #569 part 1: the Vite discovery pipeline imports buildRouteTrie / buildPerRouterTrie / collectFallbackClientRefs at build time via runner.import("@rangojs/router/build") (discover-routers.ts), and the RSC runner does not resolve a ./build/internal subpath in that realm. Moving them left collectFallbackClientRefs undefined, so the router-level default error / notFound boundary was never collected into the app-fallback chunk (mini.test.ts clientChunks: "mini-default-error must be in app-fallback"). Revert #569.6: restore buildRouteTrie/buildPerRouterTrie/collectFallbackClientRefs + TrieNode/TrieLeaf on ./build; delete ./build/internal + its package.json export. #569.6 is re-deferred — internalizing these needs runner subpath resolution or a different seam (noted in build/index.ts). #569.10 revision: per owner, the return-form redirect test actions (saveAndRedirect, actionSimpleRedirect) now `throw redirect()` instead of being typed Promise<Response>. The form-bound peReturnRedirect keeps its documented intrinsic cast. Verified: mini clientChunks 6/6, location-state e2e 47/47 (dev+prod), typecheck, 3866 unit, lint, format.
1 parent 1ec8e97 commit a86f711

42 files changed

Lines changed: 560 additions & 184 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/rangojs-router/docs/internal/feature-file-map.md‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎packages/rangojs-router/docs/tree-structure.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ like `useActionState`, refs, and local state. This is extremely hard to debug.
2020

2121
Segment `key` derivation (the per-segment `key` that flows into the
2222
LoaderBoundary/OutletProvider/Suspense keys), gated on `inTransitionScope`
23-
(computed once per render: does any layout/route segment in the matched chain
24-
declare `transition()`):
23+
(computed once per render: does any layout, route, error, or notFound segment
24+
in the matched chain declare `transition()`):
2525
- `route` and route-owned (`belongsToRoute`) `layout` segments use a
2626
param-AGNOSTIC key (`id` only) WHEN `inTransitionScope`; otherwise they keep
2727
a param-BEARING key (`id-params`). The param-agnostic case is the
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { expect, test } from "@playwright/test";
2+
import { useFixture, type Fixture } from "./fixture";
3+
import {
4+
waitForHydration,
5+
expectNoPageError,
6+
testId,
7+
clickAndWaitFor,
8+
} from "./helper";
9+
10+
// redirect() from a loading() route (M9).
11+
//
12+
// A synchronous handler return of redirect() on a loading() route short-circuits
13+
// to a real HTTP redirect before the streamed loading() boundary takes over.
14+
// Verified for both a hard navigation (initial document load) and a soft
15+
// navigation (client-side Link click), in dev and production.
16+
//
17+
// defineTests takes only the fixture so the dev/production mode stays inline in
18+
// each describe (statically visible coupling, no title drift).
19+
function defineTests(f: Fixture) {
20+
test("hard navigation to /sync lands on /target", async ({ page }) => {
21+
using _ = expectNoPageError(page);
22+
23+
await page.goto(f.url("/loading-redirect/sync"));
24+
await waitForHydration(page);
25+
26+
await expect(testId(page, "lr-target")).toBeVisible();
27+
await expect(page).toHaveURL(/\/loading-redirect\/target$/);
28+
});
29+
30+
test("soft navigation (Link click) to /sync lands on /target", async ({
31+
page,
32+
}) => {
33+
using _ = expectNoPageError(page);
34+
35+
await page.goto(f.url("/loading-redirect/"));
36+
await waitForHydration(page);
37+
38+
await clickAndWaitFor(testId(page, "lr-link"), testId(page, "lr-target"));
39+
await expect(page).toHaveURL(/\/loading-redirect\/target$/);
40+
});
41+
}
42+
43+
// -- Dev mode ----------------------------------------------------------------
44+
test.describe("loading redirect (dev mode)", () => {
45+
defineTests(useFixture({ root: "./e2e/test-app", mode: "dev" }));
46+
});
47+
48+
// -- Production build --------------------------------------------------------
49+
test.describe("loading redirect (production build)", () => {
50+
defineTests(useFixture({ root: "./e2e/test-app", mode: "build" }));
51+
});
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { expect, test } from "@playwright/test";
2+
import { useFixture } from "./fixture";
3+
import { waitForHydration, expectNoPageError, testId } from "./helper";
4+
5+
// Prerender + loading() + ctx.passthrough() (M16 regression guard).
6+
//
7+
// The loading() boundary defers the build handler, so ctx.passthrough() arrives
8+
// Promise-wrapped. detectPrerenderPassthrough must await the thenable before the
9+
// synchronous sentinel check; otherwise the "skip" param bakes a corrupt artifact
10+
// at build time instead of deferring to the live Passthrough handler.
11+
//
12+
// getParams() lists [baked, skip]. "baked" is prerendered; "skip" calls
13+
// ctx.passthrough() and renders live (source === "live", ctx.build === false).
14+
15+
// -- Dev mode ----------------------------------------------------------------
16+
// On-demand dev prerender runs the build handler per request. "baked" renders
17+
// from the build handler (ctx.build true); "skip" falls through to the live
18+
// handler exactly as it does at runtime in production.
19+
20+
test.describe("prerender loading (dev mode)", () => {
21+
const f = useFixture({
22+
root: "./e2e/test-app",
23+
mode: "dev",
24+
});
25+
26+
test("baked slug renders the prerendered build handler", async ({ page }) => {
27+
using _ = expectNoPageError(page);
28+
29+
await page.goto(f.url("/prerender-loading/baked"));
30+
await waitForHydration(page);
31+
32+
await expect(testId(page, "prerender-loading-title")).toHaveText("baked");
33+
await expect(testId(page, "prerender-loading-source")).toHaveText("baked");
34+
await expect(testId(page, "prerender-loading-build")).toHaveText("true");
35+
await expect(testId(page, "prerender-loading-dev")).toHaveText("true");
36+
});
37+
38+
test("skip slug passes through to the live handler under loading()", async ({
39+
page,
40+
}) => {
41+
using _ = expectNoPageError(page);
42+
43+
await page.goto(f.url("/prerender-loading/skip"));
44+
await waitForHydration(page);
45+
46+
await expect(testId(page, "prerender-loading-title")).toHaveText("skip");
47+
// ctx.passthrough() deferred to the live handler despite the loading() boundary.
48+
await expect(testId(page, "prerender-loading-source")).toHaveText("live");
49+
await expect(testId(page, "prerender-loading-build")).toHaveText("false");
50+
});
51+
});
52+
53+
// -- Production build --------------------------------------------------------
54+
// "baked" serves a frozen prerender artifact (stable timestamp). "skip" was
55+
// skipped via ctx.passthrough(), so no artifact exists and it renders live
56+
// (changing timestamp). The manifest holds exactly one entry: baked, not skip.
57+
58+
test.describe("prerender loading (production build)", () => {
59+
const f = useFixture({
60+
root: "./e2e/test-app",
61+
mode: "build",
62+
});
63+
64+
test("baked slug serves a frozen prerender artifact", async ({ page }) => {
65+
using _ = expectNoPageError(page);
66+
67+
await page.goto(f.url("/prerender-loading/baked"));
68+
await waitForHydration(page);
69+
70+
await expect(testId(page, "prerender-loading-title")).toHaveText("baked");
71+
await expect(testId(page, "prerender-loading-source")).toHaveText("baked");
72+
await expect(testId(page, "prerender-loading-build")).toHaveText("true");
73+
await expect(testId(page, "prerender-loading-dev")).toHaveText("false");
74+
});
75+
76+
test("baked timestamp is stable across reloads (truly prerendered)", async ({
77+
page,
78+
}) => {
79+
await page.goto(f.url("/prerender-loading/baked"));
80+
await waitForHydration(page);
81+
const ts1 = await testId(page, "prerender-loading-ts").textContent();
82+
83+
await page.reload();
84+
await waitForHydration(page);
85+
const ts2 = await testId(page, "prerender-loading-ts").textContent();
86+
87+
expect(ts1).toBe(ts2);
88+
});
89+
90+
test("skip slug renders live via ctx.passthrough() under loading()", async ({
91+
page,
92+
}) => {
93+
using _ = expectNoPageError(page);
94+
95+
await page.goto(f.url("/prerender-loading/skip"));
96+
await waitForHydration(page);
97+
98+
await expect(testId(page, "prerender-loading-title")).toHaveText("skip");
99+
await expect(testId(page, "prerender-loading-source")).toHaveText("live");
100+
await expect(testId(page, "prerender-loading-build")).toHaveText("false");
101+
});
102+
103+
test("skip timestamp changes across reloads (live, not prerendered)", async ({
104+
page,
105+
}) => {
106+
await page.goto(f.url("/prerender-loading/skip"));
107+
await waitForHydration(page);
108+
const ts1 = await testId(page, "prerender-loading-ts").textContent();
109+
110+
await page.reload();
111+
await waitForHydration(page);
112+
const ts2 = await testId(page, "prerender-loading-ts").textContent();
113+
114+
expect(ts1).not.toBe(ts2);
115+
});
116+
117+
test("manifest holds baked but not skip (M16 regression guard)", async ({
118+
page,
119+
}) => {
120+
const res = await page.request.get(
121+
f.url("/__test/prerender-manifest-entries?route=prerenderLoading.detail"),
122+
);
123+
const data = await res.json();
124+
// Without the fix, "skip" would also be baked (count === 2). With the fix,
125+
// ctx.passthrough() under loading() defers and only "baked" is prerendered.
126+
expect(data.available).toBe(true);
127+
expect(data.count).toBe(1);
128+
});
129+
});

‎packages/rangojs-router/e2e/test-app/src/actions.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ export const StreamingAction = async (_data: FormData) => {
205205
* Tests that server actions can use redirect() with location state.
206206
*/
207207
export async function saveAndRedirect(): Promise<void> {
208-
return redirect("/location-state", {
208+
throw redirect("/location-state", {
209209
state: FlashMessage({ text: "Action saved successfully!" }),
210-
}) as any;
210+
});
211211
}
212212

213213
/**
214214
* Action that redirects without state (pure redirect from action).
215215
*/
216216
export async function actionSimpleRedirect(): Promise<void> {
217-
return redirect("/location-state/target") as any;
217+
throw redirect("/location-state/target");
218218
}
219219

220220
/**
@@ -381,6 +381,11 @@ export async function mwChainAction(): Promise<void> {
381381
* These are form-compatible (accept FormData) so they work with native HTML forms.
382382
*/
383383
export async function peReturnRedirect(_formData: FormData): Promise<void> {
384+
// Bound to a <form action> whose type is (formData) => void | Promise<void>.
385+
// This action deliberately RETURNS a redirect to exercise the runtime path
386+
// that follows a returned Response in PE mode; React's form-action type can't
387+
// express a Response return, so the cast is intrinsic here. Consumers should
388+
// prefer `throw redirect(...)` (see peThrowRedirect), which keeps a void return.
384389
return redirect("/progressive-enhancement") as any;
385390
}
386391

‎packages/rangojs-router/e2e/test-app/src/router.named-routes.gen.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ export const NamedRoutes = {
173173
loadingElementClientTest: "/loading-element-client-test",
174174
loadingFnClientTest: "/loading-fn-client-test",
175175
loadingFnTest: "/loading-fn-test",
176+
"loadingRedirect.index": "/loading-redirect",
177+
"loadingRedirect.sync": "/loading-redirect/sync",
178+
"loadingRedirect.target": "/loading-redirect/target",
176179
"locale.detail": "/:locale/blog/:slug",
177180
"locale.list": "/:locale/blog",
178181
"locationState.index": "/location-state",
@@ -247,6 +250,7 @@ export const NamedRoutes = {
247250
"prerenderCtx.detail": "/prerender-ctx/:slug",
248251
"prerenderIntercept.detail": "/prerender-intercept/:slug",
249252
"prerenderIntercept.index": "/prerender-intercept",
253+
"prerenderLoading.detail": "/prerender-loading/:slug",
250254
"proactiveCache.index": "/proactive-cache",
251255
"proactiveCache.itemA": "/proactive-cache/item-a",
252256
"proactiveCache.itemB": "/proactive-cache/item-b",

‎packages/rangojs-router/e2e/test-app/src/urls.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import { handlerUsePatterns } from "./urls/handler-use.js";
4444
import { parallelLoaderInheritPatterns } from "./urls/parallel-loader-inherit.js";
4545
import { buildSkipPatterns } from "./urls/prerender-build-skip.js";
4646
import { prerenderCtxPatterns } from "./urls/prerender-ctx.js";
47+
import { prerenderLoadingPatterns } from "./urls/prerender-loading.js";
48+
import { loadingRedirectPatterns } from "./urls/loading-redirect.js";
4749
import { reverseAutofillPatterns } from "./urls/reverse-autofill.js";
4850
import { clientReversePatterns } from "./urls/client-reverse.js";
4951
import { useCachePatterns } from "./urls/use-cache.js";
@@ -885,6 +887,18 @@ export const urlpatterns = urls(
885887
// Prerender context test patterns (ctx.build, ctx.set/get, getParams context)
886888
include("/prerender-ctx", prerenderCtxPatterns, { name: "prerenderCtx" }),
887889

890+
// Prerender + loading() + ctx.passthrough() (M16): loading() defers the
891+
// build handler, so the passthrough sentinel arrives Promise-wrapped.
892+
include("/prerender-loading", prerenderLoadingPatterns, {
893+
name: "prerenderLoading",
894+
}),
895+
896+
// redirect() from a loading() route (M9): sync return short-circuits to
897+
// a real HTTP redirect before the streamed loading() boundary takes over.
898+
include("/loading-redirect", loadingRedirectPatterns, {
899+
name: "loadingRedirect",
900+
}),
901+
888902
// Reverse auto-fill test patterns (parameterized include prefix)
889903
include("/reverse-autofill/:tenantId", reverseAutofillPatterns, {
890904
name: "reverseAutofill",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { urls, redirect } from "@rangojs/router";
2+
import { Link } from "@rangojs/router/client";
3+
4+
// redirect() from a loading() route (M9).
5+
//
6+
// A synchronous handler return of redirect() on a loading() route short-circuits
7+
// to a real HTTP redirect before the streamed loading() boundary takes over.
8+
// (An async return of a Response is streamed instead — a documented limitation
9+
// that dev warns about via warnOnStreamedResponse; it produces a degraded render,
10+
// not a navigable outcome, so it is covered by the unit test, not e2e.)
11+
export const loadingRedirectPatterns = urls(({ path, loading }) => [
12+
// Index with a soft-nav Link, so the client navigation path is exercised too.
13+
path(
14+
"/",
15+
() => (
16+
<div data-testid="lr-index">
17+
<Link to="/loading-redirect/sync" data-testid="lr-link">
18+
go sync
19+
</Link>
20+
</div>
21+
),
22+
{ name: "index" },
23+
),
24+
// Synchronous redirect() return under a loading() boundary.
25+
path(
26+
"/sync",
27+
() => redirect("/loading-redirect/target", 302),
28+
{ name: "sync" },
29+
() => [loading(<div data-testid="lr-skeleton">Loading...</div>)],
30+
),
31+
path("/target", () => <div data-testid="lr-target">arrived</div>, {
32+
name: "target",
33+
}),
34+
]);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { urls, Prerender, Passthrough } from "@rangojs/router";
2+
3+
// Prerender + loading() + ctx.passthrough() (M16 regression guard).
4+
//
5+
// The loading() boundary on the route defers the build handler, so its return
6+
// value (including the ctx.passthrough() sentinel) arrives Promise-wrapped.
7+
// detectPrerenderPassthrough must await that thenable before the synchronous
8+
// sentinel check; otherwise the "skip" param bakes a corrupt artifact at build
9+
// time instead of deferring to the live Passthrough handler.
10+
export const PrerenderLoadingDef = Prerender<{ slug: string }>(
11+
async () => [{ slug: "baked" }, { slug: "skip" }],
12+
async (ctx) => {
13+
// skip: defer to the live Passthrough handler, do not bake an artifact.
14+
if (ctx.params.slug === "skip") return ctx.passthrough();
15+
return (
16+
<div data-testid="prerender-loading-page">
17+
<h1 data-testid="prerender-loading-title">{ctx.params.slug}</h1>
18+
<p data-testid="prerender-loading-build">{String(ctx.build)}</p>
19+
<p data-testid="prerender-loading-dev">{String(ctx.dev)}</p>
20+
<p data-testid="prerender-loading-source">baked</p>
21+
<p data-testid="prerender-loading-ts">{Date.now()}</p>
22+
</div>
23+
);
24+
},
25+
{ concurrency: 2 },
26+
);
27+
28+
// Live handler renders skipped/unknown params at runtime (ctx.build === false).
29+
export const PrerenderLoadingTest = Passthrough(
30+
PrerenderLoadingDef,
31+
async (ctx) => (
32+
<div data-testid="prerender-loading-page">
33+
<h1 data-testid="prerender-loading-title">{ctx.params.slug}</h1>
34+
<p data-testid="prerender-loading-build">{String(ctx.build)}</p>
35+
<p data-testid="prerender-loading-dev">{String(ctx.dev)}</p>
36+
<p data-testid="prerender-loading-source">live</p>
37+
<p data-testid="prerender-loading-ts">{Date.now()}</p>
38+
</div>
39+
),
40+
);
41+
42+
export const prerenderLoadingPatterns = urls(({ path, loading }) => [
43+
path("/:slug", PrerenderLoadingTest, { name: "detail" }, () => [
44+
loading(<div data-testid="prerender-loading-skeleton">Loading...</div>),
45+
]),
46+
]);

‎packages/rangojs-router/skills/server-actions/SKILL.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,10 @@ See `/middleware` for the full cross-segment revalidation contract.
465465

466466
`redirect()` works inside actions. Both `return redirect(...)` and
467467
`throw redirect(...)` are supported and behave the same way for the
468-
client. Throwing is clearer when the redirect is conditional.
468+
client. Throwing is clearer when the redirect is conditional, and it keeps
469+
the action's return type narrow (e.g. `Promise<void>`) — `redirect()` returns
470+
a `Response`, so the `return` form needs `Promise<Response>` in the signature.
471+
Prefer `throw redirect(...)`; never cast with `as any`.
469472

470473
```typescript
471474
"use server";

0 commit comments

Comments
 (0)