@rsc-kit/core 0.22.6 → 0.22.8

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.js CHANGED
@@ -407,6 +407,25 @@ function resolvePaths(options) {
407
407
  function log(...args) {
408
408
  console.error("[rsc-kit]", ...args);
409
409
  }
410
+ /**
411
+ * A generated file, written only when what it says has changed.
412
+ *
413
+ * Every Vite start writes these - a dev server, and a build run beside one
414
+ * in the same project. Rewritten unchanged, the running dev server saw its
415
+ * own entries change under it and reloaded mid-render: aborted renders, and
416
+ * React warning about two renderers sharing a context. An agent that builds
417
+ * to check its work did it every time.
418
+ */
419
+ function writeGenerated(path, content) {
420
+ try {
421
+ if (readFileSync(path, "utf-8") === content)
422
+ return;
423
+ }
424
+ catch {
425
+ // Not there yet.
426
+ }
427
+ writeFileSync(path, content);
428
+ }
410
429
  // ── The route manifest ───────────────────────────────────────────────────────
411
430
  /**
412
431
  * What the plugin knows about the route tree, written out for a host to read.
@@ -702,15 +721,15 @@ function writeHostBindings(manifest) {
702
721
  // The global is installed at runtime, so nothing in app source declares it
703
722
  // and a typecheck cannot see it. Written whether or not there are actions:
704
723
  // server components call it directly too.
705
- writeFileSync(join(typesDir, "rsc-env.d.ts"), renderHostGlobalTypes());
724
+ writeGenerated(join(typesDir, "rsc-env.d.ts"), renderHostGlobalTypes());
706
725
  // The urls this build found, so a link to a page that does not exist fails
707
726
  // the typecheck instead of the browser.
708
- writeFileSync(join(typesDir, "rsc-routes.d.ts"), renderRouteTypes(manifest));
727
+ writeGenerated(join(typesDir, "rsc-routes.d.ts"), renderRouteTypes(manifest));
709
728
  // The bundle the host imports is generated, so nothing declares it. Written
710
729
  // here rather than left to the app: every app needs the identical file, and
711
730
  // an app-authored one goes stale — the first version named only RscEngine,
712
731
  // which typechecks a server and fails a prerender script.
713
- writeFileSync(join(typesDir, "rsc-engine.d.ts"), ENGINE_TYPES);
732
+ writeGenerated(join(typesDir, "rsc-engine.d.ts"), ENGINE_TYPES);
714
733
  warnIfTypesUnreachable();
715
734
  const target = join(sourceDir, "server-actions.generated.ts");
716
735
  // A host with no functions of its own leaves no file behind: kept, its
@@ -720,7 +739,7 @@ function writeHostBindings(manifest) {
720
739
  rmSync(target);
721
740
  return;
722
741
  }
723
- writeFileSync(target, renderHostActions());
742
+ writeGenerated(target, renderHostActions());
724
743
  }
725
744
  /**
726
745
  * The generated engine bundle, as the type its callers expect.
@@ -2590,6 +2609,7 @@ import { parseParams, parseSearchParams, parseBody, isSearchParamsError, isBodyE
2590
2609
  import { notFoundDigest, isNotFoundSignal } from ${JSON.stringify(join(packageDir, "notFound"))}
2591
2610
  import { noteRequestRead, urlOf } from ${JSON.stringify(join(packageDir, "request"))}
2592
2611
  import { redirectDigest } from ${JSON.stringify(join(packageDir, "redirectDigest"))}
2612
+ import { cancelledByConsumer } from ${JSON.stringify(join(packageDir, "js/fallbackReport"))}
2593
2613
  import { createRscHandler, queryAndParams } from ${JSON.stringify(join(packageDir, "host"))}
2594
2614
  import { httpHostCalls } from ${JSON.stringify(join(packageDir, "hostCalls"))}
2595
2615
  import { prerenderedBeside } from ${JSON.stringify(join(packageDir, "files"))}
@@ -3914,6 +3934,11 @@ function flightOnError(error: unknown): string | undefined {
3914
3934
 
3915
3935
  if (digest) return digest
3916
3936
 
3937
+ // The consumer cancelled: a browser that left mid-stream, a dev reload
3938
+ // that dropped the page being rendered. The HTML renderer has always kept
3939
+ // quiet about these; the payload renderer printed each one as an error.
3940
+ if (cancelledByConsumer(error)) return undefined
3941
+
3917
3942
  console.error('[rsc-kit]', error)
3918
3943
 
3919
3944
  return undefined
@@ -6246,8 +6271,9 @@ export function rscKit(options = {}) {
6246
6271
  // module graph is walked as soon as this hook returns.
6247
6272
  const manifest = routeManifest();
6248
6273
  writeHostBindings(manifest);
6249
- if (existsSync(genDir))
6250
- rmSync(genDir, { recursive: true, force: true });
6274
+ // Not emptied first: a dev server may be running from these very
6275
+ // files, and a build beside it deleting them reloaded it mid-render.
6276
+ // The names are fixed, so nothing stale is left to clear.
6251
6277
  mkdirSync(genDir, { recursive: true });
6252
6278
  // Where a url this server does not own is handed on. Resolved exactly as
6253
6279
  // host calls resolve their endpoint, from the app's own .env, so the two
@@ -6271,13 +6297,13 @@ export function rscKit(options = {}) {
6271
6297
  "")
6272
6298
  : "";
6273
6299
  const fallbackOrigin = options.devFallback === false ? "" : (options.devFallback ?? detected);
6274
- writeFileSync(join(genDir, "entry.rsc.tsx"), generateEntryRsc(fallbackOrigin));
6275
- writeFileSync(join(genDir, "entry.ssr.tsx"), generateEntrySsr());
6276
- writeFileSync(join(genDir, "entry.browser.tsx"), generateEntryBrowser());
6300
+ writeGenerated(join(genDir, "entry.rsc.tsx"), generateEntryRsc(fallbackOrigin));
6301
+ writeGenerated(join(genDir, "entry.ssr.tsx"), generateEntrySsr());
6302
+ writeGenerated(join(genDir, "entry.browser.tsx"), generateEntryBrowser());
6277
6303
  // Written beside the entries, for a host to read instead of walking the
6278
6304
  // route tree itself. Laravel scans it a second time today; a JS host
6279
6305
  // would otherwise have to write a third walk of the same directories.
6280
- writeFileSync(join(outDir, "routes.json"), JSON.stringify(manifest, null, 2));
6306
+ writeGenerated(join(outDir, "routes.json"), JSON.stringify(manifest, null, 2));
6281
6307
  return {
6282
6308
  // Off, not merely unused: Vite warns when publicDir sits inside outDir,
6283
6309
  // and assetsDir is normally a directory under the build output. An app