@krate/runtime 0.5.0-rc.14 → 0.5.0-rc.15
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/dist/action-context.js +5 -1
- package/dist/dev/api.d.ts +93 -0
- package/dist/dev/api.js +2 -0
- package/dist/dev/app.d.ts +165 -0
- package/dist/dev/app.js +1204 -0
- package/dist/dev/commands.d.ts +49 -0
- package/dist/dev/commands.js +114 -0
- package/dist/dev/highlight.d.ts +4 -0
- package/dist/dev/highlight.js +126 -0
- package/dist/dev/icons.d.ts +4 -0
- package/dist/dev/icons.js +57 -0
- package/dist/dev/inspect.d.ts +55 -0
- package/dist/dev/inspect.js +256 -0
- package/dist/dev/inspector.d.ts +39 -0
- package/dist/dev/inspector.js +348 -0
- package/dist/dev/issues.d.ts +83 -0
- package/dist/dev/issues.js +166 -0
- package/dist/dev/modal.d.ts +16 -0
- package/dist/dev/modal.js +836 -0
- package/dist/dev/native.d.ts +53 -0
- package/dist/dev/native.js +95 -0
- package/dist/dev/palette.d.ts +9 -0
- package/dist/dev/palette.js +250 -0
- package/dist/dev/panel.d.ts +31 -0
- package/dist/dev/panel.js +848 -0
- package/dist/dev/requests.d.ts +36 -0
- package/dist/dev/requests.js +150 -0
- package/dist/dev/settings.d.ts +32 -0
- package/dist/dev/settings.js +78 -0
- package/dist/dev/sourcemap.d.ts +22 -0
- package/dist/dev/sourcemap.js +148 -0
- package/dist/dev/stack.d.ts +38 -0
- package/dist/dev/stack.js +115 -0
- package/dist/dev/styles.d.ts +1 -0
- package/dist/dev/styles.js +424 -0
- package/dist/dev/util.d.ts +63 -0
- package/dist/dev/util.js +190 -0
- package/dist/dev-overlay.d.ts +9 -83
- package/dist/dev-overlay.js +17 -1038
- package/dist/island-swap.js +7 -1
- package/dist/krate-core.js +1 -1
- package/dist/krate-dev.js +441 -871
- package/dist/krate-f-list.js +1 -1
- package/dist/krate-f-navigation.js +1 -1
- package/dist/krate-hydrate-lite.js +5 -5
- package/dist/krate-hydrate.js +5 -5
- package/dist/krate-island-swap.js +1 -1
- package/dist/krate-runtime.js +5 -5
- package/dist/list.js +23 -1
- package/dist/metadata.js +23 -12
- package/dist/request-context.d.ts +10 -0
- package/dist/request-context.js +24 -0
- package/dist/server-handler.d.ts +2 -0
- package/dist/server-handler.js +1 -1
- package/dist/server-renderer.js +6 -2
- package/dist/server.js +2 -2
- package/dist/signal.d.ts +8 -0
- package/dist/signal.js +4 -0
- package/dist/ssr-core.d.ts +3 -0
- package/dist/ssr-core.js +44 -5
- package/package.json +1 -1
package/dist/list.js
CHANGED
|
@@ -32,7 +32,29 @@ function keyOf(keyFn, item, i) {
|
|
|
32
32
|
if (!keyFn)
|
|
33
33
|
return String(i);
|
|
34
34
|
const k = keyFn(item, i);
|
|
35
|
-
|
|
35
|
+
if (k == null)
|
|
36
|
+
return String(i);
|
|
37
|
+
if (typeof k === 'object' || typeof k === 'function')
|
|
38
|
+
return objectKey(k);
|
|
39
|
+
return '$' + String(k);
|
|
40
|
+
}
|
|
41
|
+
// Object keys (a DOM node, say) have no useful string form, so they are keyed
|
|
42
|
+
// by identity: a stable id per object.
|
|
43
|
+
let objectIds;
|
|
44
|
+
let nextObjectId = 0;
|
|
45
|
+
let warnedObjectKey = false;
|
|
46
|
+
function objectKey(k) {
|
|
47
|
+
const ids = objectIds || (objectIds = new WeakMap());
|
|
48
|
+
let id = ids.get(k);
|
|
49
|
+
if (id === undefined) {
|
|
50
|
+
id = ++nextObjectId;
|
|
51
|
+
ids.set(k, id);
|
|
52
|
+
}
|
|
53
|
+
if (!warnedObjectKey) {
|
|
54
|
+
warnedObjectKey = true;
|
|
55
|
+
console.error('A list key is a DOM node or object. Use a string or number as the key; Krate keys the row by object identity instead.');
|
|
56
|
+
}
|
|
57
|
+
return '@o' + id;
|
|
36
58
|
}
|
|
37
59
|
function decodeKey(s) {
|
|
38
60
|
try {
|
package/dist/metadata.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// viewport (string), verification, appleWebApp, formatDetection, category,
|
|
15
15
|
// itunes, appLinks, archives, assets, bookmarks and other. metadataBase resolves
|
|
16
16
|
// relative URLs. Anything else is ignored.
|
|
17
|
-
import { httpFallbackStatus, redirectTarget, thenableRecord } from './request-context.js';
|
|
17
|
+
import { httpFallbackStatus, isDynamicUsageError, redirectTarget, thenableRecord } from './request-context.js';
|
|
18
18
|
function isThenable(v) {
|
|
19
19
|
return !!v && typeof v.then === 'function';
|
|
20
20
|
}
|
|
@@ -93,7 +93,7 @@ export async function resolveMetadata(segments, rawProps) {
|
|
|
93
93
|
// notFound(), forbidden(), unauthorized() and redirect() in
|
|
94
94
|
// generateMetadata answer the request; any other error costs only the
|
|
95
95
|
// segment's metadata.
|
|
96
|
-
if (httpFallbackStatus(error) || redirectTarget(error))
|
|
96
|
+
if (httpFallbackStatus(error) || redirectTarget(error) || isDynamicUsageError(error))
|
|
97
97
|
throw error;
|
|
98
98
|
errors.push({ file: seg.file || '', error });
|
|
99
99
|
own = undefined;
|
|
@@ -341,10 +341,21 @@ export function renderMetadataTags(md, templates = {}) {
|
|
|
341
341
|
if (parts.length)
|
|
342
342
|
push(meta('name', 'format-detection', parts.join(', ')));
|
|
343
343
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
344
|
+
// Like Next.js, an openGraph or twitter object without its own title takes
|
|
345
|
+
// the resolved top-level title (already templated); twitter takes the
|
|
346
|
+
// openGraph title and description first. Descriptions are not copied from
|
|
347
|
+
// the top level, so a <Head> description override leaves no stale copy.
|
|
348
|
+
const topTitle = typeof md.title === 'string' ? md.title : '';
|
|
349
|
+
let ogTitle = '';
|
|
350
|
+
if (md.openGraph) {
|
|
351
|
+
ogTitle = titleOf(md.openGraph.title, templates.openGraph) || topTitle;
|
|
352
|
+
renderOpenGraph(md.openGraph, base, ogTitle, md.openGraph.description, push);
|
|
353
|
+
}
|
|
354
|
+
if (md.twitter) {
|
|
355
|
+
const twTitle = titleOf(md.twitter.title, templates.twitter) || ogTitle || topTitle;
|
|
356
|
+
const twDescription = md.twitter.description || md.openGraph?.description;
|
|
357
|
+
renderTwitter(md.twitter, base, twTitle, twDescription, push);
|
|
358
|
+
}
|
|
348
359
|
if (md.appLinks) {
|
|
349
360
|
for (const [platform, entries] of Object.entries(md.appLinks))
|
|
350
361
|
for (const entry of toArray(entries))
|
|
@@ -378,9 +389,9 @@ function renderIcons(icons, base, push) {
|
|
|
378
389
|
emit(o.apple, 'apple-touch-icon');
|
|
379
390
|
emit(o.other, 'icon');
|
|
380
391
|
}
|
|
381
|
-
function renderOpenGraph(og, base,
|
|
382
|
-
push(meta('property', 'og:title',
|
|
383
|
-
push(meta('property', 'og:description',
|
|
392
|
+
function renderOpenGraph(og, base, title, description, push) {
|
|
393
|
+
push(meta('property', 'og:title', title));
|
|
394
|
+
push(meta('property', 'og:description', description));
|
|
384
395
|
push(meta('property', 'og:url', resolveBaseJoin(og.url, base)));
|
|
385
396
|
push(meta('property', 'og:site_name', og.siteName));
|
|
386
397
|
push(meta('property', 'og:locale', og.locale));
|
|
@@ -423,7 +434,7 @@ function renderOpenGraph(og, base, template, push) {
|
|
|
423
434
|
push(meta('property', 'profile:gender', og.gender));
|
|
424
435
|
}
|
|
425
436
|
}
|
|
426
|
-
function renderTwitter(tw, base,
|
|
437
|
+
function renderTwitter(tw, base, title, description, push) {
|
|
427
438
|
const images = imageList(tw.images, base);
|
|
428
439
|
const card = tw.card || (images.length > 0 ? 'summary_large_image' : 'summary');
|
|
429
440
|
push(meta('name', 'twitter:card', card));
|
|
@@ -431,8 +442,8 @@ function renderTwitter(tw, base, template, push) {
|
|
|
431
442
|
push(meta('name', 'twitter:site:id', tw.siteId));
|
|
432
443
|
push(meta('name', 'twitter:creator', tw.creator));
|
|
433
444
|
push(meta('name', 'twitter:creator:id', tw.creatorId));
|
|
434
|
-
push(meta('name', 'twitter:title',
|
|
435
|
-
push(meta('name', 'twitter:description',
|
|
445
|
+
push(meta('name', 'twitter:title', title));
|
|
446
|
+
push(meta('name', 'twitter:description', description));
|
|
436
447
|
for (const img of images) {
|
|
437
448
|
push(meta('name', 'twitter:image', img.url));
|
|
438
449
|
push(meta('name', 'twitter:image:alt', img.alt));
|
|
@@ -16,6 +16,8 @@ export interface RequestContext {
|
|
|
16
16
|
cookies: Map<string, string>;
|
|
17
17
|
params: Record<string, string>;
|
|
18
18
|
searchParams: Record<string, string>;
|
|
19
|
+
/** True during build-time prerendering, where request-only APIs bail out. */
|
|
20
|
+
prerender?: boolean;
|
|
19
21
|
}
|
|
20
22
|
/** The current render request, or undefined outside a server render. */
|
|
21
23
|
export declare function getRequestContext(): RequestContext | undefined;
|
|
@@ -88,3 +90,11 @@ export declare function httpFallbackStatus(err: unknown): 401 | 403 | 404 | 0;
|
|
|
88
90
|
export declare function redirectStatus(err: unknown): 307 | 308;
|
|
89
91
|
/** redirectTarget returns the URL of a redirect() signal, or "" for other errors. */
|
|
90
92
|
export declare function redirectTarget(err: unknown): string;
|
|
93
|
+
/** Thrown when a request-only API is read during build-time prerendering. */
|
|
94
|
+
export interface DynamicUsageError extends Error {
|
|
95
|
+
__krateDynamicUsage: string;
|
|
96
|
+
digest: string;
|
|
97
|
+
}
|
|
98
|
+
export declare function dynamicUsageError(api: string): DynamicUsageError;
|
|
99
|
+
export declare function isDynamicUsageError(err: unknown): err is DynamicUsageError;
|
|
100
|
+
export declare function dynamicUsageReason(err: unknown): string;
|
package/dist/request-context.js
CHANGED
|
@@ -167,3 +167,27 @@ export function redirectTarget(err) {
|
|
|
167
167
|
}
|
|
168
168
|
return '';
|
|
169
169
|
}
|
|
170
|
+
export function dynamicUsageError(api) {
|
|
171
|
+
const err = new Error(`Dynamic server usage: ${api} cannot be used while prerendering a static page`);
|
|
172
|
+
err.__krateDynamicUsage = api;
|
|
173
|
+
err.digest = 'DYNAMIC_SERVER_USAGE';
|
|
174
|
+
return err;
|
|
175
|
+
}
|
|
176
|
+
export function isDynamicUsageError(err) {
|
|
177
|
+
if (!err || typeof err !== 'object')
|
|
178
|
+
return false;
|
|
179
|
+
const e = err;
|
|
180
|
+
if (typeof e.__krateDynamicUsage === 'string' && e.__krateDynamicUsage !== '')
|
|
181
|
+
return true;
|
|
182
|
+
return e.digest === 'DYNAMIC_SERVER_USAGE';
|
|
183
|
+
}
|
|
184
|
+
export function dynamicUsageReason(err) {
|
|
185
|
+
if (!err || typeof err !== 'object')
|
|
186
|
+
return 'dynamic server usage';
|
|
187
|
+
const e = err;
|
|
188
|
+
if (typeof e.__krateDynamicUsage === 'string' && e.__krateDynamicUsage !== '')
|
|
189
|
+
return e.__krateDynamicUsage;
|
|
190
|
+
if (typeof e.message === 'string' && e.message !== '')
|
|
191
|
+
return e.message;
|
|
192
|
+
return 'dynamic server usage';
|
|
193
|
+
}
|
package/dist/server-handler.d.ts
CHANGED
|
@@ -82,6 +82,8 @@ export interface HandlerPage {
|
|
|
82
82
|
segDir?: string;
|
|
83
83
|
/** A segment page that renders per request: reached through its synthetic route, never a URL. */
|
|
84
84
|
segment?: boolean;
|
|
85
|
+
/** Route params of a page expanded from generateStaticParams, whose route is a plain path. */
|
|
86
|
+
params?: Record<string, string>;
|
|
85
87
|
}
|
|
86
88
|
/**
|
|
87
89
|
* A per-request metadata route. `path` is an exact URL; `prefix` and `suffix`
|
package/dist/server-handler.js
CHANGED
|
@@ -368,7 +368,7 @@ export function createKrateHandler(options) {
|
|
|
368
368
|
for (const p of pagesBySpecificity) {
|
|
369
369
|
const params = matchRoutePattern(urlPath, p.route);
|
|
370
370
|
if (params)
|
|
371
|
-
return { page: p, params };
|
|
371
|
+
return { page: p, params: p.params && Object.keys(params).length === 0 ? { ...p.params } : params };
|
|
372
372
|
}
|
|
373
373
|
return null;
|
|
374
374
|
}
|
package/dist/server-renderer.js
CHANGED
|
@@ -330,13 +330,14 @@ function reloadManifest() {
|
|
|
330
330
|
// ISR cache persistence - survives renderer restarts so a bounce doesn't
|
|
331
331
|
// cold-render every ISR variant. Written debounced (coalesced) to the build
|
|
332
332
|
// output dir (.krate/isr-cache.json), overridable via KRATE_ISR_CACHE.
|
|
333
|
+
const PRERENDER_MODE = process.env.KRATE_PRERENDER === "1";
|
|
333
334
|
const isrCacheFile = process.env.KRATE_ISR_CACHE || "";
|
|
334
335
|
let persistTimer = null;
|
|
335
336
|
function isrCachePath() {
|
|
336
337
|
return isrCacheFile || path.join(OUT_DIR, ".krate", "isr-cache.json");
|
|
337
338
|
}
|
|
338
339
|
function persistIsrNow() {
|
|
339
|
-
if (SSR_WORKERS > 1)
|
|
340
|
+
if (PRERENDER_MODE || SSR_WORKERS > 1)
|
|
340
341
|
return;
|
|
341
342
|
if (persistTimer) {
|
|
342
343
|
clearTimeout(persistTimer);
|
|
@@ -355,13 +356,15 @@ function persistIsrNow() {
|
|
|
355
356
|
function scheduleIsrPersist() {
|
|
356
357
|
// Clustered: multiple workers would race on the same cache file; keep the ISR
|
|
357
358
|
// cache in memory only.
|
|
358
|
-
if (SSR_WORKERS > 1)
|
|
359
|
+
if (PRERENDER_MODE || SSR_WORKERS > 1)
|
|
359
360
|
return;
|
|
360
361
|
if (persistTimer)
|
|
361
362
|
clearTimeout(persistTimer);
|
|
362
363
|
persistTimer = setTimeout(persistIsrNow, 1000);
|
|
363
364
|
}
|
|
364
365
|
function loadIsrCache() {
|
|
366
|
+
if (PRERENDER_MODE)
|
|
367
|
+
return;
|
|
365
368
|
try {
|
|
366
369
|
const file = isrCachePath();
|
|
367
370
|
if (fs.existsSync(file)) {
|
|
@@ -544,6 +547,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
544
547
|
params: parsed.params,
|
|
545
548
|
query: parsed.query,
|
|
546
549
|
regions: parsed.regions,
|
|
550
|
+
prerender: !!parsed.prerender,
|
|
547
551
|
};
|
|
548
552
|
const page = findPage(renderReq.route);
|
|
549
553
|
if (!page) {
|
package/dist/server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ATTR_ALIASES } from './htmlspec-attributes.js';
|
|
|
4
4
|
import { withBase } from './base-path.js';
|
|
5
5
|
import { highlight as highlightCode, trimSpace } from './highlight.js';
|
|
6
6
|
import { sealBoundArgs } from './action-seal.js';
|
|
7
|
-
import { accessDeniedStatus, isNotFoundSignal, redirectTarget } from './request-context.js';
|
|
7
|
+
import { accessDeniedStatus, isDynamicUsageError, isNotFoundSignal, redirectTarget } from './request-context.js';
|
|
8
8
|
import { sha256Hex } from './sha256.js';
|
|
9
9
|
import { currentRenderScope, markErrorCaught } from './cache-scope.js';
|
|
10
10
|
import { encodeProp } from './flight-props.js';
|
|
@@ -324,7 +324,7 @@ export class ServerErrorBoundary {
|
|
|
324
324
|
this.props = props;
|
|
325
325
|
}
|
|
326
326
|
static getDerivedStateFromError(error) {
|
|
327
|
-
if (isNotFoundSignal(error) || accessDeniedStatus(error) || redirectTarget(error))
|
|
327
|
+
if (isNotFoundSignal(error) || accessDeniedStatus(error) || redirectTarget(error) || isDynamicUsageError(error))
|
|
328
328
|
throw error;
|
|
329
329
|
return { error: describeBoundaryError(error) };
|
|
330
330
|
}
|
package/dist/signal.d.ts
CHANGED
|
@@ -216,6 +216,8 @@ export type CSSFlagsScope<K extends string> = [
|
|
|
216
216
|
trigger: (flag: K) => Record<string, unknown>;
|
|
217
217
|
panel: (flag: K) => Record<string, unknown>;
|
|
218
218
|
close: () => Record<string, unknown>;
|
|
219
|
+
/** Condition atom for `showIf`: true while `flag` is on. */
|
|
220
|
+
is: (flag: K) => boolean;
|
|
219
221
|
};
|
|
220
222
|
export declare function createCSSFlags<K extends string>(flags: readonly K[], _options?: CSSARIAOptions & {
|
|
221
223
|
vars?: Record<string, Partial<Record<K, string>>>;
|
|
@@ -261,6 +263,12 @@ export type CSSScope<T> = [() => T, (next: T) => void] & {
|
|
|
261
263
|
close: () => Record<string, unknown>;
|
|
262
264
|
/** The current selected value (live, via `--krate-current`). */
|
|
263
265
|
current: () => T;
|
|
266
|
+
/** Condition atom for `showIf`: true while `value` is selected. */
|
|
267
|
+
is: (value: T) => boolean;
|
|
268
|
+
/** Condition atom for a toggle: true while it is on. */
|
|
269
|
+
on: () => boolean;
|
|
270
|
+
/** Negated condition atom for a toggle: true while it is off. */
|
|
271
|
+
off: () => boolean;
|
|
264
272
|
};
|
|
265
273
|
/** Actions destructured from a `createCSSStack` result. */
|
|
266
274
|
export interface CSSStackActions<K extends string> {
|
package/dist/signal.js
CHANGED
|
@@ -571,6 +571,7 @@ export function createCSSFlags(flags, _options) {
|
|
|
571
571
|
scope.trigger = (flag) => ({ 'data-krate-scope': 'trigger', value: flag });
|
|
572
572
|
scope.panel = (flag) => ({ 'data-krate-scope': 'panel', value: flag });
|
|
573
573
|
scope.close = () => ({ 'data-krate-scope': 'close' });
|
|
574
|
+
scope.is = (flag) => getters[flag]?.() ?? false;
|
|
574
575
|
return scope;
|
|
575
576
|
}
|
|
576
577
|
/**
|
|
@@ -595,6 +596,9 @@ function withScopeHelpers(result) {
|
|
|
595
596
|
scope.panel = (value) => ({ 'data-krate-scope': 'panel', value });
|
|
596
597
|
scope.close = () => ({ 'data-krate-scope': 'close' });
|
|
597
598
|
scope.current = () => result[0]();
|
|
599
|
+
scope.is = (value) => result[0]() === value;
|
|
600
|
+
scope.on = () => Boolean(result[0]());
|
|
601
|
+
scope.off = () => !result[0]();
|
|
598
602
|
return scope;
|
|
599
603
|
}
|
|
600
604
|
/**
|
package/dist/ssr-core.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export interface RenderRequest {
|
|
|
47
47
|
id: string;
|
|
48
48
|
kind?: "component" | "page";
|
|
49
49
|
}[];
|
|
50
|
+
prerender?: boolean;
|
|
50
51
|
}
|
|
51
52
|
export type CacheStatus = "hit" | "stale" | "miss";
|
|
52
53
|
export interface RenderResponse {
|
|
@@ -56,6 +57,8 @@ export interface RenderResponse {
|
|
|
56
57
|
notFound?: boolean;
|
|
57
58
|
/** 401 or 403 when the render called unauthorized() or forbidden(). */
|
|
58
59
|
denied?: 401 | 403;
|
|
60
|
+
/** Request-only API that bailed out a build-time prerender. */
|
|
61
|
+
dynamicUsage?: string;
|
|
59
62
|
cached?: boolean;
|
|
60
63
|
cacheStatus?: CacheStatus;
|
|
61
64
|
error?: string;
|
package/dist/ssr-core.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
7
|
import { jsx, renderToStringAsync } from "./server.js";
|
|
8
8
|
import { sha256Hex as portableSha256Hex } from "./sha256.js";
|
|
9
|
-
import { isNotFoundSignal, accessDeniedStatus, parseCookieHeader, redirectTarget, redirectStatus, thenable, thenableRecord, } from "./request-context.js";
|
|
9
|
+
import { isNotFoundSignal, isDynamicUsageError, dynamicUsageError, dynamicUsageReason, accessDeniedStatus, parseCookieHeader, redirectTarget, redirectStatus, thenable, thenableRecord, } from "./request-context.js";
|
|
10
10
|
import { HEAD_CLOSE, HEAD_OPEN, takeHead } from "./head-tags.js";
|
|
11
11
|
import { metadataHeadTags } from "./metadata.js";
|
|
12
12
|
import { SegmentedLRU } from "./segmented-lru.js";
|
|
@@ -370,14 +370,17 @@ export function createSSRCore(opts) {
|
|
|
370
370
|
headers: h,
|
|
371
371
|
cookies: parseCookieHeader(h.get("cookie")),
|
|
372
372
|
params: { ...req.params },
|
|
373
|
-
searchParams: tracker ? trackedQuery(req.query, tracker) : { ...req.query },
|
|
373
|
+
searchParams: req.prerender ? {} : tracker ? trackedQuery(req.query, tracker) : { ...req.query },
|
|
374
|
+
prerender: !!req.prerender,
|
|
374
375
|
};
|
|
375
376
|
}
|
|
376
377
|
function withRequest(req, fn, tracker) {
|
|
377
378
|
return requestStore.run(requestContextFor(req, tracker), fn);
|
|
378
379
|
}
|
|
379
|
-
// renderSignal maps notFound()/redirect() thrown during a render to a response.
|
|
380
|
+
// renderSignal maps notFound()/redirect()/dynamic-usage thrown during a render to a response.
|
|
380
381
|
function renderSignal(err) {
|
|
382
|
+
if (isDynamicUsageError(err))
|
|
383
|
+
return { html: "", status: 200, dynamicUsage: dynamicUsageReason(err) };
|
|
381
384
|
if (isNotFoundSignal(err))
|
|
382
385
|
return { html: "", status: 404, notFound: true };
|
|
383
386
|
const denied = accessDeniedStatus(err);
|
|
@@ -388,6 +391,36 @@ export function createSSRCore(opts) {
|
|
|
388
391
|
return { html: "", status: redirectStatus(err), redirect: to };
|
|
389
392
|
return null;
|
|
390
393
|
}
|
|
394
|
+
// prerenderSearchParams returns a thenable Proxy that throws a dynamic-usage
|
|
395
|
+
// error if page or generateMetadata code reads any key or enumerates it,
|
|
396
|
+
// while letting pages that merely receive props without reading searchParams
|
|
397
|
+
// prerender cleanly.
|
|
398
|
+
function prerenderSearchParams() {
|
|
399
|
+
const makeProxy = () => new Proxy({}, {
|
|
400
|
+
get(obj, prop, recv) {
|
|
401
|
+
if (typeof prop === "string" && prop !== "then" && prop !== "toJSON" && prop !== "constructor") {
|
|
402
|
+
throw dynamicUsageError("searchParams");
|
|
403
|
+
}
|
|
404
|
+
return Reflect.get(obj, prop, recv);
|
|
405
|
+
},
|
|
406
|
+
has(_obj, prop) {
|
|
407
|
+
if (typeof prop === "string" && prop !== "then" && prop !== "toJSON" && prop !== "constructor") {
|
|
408
|
+
throw dynamicUsageError("searchParams");
|
|
409
|
+
}
|
|
410
|
+
return false;
|
|
411
|
+
},
|
|
412
|
+
ownKeys() {
|
|
413
|
+
throw dynamicUsageError("searchParams");
|
|
414
|
+
},
|
|
415
|
+
getOwnPropertyDescriptor(obj, prop) {
|
|
416
|
+
if (typeof prop === "string" && prop !== "then" && prop !== "toJSON" && prop !== "constructor") {
|
|
417
|
+
throw dynamicUsageError("searchParams");
|
|
418
|
+
}
|
|
419
|
+
return Reflect.getOwnPropertyDescriptor(obj, prop);
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
return thenable(makeProxy(), makeProxy);
|
|
423
|
+
}
|
|
391
424
|
function buildProps(req, tracker) {
|
|
392
425
|
// Page-level data fetching (getStaticProps/getServerSideProps) has been
|
|
393
426
|
// removed; per-request data is provided by server components (@server),
|
|
@@ -401,6 +434,10 @@ export function createSSRCore(opts) {
|
|
|
401
434
|
const props = {};
|
|
402
435
|
if (req.params)
|
|
403
436
|
props.params = thenableRecord(req.params);
|
|
437
|
+
if (req.prerender) {
|
|
438
|
+
props.searchParams = prerenderSearchParams();
|
|
439
|
+
return props;
|
|
440
|
+
}
|
|
404
441
|
if (tracker) {
|
|
405
442
|
// Reads through the view are recorded; awaiting it resolves to another
|
|
406
443
|
// tracked view so `const { page } = await searchParams` records "page".
|
|
@@ -457,7 +494,7 @@ export function createSSRCore(opts) {
|
|
|
457
494
|
}
|
|
458
495
|
// An uncacheable read (no-store) keeps the render out of the ISR cache, and
|
|
459
496
|
// a revalidation that landed mid-render means the HTML may be stale.
|
|
460
|
-
if (page.mode === "isr" && !scope.noStore && !invalidated) {
|
|
497
|
+
if (!req.prerender && page.mode === "isr" && !scope.noStore && !invalidated) {
|
|
461
498
|
recordQueryReads(req, tracker);
|
|
462
499
|
await isrStore.set(pageKey(req), {
|
|
463
500
|
html,
|
|
@@ -552,7 +589,7 @@ export function createSSRCore(opts) {
|
|
|
552
589
|
return { html: "", status: 404, notFound: true };
|
|
553
590
|
}
|
|
554
591
|
// ISR: serve from cache with stale-while-revalidate.
|
|
555
|
-
if (page.mode === "isr") {
|
|
592
|
+
if (!req.prerender && page.mode === "isr") {
|
|
556
593
|
const interval = page.revalidate || 60;
|
|
557
594
|
pageIntervals.set(page.route, interval);
|
|
558
595
|
const key = pageKey(req);
|
|
@@ -861,6 +898,8 @@ export function createSSRCore(opts) {
|
|
|
861
898
|
frame.notFound = true;
|
|
862
899
|
if (result.denied)
|
|
863
900
|
frame.denied = result.denied;
|
|
901
|
+
if (result.dynamicUsage)
|
|
902
|
+
frame.dynamicUsage = result.dynamicUsage;
|
|
864
903
|
if (result.redirect)
|
|
865
904
|
frame.redirect = result.redirect;
|
|
866
905
|
if (result.error)
|
package/package.json
CHANGED