Skip to content

Commit d7212b1

Browse files
committed
Merge main.
2 parents 7a0b219 + d5fff54 commit d7212b1

7 files changed

Lines changed: 37 additions & 15 deletions

File tree

‎docs/guide/edge/revalidation.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,18 @@ You can purge ISR cache entries programmatically from a route handler:
121121
```ts
122122
import { defineHandler } from 'void';
123123
import { revalidate } from 'void/isr';
124-
import type { RouteUrl } from 'void/routes';
125124

126125
export const POST = defineHandler(async (c) => {
127126
// ... update content in database ...
128127

129-
// Purge specific pages. `satisfies RouteUrl[]` checks the paths when routing.typedRoutes is on.
130-
await revalidate({ paths: ['/', '/blog/hello-world'] satisfies RouteUrl[] });
128+
// Purge specific pages
129+
await revalidate({ paths: ['/', '/blog/hello-world'] });
131130

132131
// Or purge all cached pages
133132
await revalidate({ all: true });
134133

135134
return c.json({ ok: true });
136135
});
137136
```
137+
138+
With [`routing.typedRoutes`](../../reference/config.md#routing-typedroutes) on, each path must match one of your routes. Cast a path that TypeScript can't check, such as one from a webhook payload, with `as RouteUrl` from `void/routes`. The cast turns the check off for that path.

‎docs/guide/type-safety.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,21 @@ export async function getPrerenderPaths(): Promise<PageParams<'/blog/:slug'>[]>
247247

248248
In custom SSR mode the function returns full path strings, so annotate it as `Promise<string[]>`. See [Edge Prerendering](./edge/prerendering.md#dynamic-pages-with-params) and [Static Site Generation](./ssg.md#per-page-overrides).
249249

250-
`revalidate({ paths })` and `routing.prerender` are lists of plain strings. Annotate the array with `satisfies RouteUrl[]` so each path has to match a route. The check applies when [`routing.typedRoutes`](../reference/config.md#routing-typedroutes) is on; otherwise `RouteUrl` is `string`:
250+
`routing.prerender` is a list of plain strings. Annotate the array with `satisfies RouteUrl[]` so each path has to match a route. The check applies when [`routing.typedRoutes`](../reference/config.md#routing-typedroutes) is on; otherwise `RouteUrl` is `string`:
251251

252252
```ts
253+
// void.config.ts
254+
import { defineConfig } from 'void/config';
253255
import type { RouteUrl } from 'void/routes';
254256

255-
await revalidate({ paths: ['/', '/blog/hello-world'] satisfies RouteUrl[] });
257+
export default defineConfig({
258+
routing: { prerender: ['/', '/blog/hello-world'] satisfies RouteUrl[] },
259+
});
256260
```
257261

258262
### Checked URL strings
259263

260-
[`routing.typedRoutes`](../reference/config.md#routing-typedroutes) checks plain URL strings in `Link`'s `href`, `router.visit()`, `router.prefetch()`, `router.flush()`, `c.rewrite()`, `c.redirect()`, `connectEventStream()`, `connectLiveStream()`, and `useIslandForm()`'s `post()`, `put()`, `patch()`, `delete()`, and `submit()`. Apps created with `void init` have it on. To turn it on in an existing app:
264+
[`routing.typedRoutes`](../reference/config.md#routing-typedroutes) checks plain URL strings in `Link`'s `href`, `router.visit()`, `router.prefetch()`, `router.flush()`, `c.rewrite()`, `c.redirect()`, `revalidate({ paths })`, `connectEventStream()`, `connectLiveStream()`, and `useIslandForm()`'s `post()`, `put()`, `patch()`, `delete()`, and `submit()`. Apps created with `void init` have it on. To turn it on in an existing app:
261265

262266
```ts
263267
// void.config.ts
@@ -346,10 +350,10 @@ The cast turns the check off, so cast only URLs you trust. Check a URL from the
346350

347351
`void/routes` exports two types for these strings:
348352

349-
- `RouteUrl`: the URL of one of your routes. `routeUrl()` returns it, and `c.rewrite()` and `useIslandForm()` accept it. Annotate a prerender or revalidate path list with it.
353+
- `RouteUrl`: the URL of one of your routes. `routeUrl()` returns it, and `c.rewrite()`, `useIslandForm()`, and `revalidate({ paths })` accept it. Annotate a `routing.prerender` list with it.
350354
- `Href`: anything a link or `c.redirect()` can point to: a `RouteUrl`, a same-page query or hash, or an external URL.
351355

352-
Cast a string that TypeScript can't check, such as a path from your CMS or a file in `public/`. The cast skips the check, so a wrong path still compiles:
356+
Cast a string that TypeScript can't check, such as a path from your CMS or a file in `public/`. The cast turns the check off for that string:
353357

354358
::: code-group
355359

@@ -416,7 +420,8 @@ Route types update with the dev server. For CI or standalone typechecking, run `
416420
| `useParams` | Page patterns and the names of the params they return |
417421
| `c.req.param` | Page param names, when the result is annotated with `PageParams` |
418422
| `getPrerenderPaths` | Page param names, when the return type is annotated with `PageParams` |
419-
| `revalidate` | `paths`, and `routing.prerender`, when the array is annotated with `satisfies RouteUrl[]` |
423+
| `revalidate` | With `routing.typedRoutes`, URL strings in `paths` |
424+
| `routing.prerender` | Paths, when the array is annotated with `satisfies RouteUrl[]` |
420425
| `useForm` | Action URLs, `data` fields, `errors` keys, `reset()` args (including `{ initial: true }`), `params`, `resetOnSuccess` |
421426
| `action()` | Action URLs, `data` payload, `params` |
422427

‎docs/reference/api/resources.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,17 @@ Revalidate ISR-cached pages on demand. In local development this is a no-op beca
104104

105105
```ts
106106
import { revalidate } from 'void/isr';
107-
import type { RouteUrl } from 'void/routes';
108107

109-
await revalidate({ paths: ['/', '/blog/hello'] satisfies RouteUrl[] });
108+
await revalidate({ paths: ['/', '/blog/hello'] });
110109
await revalidate({ all: true });
111110
```
112111

113-
`paths` is `string[]`. Annotate the array with `satisfies RouteUrl[]` so TypeScript checks each path when [`routing.typedRoutes`](../config.md#routing-typedroutes) is on.
112+
With [`routing.typedRoutes`](../config.md#routing-typedroutes) on, each path in `paths` must match one of your routes; otherwise `RouteUrl` is `string`. Cast a path that TypeScript can't check with `as RouteUrl`. The cast turns the check off for that path.
114113

115114
**Signature:**
116115

117116
```ts
118-
function revalidate(options: { paths?: string[]; all?: boolean }): Promise<void>;
117+
function revalidate(options: { paths?: RouteUrl[]; all?: boolean }): Promise<void>;
119118
```
120119

121120
## Logging {#logging}

‎docs/reference/config.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ routing: {
378378

379379
#### `routing.typedRoutes`
380380

381-
Type-check URL strings against your app's routes in `Link`'s `href`, `router.visit()`, `router.prefetch()`, `router.flush()`, `c.rewrite()`, `c.redirect()`, `useIslandForm()`, `connectEventStream()`, and `connectLiveStream()`. Omitted or `false` means off; `void init` turns it on for new apps. It changes types only, not navigation at runtime. Link and router strings may also be same-page queries or hashes, or `http://`, `https://`, `mailto:`, and `tel:` URLs. `useIslandForm()` takes a route URL; `connectEventStream()` and `connectLiveStream()` also take `http://` and `https://` URLs. `c.redirect()` accepts those strings, a `URL`, or a destination object. An external `https://` literal needs no cast; cast a string TypeScript cannot check with `as Href`. `revalidate({ paths })` and `routing.prerender` stay plain strings until you annotate them. See [Checked URL strings](../guide/type-safety#checked-url-strings).
381+
Type-check URL strings against your app's routes in `Link`'s `href`, `router.visit()`, `router.prefetch()`, `router.flush()`, `c.rewrite()`, `c.redirect()`, `useIslandForm()`, `revalidate({ paths })`, `connectEventStream()`, and `connectLiveStream()`. Omitted or `false` means off; `void init` turns it on for new apps. It changes types only, not navigation at runtime. Link and router strings may also be same-page queries or hashes, or `http://`, `https://`, `mailto:`, and `tel:` URLs. `useIslandForm()` and `revalidate({ paths })` take route URLs; `connectEventStream()` and `connectLiveStream()` also take `http://` and `https://` URLs. `c.redirect()` accepts those strings, a `URL`, or a destination object. An external `https://` literal needs no cast; cast a string TypeScript cannot check with `as Href`. `routing.prerender` takes plain strings unless you annotate them. See [Checked URL strings](../guide/type-safety#checked-url-strings).
382382

383383
```ts
384384
routing: {

‎packages/void/src/runtime/isr.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import {
66
isrVariantPrefix,
77
listIsrHosts,
88
} from '@void/isr/runtime';
9+
import type { RouteUrl } from 'void/routes';
910
import { getRawRuntimeEnv } from './env-raw.ts';
1011

1112
export type RevalidateOptions = {
12-
paths?: Array<string>;
13+
/** Paths to purge. Checked against the app's routes when `routing.typedRoutes` is on. */
14+
paths?: Array<RouteUrl>;
1315
all?: boolean;
1416
};
1517

‎packages/void/test/integration/route-url-builder.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { routeUrl, type Href, type RouteUrl } from 'void/routes';
3030
import { defineConfig } from 'void/config';
3131
import type { VoidRouter } from 'void/pages-client';
3232
import { defineHandler, defineMiddleware, type CloudContext } from 'void/handler';
33+
import { revalidate } from 'void/isr';
3334
import { connectLiveStream } from 'void/live/client';
3435
import { connectEventStream } from 'void/sse/client';
3536
import type { IslandFormState } from 'void/pages-client';
@@ -126,6 +127,13 @@ defineMiddleware(async (c, next) => {
126127
if (!getCookie(c, 'session')) return c.redirect('/about');
127128
await next();
128129
});
130+
void revalidate({ paths: ['/', '/about', \`/users/\${id}\`, user] });
131+
// @ts-expect-error revalidated paths are checked
132+
void revalidate({ paths: ['/unknown'] });
133+
declare const stored: string[];
134+
// @ts-expect-error unchecked string arrays are rejected
135+
void revalidate({ paths: stored });
136+
void revalidate({ paths: stored as RouteUrl[] });
129137
connectEventStream('/api/legacy');
130138
connectEventStream(\`/api/users/\${id}\`);
131139
connectEventStream(user);

‎packages/void/test/unit/typed-navigation.typecheck.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type CloudContext,
1616
type CloudEnv,
1717
} from '../../src/runtime/handler.ts';
18+
import { revalidate } from '../../src/runtime/isr.ts';
1819
import { connectLiveStream } from '../../src/runtime/live-client.ts';
1920
import { connectEventStream } from '../../src/runtime/sse-client.ts';
2021

@@ -119,6 +120,12 @@ export function checkUntypedRouteStrings(): void {
119120
expectTypeOf(routeUrl('/typed-navigation')).toEqualTypeOf<string>();
120121
}
121122

123+
// Without routing.typedRoutes, revalidated paths are plain strings.
124+
export async function checkUntypedRevalidatePaths(paths: Array<string>): Promise<void> {
125+
await revalidate({ paths });
126+
await revalidate({ paths: ['/unknown'] });
127+
}
128+
122129
export function checkUntypedStreamUrls(url: string): void {
123130
expectTypeOf<Parameters<typeof connectEventStream>[0]>().toEqualTypeOf<string | URL>();
124131
expectTypeOf<Parameters<typeof connectLiveStream>[0]>().toEqualTypeOf<string | URL>();

0 commit comments

Comments
 (0)