@rsc-kit/core 0.37.0 → 0.39.0

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/vite.d.ts CHANGED
@@ -240,8 +240,26 @@ export interface RscKitOptions {
240
240
  * under it, never `/authors` - and every method goes, a POST as a GET. A
241
241
  * team called `auth` is then unreachable, which is the price of the name.
242
242
  * Without a backend where this runs, such a url is this app's not-found page.
243
+ *
244
+ * A whole segment in brackets is any one segment: `/login/[provider]` is
245
+ * `/login/google` and what is under it, and not `/login` itself. Not the
246
+ * first segment, and a page it would cover stops dev and the build.
243
247
  */
244
248
  backendPaths?: string[];
249
+ /**
250
+ * Top-level directories served on their own subdomain, and only there:
251
+ * `['merchant']` puts `app/merchant/orders/page.tsx` on
252
+ * `merchant.example.com/orders`.
253
+ *
254
+ * A subdomain is routed without being named here - `merchant.example.com`
255
+ * reaches app/merchant either way. Naming it makes that url the page's
256
+ * only one: `example.com/merchant/orders` answers 301 to it, a `Link`,
257
+ * `visit()` or `redirect()` to `/merchant/orders` goes there, a root path
258
+ * written on the subdomain goes back to the site, and the build's route
259
+ * table says so for a backend that names routes (Laravel's `route()`).
260
+ * Needs the site's host (`hosts`), and a directory of that name.
261
+ */
262
+ subdomains?: string[];
245
263
  /**
246
264
  * This package's directory, holding the client runtime the browser entry
247
265
  * imports. Vite stages configs through node_modules/.vite-temp, so
@@ -376,6 +394,52 @@ export declare function normaliseBackendPaths(paths: readonly string[] | undefin
376
394
  * prefetch, wherever the router meets one: a click, a redirect, a hover.
377
395
  */
378
396
  export declare function backendPatterns(paths: readonly string[]): string[];
397
+ /**
398
+ * The ones that are plain prefixes, which is what a proxy in front reads from
399
+ * routes.json and the build report: "a path equal to one or under it". One
400
+ * with a dynamic segment is left out of that list rather than changing what
401
+ * the list means - the proxy hands the url on like any other, and the
402
+ * renderer, which reads them all, forwards it.
403
+ */
404
+ export declare function backendPrefixes(paths: readonly string[]): string[];
405
+ /** A backend path as the source of a RegExp: the prefix, at a segment boundary. */
406
+ export declare function backendPathSource(path: string): string;
407
+ /**
408
+ * A page a dynamic backend path would take.
409
+ *
410
+ * A named prefix wins over every page, without asking one - that is what it
411
+ * is for, and why it costs a request nothing. With a dynamic segment the
412
+ * prefix can cover a page nobody meant it to: '/login/[provider]' is
413
+ * /login/forgot too. Said once, where the app starts, rather than checked on
414
+ * every request: the page would simply never render.
415
+ */
416
+ /** rscKit({ subdomains }), checked: labels a host can have, without a slash, once each. */
417
+ export declare function normaliseSubdomains(labels: unknown): string[];
418
+ /**
419
+ * Why rscKit({ subdomains }) cannot be honoured, or null: a subdomain needs a
420
+ * site to be a subdomain of, and a directory to serve. Without either it
421
+ * would redirect visitors to a host that answers nothing.
422
+ */
423
+ export declare function subdomainProblem(routes: {
424
+ component: string;
425
+ segments: RouteSegment[];
426
+ }[], labels: readonly string[], hasSiteHost: boolean): string | null;
427
+ /**
428
+ * A backend path under a folder served on its own subdomain: a proxy forwards
429
+ * by the path visitors send, and on merchant.example.com that is /auth, never
430
+ * /merchant/auth - the prefix would match nothing.
431
+ */
432
+ export declare function backendPathOnSubdomain(paths: readonly string[], labels: readonly string[]): string | null;
433
+ /**
434
+ * A page a backend path would take - a plain prefix or one with a bracketed
435
+ * segment. The path goes to the backend before any page is asked, so that
436
+ * page would never render. A dynamic page the prefix only shares urls with,
437
+ * [team]/[app] under /auth, is not taken: that is what backendPaths is for.
438
+ */
439
+ export declare function pageUnderBackendPath(routes: {
440
+ component: string;
441
+ segments: RouteSegment[];
442
+ }[], paths: readonly string[]): string | null;
379
443
  /**
380
444
  * The service worker, written into the client output at build time.
381
445
  *
@@ -532,6 +596,15 @@ export declare function samePageUrl(routes: {
532
596
  * its own - is its character code, so no two paths share an alias.
533
597
  */
534
598
  export declare function toAlias(name: string): string;
599
+ /**
600
+ * `export const crossOrigin = true` on a route.ts, read from the source as
601
+ * revalidate is. `true` only: anything the build cannot read is refused,
602
+ * since reading it as false would 403 every other site and reading it as true
603
+ * would open a route nobody meant to.
604
+ */
605
+ export declare function crossOriginOf(file: string): {
606
+ crossOrigin?: true;
607
+ };
535
608
  export declare function compileStep(root: string): {
536
609
  compile?: string;
537
610
  binary?: string;
package/dist/vite.js CHANGED
@@ -26,7 +26,7 @@ import { stampDisplayNames } from "./stableNames.js";
26
26
  import { REPORT_FILE, buildReport } from "./buildReport.js";
27
27
  import { contractPath, edgeGuarded, edgeMarker, edgeShells, edgeStatic } from "./edgeShells.js";
28
28
  import { EDGE, EDGE_HEADERS } from "./headers.js";
29
- import { claimDevServer, recordDevServerUrl, releaseDevServer, secondDevServerMessage, waitForDevServer } from "./devLock.js";
29
+ import { claimDevServer, recordDevServerUrl, releaseDevServer, secondDevServerMessage, startedAtATerminal, waitForDevServer } from "./devLock.js";
30
30
  import { devContentSecurityPolicy, normaliseContentSecurityPolicy, } from "./csp.js";
31
31
  import { MANIFEST_PATH, manifestWarning, webManifest } from "./webManifest.js";
32
32
  import { ASSET_BASE, allAppAssets, assetFile, appAssets, headTags, shareImageUrls, typeOf, } from "./appAssets.js";
@@ -241,6 +241,7 @@ let hotFile;
241
241
  let hostCallOptions;
242
242
  let packageDir;
243
243
  let backendPaths = [];
244
+ let subdomains = [];
244
245
  let hostGlobal;
245
246
  let interceptManifestFile;
246
247
  let packageAlias;
@@ -503,9 +504,18 @@ export function normaliseBackendPaths(paths, hostCallPath = DEFAULT_HOST_CALL_PA
503
504
  if (hostCallPath === path || hostCallPath.startsWith(path + "/")) {
504
505
  throw new Error(`[rsc-kit] backendPaths: ${JSON.stringify(raw)} is the host-call endpoint (${hostCallPath}), which only the renderer calls. A proxy reading backendPaths would open it to browsers.`);
505
506
  }
506
- // A bracket is a dynamic segment to the client, which reads these as route patterns.
507
- if (/[?#*[\]]/.test(path)) {
508
- throw new Error(`[rsc-kit] backendPaths: ${JSON.stringify(raw)} is a prefix, not a pattern: no query, fragment, wildcard or bracket.`);
507
+ if (/[?#*]/.test(path)) {
508
+ throw new Error(`[rsc-kit] backendPaths: ${JSON.stringify(raw)} is a prefix, not a pattern: no query, fragment or wildcard.`);
509
+ }
510
+ // A whole segment in brackets is any one segment: '/login/[provider]' is
511
+ // /login/google and what is under it. Not the first one - '/[team]' would
512
+ // be every url - and not a catch-all, which a prefix already is.
513
+ const parts = path.slice(1).split("/");
514
+ if (parts.some((part) => /[[\]]/.test(part) && !/^\[[A-Za-z_]\w*\]$/.test(part))) {
515
+ throw new Error(`[rsc-kit] backendPaths: ${JSON.stringify(raw)} has a bracket that is not a whole segment. A dynamic segment is '[name]', as in '/login/[provider]'; a prefix already covers everything under it, so there is no '[...rest]'.`);
516
+ }
517
+ if (parts[0].startsWith("[")) {
518
+ throw new Error(`[rsc-kit] backendPaths: ${JSON.stringify(raw)} starts with a dynamic segment, which is every url of that depth and leaves none for this app. Start with a fixed segment, as in '/login/[provider]'.`);
509
519
  }
510
520
  if (!out.includes(path))
511
521
  out.push(path);
@@ -527,6 +537,116 @@ const DEFAULT_HOST_CALL_PATH = "/__rsc/host-call";
527
537
  export function backendPatterns(paths) {
528
538
  return paths.flatMap((path) => [path, `${path}/[...rest]`]);
529
539
  }
540
+ /**
541
+ * The ones that are plain prefixes, which is what a proxy in front reads from
542
+ * routes.json and the build report: "a path equal to one or under it". One
543
+ * with a dynamic segment is left out of that list rather than changing what
544
+ * the list means - the proxy hands the url on like any other, and the
545
+ * renderer, which reads them all, forwards it.
546
+ */
547
+ export function backendPrefixes(paths) {
548
+ return paths.filter((path) => !path.includes("["));
549
+ }
550
+ /** A backend path as the source of a RegExp: the prefix, at a segment boundary. */
551
+ export function backendPathSource(path) {
552
+ return ("^/" +
553
+ path
554
+ .slice(1)
555
+ .split("/")
556
+ .map((part) => (part.startsWith("[") ? "[^/]+" : part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")))
557
+ .join("/") +
558
+ "(?:/|$)");
559
+ }
560
+ /**
561
+ * A page a dynamic backend path would take.
562
+ *
563
+ * A named prefix wins over every page, without asking one - that is what it
564
+ * is for, and why it costs a request nothing. With a dynamic segment the
565
+ * prefix can cover a page nobody meant it to: '/login/[provider]' is
566
+ * /login/forgot too. Said once, where the app starts, rather than checked on
567
+ * every request: the page would simply never render.
568
+ */
569
+ /** rscKit({ subdomains }), checked: labels a host can have, without a slash, once each. */
570
+ export function normaliseSubdomains(labels) {
571
+ if (labels === undefined)
572
+ return [];
573
+ if (!Array.isArray(labels))
574
+ throw new Error("[rsc-kit] subdomains: an array of directory names, as in ['merchant'].");
575
+ const out = [];
576
+ for (const label of labels) {
577
+ const name = typeof label === "string" ? label.replace(/^\/+|\/+$/g, "") : "";
578
+ if (!/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(name)) {
579
+ throw new Error(`[rsc-kit] subdomains: ${JSON.stringify(label)} is not a subdomain label. ` +
580
+ "Name a top-level directory of app/ the way its host spells it: lower-case letters, digits and hyphens, as in 'merchant'.");
581
+ }
582
+ if (name === "www")
583
+ throw new Error("[rsc-kit] subdomains: 'www' is the site's own host, never a subdomain of it.");
584
+ if (!out.includes(name))
585
+ out.push(name);
586
+ }
587
+ return out;
588
+ }
589
+ /**
590
+ * Why rscKit({ subdomains }) cannot be honoured, or null: a subdomain needs a
591
+ * site to be a subdomain of, and a directory to serve. Without either it
592
+ * would redirect visitors to a host that answers nothing.
593
+ */
594
+ export function subdomainProblem(routes, labels, hasSiteHost) {
595
+ if (labels.length === 0)
596
+ return null;
597
+ if (!hasSiteHost) {
598
+ return ("[rsc-kit] subdomains: a subdomain is one of the site's host, and the build does not know it. " +
599
+ "Pass it as rscKit({ hosts: [new URL(env.APP_URL).host] }).");
600
+ }
601
+ for (const label of labels) {
602
+ const served = routes.some((route) => {
603
+ const first = route.segments.find((segment) => segment.type !== "host");
604
+ return first?.type === "static" && first.value === label;
605
+ });
606
+ if (!served) {
607
+ return `[rsc-kit] subdomains: ${JSON.stringify(label)} has no page - add app/${label}/page.tsx, or a page under app/${label}/.`;
608
+ }
609
+ }
610
+ return null;
611
+ }
612
+ /**
613
+ * A backend path under a folder served on its own subdomain: a proxy forwards
614
+ * by the path visitors send, and on merchant.example.com that is /auth, never
615
+ * /merchant/auth - the prefix would match nothing.
616
+ */
617
+ export function backendPathOnSubdomain(paths, labels) {
618
+ for (const path of paths) {
619
+ const first = path.slice(1).split("/")[0];
620
+ if (labels.includes(first)) {
621
+ return (`[rsc-kit] backendPaths: ${JSON.stringify(path)} is under app/${first}/, which subdomains serves on ${first}.<site>, ` +
622
+ `where its visitors send ${JSON.stringify(path.slice(first.length + 1) || "/")}. Name the backend's urls as visitors send them.`);
623
+ }
624
+ }
625
+ return null;
626
+ }
627
+ /**
628
+ * A page a backend path would take - a plain prefix or one with a bracketed
629
+ * segment. The path goes to the backend before any page is asked, so that
630
+ * page would never render. A dynamic page the prefix only shares urls with,
631
+ * [team]/[app] under /auth, is not taken: that is what backendPaths is for.
632
+ */
633
+ export function pageUnderBackendPath(routes, paths) {
634
+ for (const path of paths) {
635
+ const parts = path.slice(1).split("/");
636
+ for (const route of routes) {
637
+ const segments = route.segments.filter((segment) => segment.type !== "host");
638
+ if (segments.length < parts.length)
639
+ continue;
640
+ const covered = parts.every((part, i) => part.startsWith("[") ? true : segments[i].type === "static" && segments[i].value === part);
641
+ if (covered) {
642
+ return (`[rsc-kit] backendPaths: ${JSON.stringify(path)} takes ${patternOf(segments)} (${route.component}), which would never render: ` +
643
+ "a backend path is sent to the backend before any page is asked. " +
644
+ "Name the backend's urls one by one, or give them a prefix of their own, as in '/auth/[provider]'.");
645
+ }
646
+ }
647
+ }
648
+ return null;
649
+ }
530
650
  function resolvePaths(options) {
531
651
  projectRoot = resolve(options.projectRoot || process.env.RSC_PROJECT_ROOT || process.cwd());
532
652
  sourceDir = resolve(options.sourceDir || process.env.RSC_SOURCE_DIR || join(projectRoot, "src"));
@@ -564,6 +684,7 @@ function resolvePaths(options) {
564
684
  hotFile = options.hotFile || process.env.RSC_HOT_FILE || "";
565
685
  hostCallOptions = options.hostCall;
566
686
  packageDir = resolve(options.packageDir || process.env.RSC_PACKAGE_DIR || thisDir());
687
+ subdomains = normaliseSubdomains(options.subdomains);
567
688
  backendPaths = normaliseBackendPaths(options.backendPaths, options.hostCall?.path ?? process.env.RSC_HOST_CALL_PATH ?? DEFAULT_HOST_CALL_PATH);
568
689
  hostGlobal = options.hostGlobal || process.env.RSC_HOST_GLOBAL || "rpc";
569
690
  interceptManifestFile = resolve(options.interceptManifestFile ||
@@ -932,7 +1053,7 @@ function routeManifest() {
932
1053
  ...revalidateOf([...layouts, name].map((n) => components.get(n).absPath)),
933
1054
  });
934
1055
  }
935
- const clash = samePageUrl(routes);
1056
+ const clash = samePageUrl(routes) ?? pageUnderBackendPath(routes, backendPaths) ?? subdomainProblem(routes, subdomains, siteHosts.length > 0) ?? backendPathOnSubdomain(backendPaths, subdomains);
936
1057
  if (clash)
937
1058
  throw new Error(clash);
938
1059
  // What the build decided, for a host that has to act on it afterwards —
@@ -949,12 +1070,13 @@ function routeManifest() {
949
1070
  headers: Object.keys(pageHeaders).length ? pageHeaders : undefined,
950
1071
  contentSecurityPolicy: devPolicy(),
951
1072
  // Always written, [] when none: a reader can tell "none" from a build
952
- // too old to say.
953
- backendPaths,
1073
+ // too old to say. Prefixes only - see backendPrefixes.
1074
+ backendPaths: backendPrefixes(backendPaths),
1075
+ subdomains: subdomains.length ? subdomains : undefined,
954
1076
  },
955
1077
  routes,
956
1078
  intercepts,
957
- apis: [...apiRoutes.values()].map(({ name, methods, generated, absPath }) => ({
1079
+ apis: [...apiRoutes.values()].map(({ name, methods, generated, absPath, crossOrigin }) => ({
958
1080
  name,
959
1081
  segments: urlSegments(name),
960
1082
  methods,
@@ -971,6 +1093,7 @@ function routeManifest() {
971
1093
  // ['auth']` on a directory guards the route.ts files in it, or adding
972
1094
  // an endpoint under a guarded path opened a hole in it.
973
1095
  hostMiddleware: generated ? [] : hostMiddleware(dirOf(name)),
1096
+ ...(crossOrigin ? { crossOrigin } : {}),
974
1097
  })),
975
1098
  };
976
1099
  }
@@ -2179,7 +2302,7 @@ ${legend(counted)}
2179
2302
  .filter((r) => existsSync(join(staticDir, pathKeyOf(r.url) + ".html")))
2180
2303
  .map((r) => r.url),
2181
2304
  results,
2182
- shells: edgeShells(results, manifest.routes),
2305
+ shells: edgeShells(results, manifest.routes, manifest.build?.subdomains ?? []),
2183
2306
  routes: manifest.routes,
2184
2307
  pathKey: pathKeyOf,
2185
2308
  build,
@@ -2441,7 +2564,11 @@ function renderRouteTypes(manifest) {
2441
2564
  " interface RegisterBackend {",
2442
2565
  backendPaths.length > 0
2443
2566
  ? " paths:\n" +
2444
- backendPaths.map((p) => " | " + JSON.stringify(p)).join("\n")
2567
+ backendPaths
2568
+ .map((p) => " | " +
2569
+ // A dynamic segment is any string there: `/login/${string}`.
2570
+ (p.includes("[") ? "`" + p.replace(/\[[^\]]+\]/g, "${string}") + "`" : JSON.stringify(p)))
2571
+ .join("\n")
2445
2572
  : " // No backendPaths named.\n paths: never",
2446
2573
  " }",
2447
2574
  // Regions: every section('name', …) the build read, and every @slot
@@ -2978,7 +3105,23 @@ function registerApiRoute(absPath) {
2978
3105
  ` Export one named for the method it answers — export function GET(request: Request) — ` +
2979
3106
  `or delete the file. One of: ${API_METHODS.join(", ")}.`);
2980
3107
  }
2981
- apiRoutes.set(name, { name, absPath, methods });
3108
+ apiRoutes.set(name, { name, absPath, methods, ...crossOriginOf(absPath) });
3109
+ }
3110
+ /**
3111
+ * `export const crossOrigin = true` on a route.ts, read from the source as
3112
+ * revalidate is. `true` only: anything the build cannot read is refused,
3113
+ * since reading it as false would 403 every other site and reading it as true
3114
+ * would open a route nobody meant to.
3115
+ */
3116
+ export function crossOriginOf(file) {
3117
+ const declared = exportedConst(file, "crossOrigin");
3118
+ if (!declared)
3119
+ return {};
3120
+ const value = unwrapTypes(declared.init);
3121
+ if (value?.type !== "Literal" || typeof value.value !== "boolean") {
3122
+ throw new Error(`${file}: export const crossOrigin must be true or false. Found: ${declared.source}`);
3123
+ }
3124
+ return value.value ? { crossOrigin: true } : {};
2982
3125
  }
2983
3126
  /**
2984
3127
  * Whether a middleware.ts is a guard the engine runs, or only names guards
@@ -3279,11 +3422,12 @@ const BACKEND_HEADERS = backendHeaders(typeof process === 'undefined' ? undefine
3279
3422
  * the same prefixes as the real one.
3280
3423
  */
3281
3424
  function backendPathConsts() {
3282
- return `const BACKEND_PATHS: string[] = ${JSON.stringify(backendPaths)}
3425
+ return `const BACKEND_PATHS: RegExp[] = ${JSON.stringify(backendPaths.map(backendPathSource))}.map((source) => new RegExp(source))
3283
3426
 
3284
- // A prefix at a segment boundary: '/auth' is '/auth' and what is under it, not '/authors'.
3427
+ // A prefix at a segment boundary: '/auth' is '/auth' and what is under it, not
3428
+ // '/authors'. '[name]' in one is any single segment.
3285
3429
  function onBackendPath(pathname: string): boolean {
3286
- return BACKEND_PATHS.some((prefix) => pathname === prefix || pathname.startsWith(prefix + '/'))
3430
+ return BACKEND_PATHS.some((prefix) => prefix.test(pathname))
3287
3431
  }
3288
3432
 
3289
3433
  // The backend's host-call endpoint, which only this server calls - straight to
@@ -7882,6 +8026,70 @@ export const SHUTDOWN_PLUGIN = `export default function rscKitShutdown() {
7882
8026
  process.once('SIGINT', stop)
7883
8027
  }
7884
8028
  `;
8029
+ /**
8030
+ * One dev-server restart at a time, and none lost.
8031
+ *
8032
+ * Vite answers a restart asked for while one is running with the running
8033
+ * one's promise. The route table that restart reads was already written, so
8034
+ * a second page added a moment after the first was a 404 until something
8035
+ * else restarted the server. A restart asked for while one runs becomes one
8036
+ * more, after it. On globalThis because a restart re-imports the config, and
8037
+ * this must outlive the plugin instance that started it.
8038
+ */
8039
+ const RESTARTS = Symbol.for("rsc-kit.dev-restarts");
8040
+ function restartOnce(server) {
8041
+ const holder = globalThis;
8042
+ const state = (holder[RESTARTS] ??= { running: false, again: false });
8043
+ if (state.running) {
8044
+ state.again = true;
8045
+ return;
8046
+ }
8047
+ state.running = true;
8048
+ void (async () => {
8049
+ try {
8050
+ do {
8051
+ state.again = false;
8052
+ await server.restart();
8053
+ } while (state.again);
8054
+ }
8055
+ finally {
8056
+ state.running = false;
8057
+ }
8058
+ })();
8059
+ }
8060
+ /**
8061
+ * What Vite starts on listen, started before a restarted server renders.
8062
+ *
8063
+ * Nitro's dev runner imports the ssr and rsc entries as soon as a restarted
8064
+ * server exists, which is before it listens - and two things Vite does only
8065
+ * on listen were therefore missing for whatever that import transformed.
8066
+ *
8067
+ * The client's buildStart, where vite:css registers its CSS-modules cache for
8068
+ * the new config: a stylesheet transformed first failed every request with
8069
+ * "cssModulesCache.get(config).get". And each environment's dependency
8070
+ * optimizer: resolved before it was initialised, react-dom/server came from
8071
+ * node_modules and the app's react from the optimized copy - two Reacts, and
8072
+ * every page failed with "resolveDispatcher().useEffect". Both lasted until
8073
+ * dev was restarted by hand. Both calls are idempotent, so Vite's own on
8074
+ * listen become no-ops.
8075
+ *
8076
+ * Its own plugin, ordered post, and not the first lines of the engine's
8077
+ * configureServer: waiting there let a transform run before plugin-rsc had
8078
+ * been handed the server ("reading 'environments'" of undefined).
8079
+ */
8080
+ function startedBeforeAnythingRenders() {
8081
+ return {
8082
+ name: "rsc-kit:started-before-anything-renders",
8083
+ apply: "serve",
8084
+ configureServer: {
8085
+ order: "post",
8086
+ async handler(server) {
8087
+ await server.environments?.client?.pluginContainer.buildStart();
8088
+ await Promise.all(Object.values(server.environments ?? {}).map((environment) => environment.depsOptimizer?.init()));
8089
+ },
8090
+ },
8091
+ };
8092
+ }
7885
8093
  /**
7886
8094
  * Where NODE_ENV=development came from, and what to do about it.
7887
8095
  *
@@ -8282,7 +8490,11 @@ export function rscKit(options = {}) {
8282
8490
  const lockDir = join(projectRoot, "node_modules", ".vite");
8283
8491
  const holder = claimDevServer(lockDir);
8284
8492
  if (holder) {
8285
- log(secondDevServerMessage(projectRoot, holder).replace(/^\[rsc-kit\] /, ""));
8493
+ const waits = !startedAtATerminal();
8494
+ log(secondDevServerMessage(projectRoot, holder, waits).replace(/^\[rsc-kit\] /, ""));
8495
+ // A person at a terminal is told and let go; see devLock.ts.
8496
+ if (!waits)
8497
+ process.exit(1);
8286
8498
  await waitForDevServer(lockDir);
8287
8499
  log("the other dev server stopped — starting this one");
8288
8500
  }
@@ -8427,6 +8639,8 @@ export function rscKit(options = {}) {
8427
8639
  __RSC_OFFLINE__: JSON.stringify(offline),
8428
8640
  // hostUrl()'s site: the host as named, port and all, without www.
8429
8641
  __RSC_SITE_HOST__: JSON.stringify(siteHostOf(rootMetadataBase(appDir), hostsOption)),
8642
+ // rscKit({ subdomains }): where Link, visit() and redirect() place a path.
8643
+ __RSC_SUBDOMAINS__: JSON.stringify(subdomains),
8430
8644
  },
8431
8645
  /*
8432
8646
  * This package's client modules are served as source, never
@@ -8792,7 +9006,7 @@ export function rscKit(options = {}) {
8792
9006
  if (!affectsRouting(file))
8793
9007
  return;
8794
9008
  server.config.logger.info(`[rsc-kit] route tree changed (${file.slice(sourceDir.length + 1)}) — restarting`);
8795
- void server.restart();
9009
+ restartOnce(server);
8796
9010
  };
8797
9011
  // Watched explicitly: the Vite root is the *out* directory, so the app's
8798
9012
  // source tree is outside it and nothing would report a file appearing.
@@ -8810,7 +9024,7 @@ export function rscKit(options = {}) {
8810
9024
  if (file !== hostActionsPath || hostFileOnDisk() === hostFileText)
8811
9025
  return;
8812
9026
  server.config.logger.info(`[rsc-kit] ${relative(projectRoot, file)} changed — restarting`);
8813
- void server.restart();
9027
+ restartOnce(server);
8814
9028
  };
8815
9029
  server.watcher.add(hostActionsPath);
8816
9030
  // The backend's own source, when the app says where it is: a function
@@ -8900,7 +9114,7 @@ export function rscKit(options = {}) {
8900
9114
  // without the app - before the build id, which hashes the documents
8901
9115
  // this changes, and before the pages are packed into a module or the
8902
9116
  // assets. A server build only: an export has no edge in front of an app.
8903
- const listed = output !== "export" && clientOut ? edgeStatic(results, routes, shells.shells) : { static: [], left: [] };
9117
+ const listed = output !== "export" && clientOut ? edgeStatic(results, routes, shells.shells, subdomains) : { static: [], left: [] };
8904
9118
  const keyOf = new Map(results.map((r) => [contractPath(r.url), pathKeyOf(r.url)]));
8905
9119
  const statics = clientOut
8906
9120
  ? storedPayloadAssets(staticDir, clientOut, listed.static.map((path) => ({ path, key: keyOf.get(path) })).filter((page) => page.key))
@@ -8978,7 +9192,7 @@ export function rscKit(options = {}) {
8978
9192
  ...(buildCommands().length ? { commands: buildCommands().map((c) => c.name) } : {}),
8979
9193
  // The prefixes a proxy in front sends straight to the
8980
9194
  // backend: a path equal to one or under it. [] when none.
8981
- backendPaths,
9195
+ backendPaths: backendPrefixes(backendPaths),
8982
9196
  }, null, 2) + "\n");
8983
9197
  // The edge contract's marker: the pages an edge may answer from a
8984
9198
  // cached shell or whole, and the build both endpoints will say they
@@ -9088,6 +9302,7 @@ export function rscKit(options = {}) {
9088
9302
  clientImportsAudit(),
9089
9303
  serverOnlyInTheBrowser(),
9090
9304
  routesPlugin,
9305
+ startedBeforeAnythingRenders(),
9091
9306
  ];
9092
9307
  }
9093
9308
  /**