akanjs 3.0.0-beta.24 → 3.0.0-beta.26

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.
Files changed (45) hide show
  1. package/common/hmrPhase.ts +2 -0
  2. package/package.json +1 -1
  3. package/server/SSR_MEMORY_DIAGNOSIS.md +2 -2
  4. package/server/akanApp.ts +1 -0
  5. package/server/akanServer.ts +7 -1
  6. package/server/artifact/builderRpc.ts +13 -2
  7. package/server/artifact/devBuildRecovery.ts +12 -0
  8. package/server/artifact/index.ts +1 -0
  9. package/server/artifact/ipcTypes.ts +46 -3
  10. package/server/artifact/routeClientCache.ts +128 -29
  11. package/server/di/diLifecycle.ts +1 -1
  12. package/server/hmr/clientScript.ts +148 -86
  13. package/server/hmr/csrDevManifest.ts +17 -0
  14. package/server/hmr/csrDevRuntime.ts +238 -18
  15. package/server/hmr/csrDevShell.ts +90 -10
  16. package/server/hmr/devArtifactPruner.ts +77 -0
  17. package/server/hmr/devHmrController.ts +233 -137
  18. package/server/hmr/ssrDevShim.ts +112 -0
  19. package/server/hmr/ssrUpdateQueue.ts +111 -0
  20. package/server/hmr/wsHub.ts +19 -4
  21. package/server/routing/apiRouter.ts +12 -0
  22. package/server/rscWorker.tsx +11 -1
  23. package/server/rscWorkerHost.ts +223 -59
  24. package/server/systemPageDocument.tsx +6 -0
  25. package/server/types.tsx +4 -0
  26. package/server/webRouter.ts +57 -22
  27. package/types/common/hmrPhase.d.ts +2 -0
  28. package/types/server/artifact/builderRpc.d.ts +3 -2
  29. package/types/server/artifact/devBuildRecovery.d.ts +4 -0
  30. package/types/server/artifact/index.d.ts +1 -0
  31. package/types/server/artifact/ipcTypes.d.ts +47 -2
  32. package/types/server/artifact/routeClientCache.d.ts +9 -2
  33. package/types/server/hmr/csrDevManifest.d.ts +15 -0
  34. package/types/server/hmr/csrDevRuntime.d.ts +34 -0
  35. package/types/server/hmr/csrDevShell.d.ts +9 -1
  36. package/types/server/hmr/devArtifactPruner.d.ts +9 -0
  37. package/types/server/hmr/devHmrController.d.ts +8 -5
  38. package/types/server/hmr/ssrDevShim.d.ts +7 -0
  39. package/types/server/hmr/ssrUpdateQueue.d.ts +23 -0
  40. package/types/server/hmr/wsHub.d.ts +16 -7
  41. package/types/server/routing/apiRouter.d.ts +8 -0
  42. package/types/server/rscWorkerHost.d.ts +14 -2
  43. package/types/server/systemPageDocument.d.ts +2 -0
  44. package/types/server/types.d.ts +4 -0
  45. package/types/server/webRouter.d.ts +8 -2
@@ -297,7 +297,7 @@ export function createRscHostRenderStream(input: {
297
297
  type RscInMsg =
298
298
  | { type: "hello" }
299
299
  | { type: "ready" }
300
- | { type: "reloaded"; buildId: number }
300
+ | { type: "reloaded"; buildId: number; reloadId?: number; pagesBundlePath?: string }
301
301
  | { type: "meta"; requestId: string; theme?: AkanTheme; status?: number; trace?: RscTraceMetadata }
302
302
  | { type: "cache-state"; requestId: string; state: RouteCacheRenderState }
303
303
  | { type: "chunk"; requestId: string; data: Uint8Array }
@@ -315,16 +315,41 @@ type RscInMsg =
315
315
  | { type: "log.records"; records: LogRecord[]; dropped?: number }
316
316
  | { type: "page-prompts.result"; requestId: string; result: PagePromptEntry[] }
317
317
  | { type: "page-prompt.result"; requestId: string; result: PagePromptRun }
318
- | { type: "error"; requestId: string; message: string; buildId?: number };
318
+ | {
319
+ type: "error";
320
+ requestId: string;
321
+ message: string;
322
+ buildId?: number;
323
+ reloadId?: number;
324
+ running?: RscAdoptedBundle;
325
+ };
319
326
 
320
327
  export interface RscWorkerReloadInput {
321
328
  clientManifest: ClientManifest;
322
329
  cssAssets?: Record<string, CssAsset>;
323
330
  buildId: number;
324
- /** Undefined keeps the current bundle (e.g. a client-manifest-only reload after a lazy route build). */
331
+ /** Undefined keeps the latest bundle a reload named (e.g. a client-manifest-only reload after a lazy route build). */
325
332
  pagesBundlePath?: string;
326
333
  }
327
334
 
335
+ export interface RscAdoptedBundle {
336
+ pagesBundlePath: string;
337
+ buildId: number;
338
+ }
339
+
340
+ interface RscReloadWaiter {
341
+ resolve: (adopted: RscAdoptedBundle) => void;
342
+ reject: (err: RscReloadFailure) => void;
343
+ }
344
+
345
+ /** A reload the worker did not take: what it runs instead, and whether a later reload failed in this one's place. */
346
+ export interface RscReloadFailure extends Error {
347
+ /** What the worker runs now. */
348
+ adopted: RscAdoptedBundle;
349
+ /** The latest state it was asked to take, which a later reload may have moved past the caller's own. */
350
+ failed: RscAdoptedBundle;
351
+ }
352
+
328
353
  type WorkerStatus = "starting" | "ready" | "restarting" | "stopped";
329
354
  type RscProcess = Bun.Subprocess;
330
355
 
@@ -346,11 +371,26 @@ export class RscWorker {
346
371
  #resolveReady!: () => void;
347
372
  #rejectReady!: (err: Error) => void;
348
373
  #readyResolved = false;
349
- #pendingReload: { resolve: () => void; reject: (err: Error) => void; targetBuildId: number } | null = null;
374
+
375
+ #pendingReload: {
376
+ waiters: RscReloadWaiter[];
377
+ reloadState: number;
378
+ reloadId: number | null;
379
+ pagesBundlePath: string;
380
+ buildId: number;
381
+ } | null = null;
382
+ #nextReloadId = 1;
383
+ #answeredReloadId = 0;
384
+
385
+ #droppedWhileBooting = false;
386
+ #reloadState = 0;
387
+ #init: RscAdoptedBundle & { reloadState: number } = { pagesBundlePath: "", buildId: 0, reloadState: 0 };
388
+ /** What the worker runs: a respawn falls back to it when the bundle a reload named failed to import. */
389
+ #adopted: RscAdoptedBundle;
350
390
 
351
391
  #status: WorkerStatus = "starting";
352
392
  #killed = false;
353
- #queuedSends: Array<() => void> = [];
393
+ #queuedSends: { requestId: string; send: () => void }[] = [];
354
394
  #restartAttempts = 0;
355
395
  #restartCount = 0;
356
396
  #recycleCount = 0;
@@ -363,15 +403,18 @@ export class RscWorker {
363
403
  #hostPendingChunkOverflowCount = 0;
364
404
  #restartTimer: ReturnType<typeof setTimeout> | null = null;
365
405
  #recycleTimer: ReturnType<typeof setTimeout> | null = null;
366
- #rollingRecycle: { oldProc: RscProcess; reason: string } | null = null;
406
+ #rollingRecycle: { oldProc: RscProcess; reason: string; reloadsSinceSpawn: number } | null = null;
407
+ #booting: RscProcess | null = null;
367
408
 
368
409
  readonly #failBeforeReady: boolean;
410
+ static readonly #queuedRespawns = 2;
369
411
 
370
412
  constructor(artifact: BaseBuildArtifact, { failBeforeReady = false }: { failBeforeReady?: boolean } = {}) {
371
413
  this.#failBeforeReady = failBeforeReady;
372
414
  this.#clientManifest = artifact.rscRuntimeClientManifest ?? {};
373
415
  this.#pagesBundlePath = artifact.pagesBundlePath;
374
416
  this.#pagesBundleBuildId = artifact.pagesBundleBuildId;
417
+ this.#adopted = { pagesBundlePath: artifact.pagesBundlePath, buildId: artifact.pagesBundleBuildId };
375
418
  this.#cssAssets = artifact.cssAssets ?? {};
376
419
  this.#basePaths = artifact.basePaths ?? [];
377
420
  this.#i18n = artifact.i18n ?? DEFAULT_AKAN_I18N;
@@ -433,7 +476,7 @@ export class RscWorker {
433
476
  if (this.#status === "ready") send();
434
477
  else if (this.#status === "stopped")
435
478
  this.#settleCall(requestId, (call) => call.reject(new Error("rsc worker is stopped")));
436
- else this.#queuedSends.push(send);
479
+ else this.#queuedSends.push({ requestId, send });
437
480
  });
438
481
  }
439
482
 
@@ -446,7 +489,10 @@ export class RscWorker {
446
489
  }
447
490
 
448
491
  invalidateRouteResultCache(invalidation?: string | RouteCacheInvalidation): void {
449
- if (this.#status !== "ready") return;
492
+ if (this.#status !== "ready") {
493
+ this.#droppedWhileBooting = true;
494
+ return;
495
+ }
450
496
  try {
451
497
  this.#proc.send(createRscWorkerInvalidateCacheMessage(invalidation));
452
498
  } catch (error) {
@@ -470,6 +516,7 @@ export class RscWorker {
470
516
 
471
517
  setLogLevel(minSev: number | null) {
472
518
  this.#logLevel = minSev;
519
+ if (this.#status !== "ready") this.#droppedWhileBooting = true;
473
520
  this.#sendLogLevel();
474
521
  }
475
522
 
@@ -498,7 +545,7 @@ export class RscWorker {
498
545
  if (this.#killed || this.#status === "stopped" || this.#status === "starting" || this.#status === "restarting") {
499
546
  return false;
500
547
  }
501
- if (this.#pending.size > 0 || this.#queuedSends.length > 0) {
548
+ if (this.#pending.size > 0 || this.#calls.size > 0 || this.#queuedSends.length > 0) {
502
549
  if (!this.#recycleTimer) {
503
550
  const graceMs = MemoryLimit.parsePositiveIntEnv("AKAN_RSC_WORKER_RECYCLE_GRACE_MS") ?? 5_000;
504
551
  this.#recycleTimer = setTimeout(() => {
@@ -513,49 +560,86 @@ export class RscWorker {
513
560
  this.#lastRecycleAtMono = performance.now();
514
561
  this.#logger.info(`[rsc] rolling recycle worker reason=${reason} oldPid=${this.#proc.pid}`);
515
562
  this.#status = "restarting";
516
- this.#rollingRecycle = { oldProc: this.#proc, reason };
563
+ this.#rollingRecycle = { oldProc: this.#proc, reason, reloadsSinceSpawn: this.#reloadsSinceSpawn };
517
564
  this.#proc = this.#spawn();
518
565
  return true;
519
566
  }
520
567
 
521
568
  updateCssAssets(cssAssets: Record<string, CssAsset>): void {
522
569
  this.#cssAssets = cssAssets;
523
- if (this.#status !== "ready") return;
570
+ if (this.#status !== "ready") {
571
+ this.#droppedWhileBooting = true;
572
+ return;
573
+ }
524
574
  try {
525
575
  this.#proc.send({ type: "updateCssAssets", cssAssets });
526
576
  } catch {
527
577
  }
528
578
  }
529
579
 
530
- reload(input: RscWorkerReloadInput): Promise<void> {
580
+ /** Resolves with the pages bundle the worker runs once it has taken this reload, or a later one. */
581
+ reload(input: RscWorkerReloadInput): Promise<RscAdoptedBundle> {
582
+ if (this.#killed) return Promise.reject(new Error("rsc worker is stopped"));
583
+ this.#reloadState += 1;
531
584
  this.#clientManifest = input.clientManifest;
532
585
  this.#cssAssets = input.cssAssets ?? this.#cssAssets;
533
586
  this.#pagesBundleBuildId = input.buildId;
534
587
  if (input.pagesBundlePath) this.#pagesBundlePath = input.pagesBundlePath;
535
-
536
- if (this.#status !== "ready") return Promise.resolve();
588
+ return new Promise<RscAdoptedBundle>((resolve, reject) => {
537
589
 
538
- if (this.#shouldRecycleForReloadAccumulation() && this.restartWhenIdle("pages-reload-accumulation")) {
539
- return Promise.resolve();
540
- }
590
+ this.#pendingReload = {
591
+ waiters: [...(this.#pendingReload?.waiters ?? []), { resolve, reject }],
592
+ reloadState: this.#reloadState,
593
+ reloadId: null,
594
+ pagesBundlePath: this.#pagesBundlePath,
595
+ buildId: this.#pagesBundleBuildId,
596
+ };
597
+ if (this.#status === "ready") this.#sendPendingReload();
598
+ });
599
+ }
600
+
601
+ #sendPendingReload(): void {
602
+ const pending = this.#pendingReload;
603
+ if (!pending) return;
604
+
605
+ const answering = this.#answeredReloadId < this.#nextReloadId - 1;
606
+ if (!answering && this.#shouldRecycleForReloadAccumulation() && this.restartWhenIdle("pages-reload-accumulation"))
607
+ return;
541
608
  this.#reloadsSinceSpawn += 1;
542
- return new Promise<void>((resolve, reject) => {
609
+ pending.reloadId = this.#nextReloadId++;
610
+ try {
611
+
612
+ this.#proc.send({
613
+ type: "reload",
614
+ clientManifest: this.#clientManifest,
615
+ cssAssets: this.#cssAssets,
616
+ buildId: pending.buildId,
617
+ pagesBundlePath: pending.pagesBundlePath,
618
+ reloadId: pending.reloadId,
619
+ });
620
+ } catch {
543
621
 
544
- if (this.#pendingReload) this.#pendingReload.resolve();
545
- this.#pendingReload = { resolve, reject, targetBuildId: input.buildId };
546
- try {
547
- this.#proc.send({
548
- type: "reload",
549
- clientManifest: input.clientManifest,
550
- cssAssets: this.#cssAssets,
551
- buildId: input.buildId,
552
- pagesBundlePath: input.pagesBundlePath,
553
- });
554
- } catch (err) {
555
- this.#pendingReload?.reject(err instanceof Error ? err : new Error(String(err)));
556
- this.#pendingReload = null;
557
- }
558
- });
622
+ pending.reloadId = null;
623
+ }
624
+ }
625
+
626
+ #resolveReload(adopted: RscAdoptedBundle): void {
627
+ this.#adopted = adopted;
628
+ const pending = this.#pendingReload;
629
+ if (!pending) return;
630
+ this.#pendingReload = null;
631
+ for (const waiter of pending.waiters) waiter.resolve(adopted);
632
+ }
633
+
634
+ #rejectReload(message: string): void {
635
+ this.#pagesBundlePath = this.#adopted.pagesBundlePath;
636
+ this.#pagesBundleBuildId = this.#adopted.buildId;
637
+ const pending = this.#pendingReload;
638
+ if (!pending) return;
639
+ this.#pendingReload = null;
640
+ const failed = { pagesBundlePath: pending.pagesBundlePath, buildId: pending.buildId };
641
+ for (const waiter of pending.waiters)
642
+ waiter.reject(Object.assign(new Error(message), { adopted: this.#adopted, failed }));
559
643
  }
560
644
 
561
645
  #spawn(): RscProcess {
@@ -634,6 +718,12 @@ export class RscWorker {
634
718
  switch (message.type) {
635
719
  case "hello":
636
720
 
721
+ this.#booting = proc;
722
+ this.#init = {
723
+ pagesBundlePath: this.#pagesBundlePath,
724
+ buildId: this.#pagesBundleBuildId,
725
+ reloadState: this.#reloadState,
726
+ };
637
727
  this.#proc.send({
638
728
  type: "init",
639
729
  clientManifest: this.#clientManifest,
@@ -645,19 +735,36 @@ export class RscWorker {
645
735
  });
646
736
  return;
647
737
  case "ready":
738
+ this.#booting = null;
648
739
  this.#status = "ready";
740
+ this.#answeredReloadId = this.#nextReloadId - 1;
741
+ this.#droppedWhileBooting = false;
649
742
  this.#restartAttempts = 0;
650
743
  this.#resolveReady();
651
744
  this.#finishRollingRecycle();
652
745
  this.#flushQueuedSends();
653
746
  if (this.#logLevel !== null) this.#sendLogLevel();
747
+
748
+ this.#adopted = { pagesBundlePath: this.#init.pagesBundlePath, buildId: this.#init.buildId };
749
+ if (this.#pendingReload && this.#pendingReload.reloadState <= this.#init.reloadState)
750
+ this.#resolveReload(this.#adopted);
751
+ else this.#sendPendingReload();
654
752
  return;
655
- case "reloaded":
656
- if (this.#pendingReload && this.#pendingReload.targetBuildId === message.buildId) {
657
- this.#pendingReload.resolve();
658
- this.#pendingReload = null;
753
+ case "reloaded": {
754
+ const pending = this.#pendingReload;
755
+
756
+ if (proc === this.#proc && message.pagesBundlePath) {
757
+ this.#adopted = { pagesBundlePath: message.pagesBundlePath, buildId: message.buildId };
758
+ this.#answeredReloadId = Math.max(this.#answeredReloadId, message.reloadId ?? 0);
759
+ if (!pending) {
760
+ this.#pagesBundlePath = message.pagesBundlePath;
761
+ this.#pagesBundleBuildId = message.buildId;
762
+ }
659
763
  }
764
+ if (pending && pending.reloadId !== null && pending.reloadId === message.reloadId)
765
+ this.#resolveReload({ pagesBundlePath: pending.pagesBundlePath, buildId: pending.buildId });
660
766
  return;
767
+ }
661
768
  case "chunk":
662
769
  this.#pending.get(message.requestId)?.onChunk(message.data);
663
770
  return;
@@ -695,21 +802,21 @@ export class RscWorker {
695
802
  return;
696
803
  case "error":
697
804
  if (message.requestId === "__init__") {
698
- if (!this.#readyResolved) this.#rejectReady(new Error(String(message.message)));
699
- else {
700
- this.#logger.error(`[rsc] worker init error on restart: ${message.message}`);
805
+ if (!this.#readyResolved) {
806
+ this.#rejectReload(String(message.message));
807
+ this.#rejectReady(new Error(String(message.message)));
808
+ } else {
809
+ this.#bootFailed(proc, String(message.message));
701
810
  proc.kill();
702
811
  }
703
812
  return;
704
813
  }
705
814
  if (message.requestId === "__reload__") {
706
- if (
707
- this.#pendingReload &&
708
- (message.buildId === undefined || this.#pendingReload.targetBuildId === message.buildId)
709
- ) {
710
- this.#pendingReload.reject(new Error(String(message.message)));
711
- this.#pendingReload = null;
712
- }
815
+ if (proc === this.#proc) this.#answeredReloadId = Math.max(this.#answeredReloadId, message.reloadId ?? 0);
816
+ if (proc === this.#proc && message.running) this.#adopted = message.running;
817
+ const pending = this.#pendingReload;
818
+ if (pending && pending.reloadId !== null && pending.reloadId === message.reloadId)
819
+ this.#rejectReload(String(message.message));
713
820
  return;
714
821
  }
715
822
  if (this.#settleCall(message.requestId, (call) => call.reject(new Error(String(message.message))))) return;
@@ -744,7 +851,7 @@ export class RscWorker {
744
851
  else if (this.#status === "stopped") {
745
852
  this.#resolvePending(requestId, (p) => p.onError("rsc worker is stopped"));
746
853
  } else {
747
- this.#queuedSends.push(send);
854
+ this.#queuedSends.push({ requestId, send });
748
855
  }
749
856
  }
750
857
 
@@ -759,7 +866,7 @@ export class RscWorker {
759
866
  #flushQueuedSends(): void {
760
867
  const queue = this.#queuedSends;
761
868
  this.#queuedSends = [];
762
- for (const send of queue) {
869
+ for (const { send } of queue) {
763
870
  try {
764
871
  send();
765
872
  } catch (err) {
@@ -768,6 +875,46 @@ export class RscWorker {
768
875
  }
769
876
  }
770
877
 
878
+ #failRequests(err: Error, which: (requestId: string) => boolean = () => true): void {
879
+ for (const [requestId, pending] of this.#pending) {
880
+ if (!which(requestId)) continue;
881
+ this.#pending.delete(requestId);
882
+ pending.onError(err.message);
883
+ }
884
+ for (const [requestId, call] of this.#calls) {
885
+ if (!which(requestId)) continue;
886
+ this.#calls.delete(requestId);
887
+ call.reject(err);
888
+ }
889
+ this.#queuedSends = this.#queuedSends.filter((entry) => !which(entry.requestId));
890
+ }
891
+
892
+ #bootFailed(proc: RscProcess, message: string): boolean {
893
+ this.#booting = null;
894
+ this.#logger.error(`[rsc] worker init error on restart: ${message}`);
895
+ const covered = !this.#pendingReload || this.#pendingReload.reloadState <= this.#init.reloadState;
896
+ if (covered) this.#rejectReload(message);
897
+ const rolling = proc === this.#proc ? this.#rollingRecycle : null;
898
+ this.#rollingRecycle = null;
899
+ if (!rolling || !RscWorker.#isAlive(rolling.oldProc)) return false;
900
+ this.#proc = rolling.oldProc;
901
+ this.#status = "ready";
902
+ this.#reloadsSinceSpawn = rolling.reloadsSinceSpawn;
903
+ if (this.#droppedWhileBooting) {
904
+ this.#droppedWhileBooting = false;
905
+ this.updateCssAssets(this.#cssAssets);
906
+ this.#sendLogLevel();
907
+ this.invalidateRouteResultCache();
908
+ }
909
+ this.#flushQueuedSends();
910
+ if (!covered) this.#sendPendingReload();
911
+ return true;
912
+ }
913
+
914
+ static #isAlive(proc: RscProcess): boolean {
915
+ return proc.exitCode === null && proc.signalCode === null && !proc.killed;
916
+ }
917
+
771
918
  #finishRollingRecycle(): void {
772
919
  const recycle = this.#rollingRecycle;
773
920
  if (!recycle) return;
@@ -781,25 +928,42 @@ export class RscWorker {
781
928
 
782
929
  #handleExit(proc: RscProcess, code: number | null): void {
783
930
 
931
+ if (proc === this.#rollingRecycle?.oldProc) {
932
+ this.#rollingRecycle = null;
933
+ return;
934
+ }
935
+
784
936
  if (proc !== this.#proc) return;
785
937
 
786
- const err = new Error(`rsc worker exited with code ${code}`);
787
- for (const [, p] of this.#pending) p.onError(err.message);
788
- this.#pending.clear();
789
- for (const [, call] of this.#calls) call.reject(err);
790
- this.#calls.clear();
791
- if (this.#pendingReload) {
792
- this.#pendingReload.reject(err);
793
- this.#pendingReload = null;
938
+ if (proc === this.#booting && !this.#killed && proc.signalCode === null) {
939
+ const message = `rsc worker exited with code ${code} while loading the pages bundle`;
940
+ if (this.#readyResolved && this.#bootFailed(proc, message)) return;
941
+ if (!this.#readyResolved) {
942
+ this.#booting = null;
943
+ this.#status = "stopped";
944
+ this.#failRequests(new Error(message));
945
+ this.#rejectReload(message);
946
+ this.#rejectReady(new Error(message));
947
+ return;
948
+ }
794
949
  }
795
- this.#queuedSends = [];
950
+
951
+ const err = new Error(`rsc worker exited with code ${code}`);
952
+
953
+ const queued = new Set(this.#queuedSends.map((entry) => entry.requestId));
954
+ const keepsQueue = this.#restartAttempts < RscWorker.#queuedRespawns;
955
+ this.#failRequests(err, (requestId) => !keepsQueue || !queued.has(requestId));
796
956
 
797
957
  if (this.#killed) {
798
958
  this.#status = "stopped";
959
+ this.#failRequests(err);
960
+ this.#rejectReload(err.message);
799
961
  return;
800
962
  }
801
963
  if (this.#failBeforeReady && !this.#readyResolved) {
802
964
  this.#status = "stopped";
965
+ this.#failRequests(err);
966
+ this.#rejectReload(err.message);
803
967
  this.#rejectReady(err);
804
968
  return;
805
969
  }
@@ -835,7 +999,7 @@ export class RscWorker {
835
999
  }
836
1000
 
837
1001
  #maybeRecycleFromMetrics(metrics: AkanMetricsReport): void {
838
- if (this.#pending.size > 0) return;
1002
+ if (this.#pending.size > 0 || this.#calls.size > 0) return;
839
1003
  const maxRssBytes = RscWorker.#getRscMaxRssBytes();
840
1004
  if (maxRssBytes && metrics.rssBytes && metrics.rssBytes >= maxRssBytes) {
841
1005
  this.restartWhenIdle(`rss>${Math.round(maxRssBytes / 1024 / 1024)}MiB`);
@@ -12,6 +12,8 @@ export interface SystemPageOptions {
12
12
  stylesheetHref?: string | null;
13
13
  showDetails?: boolean;
14
14
  error?: unknown;
15
+ /** Dev only: the HMR client, so a page that failed to render reloads once a later build fixes it. */
16
+ script?: string;
15
17
  }
16
18
 
17
19
  export interface SystemPageHomeHrefOptions {
@@ -102,6 +104,10 @@ export function createSystemPageDocument(options: SystemPageOptions): ReactNode
102
104
  ) : null}
103
105
  </section>
104
106
  </main>
107
+ {options.script ? (
108
+
109
+ <script dangerouslySetInnerHTML={{ __html: options.script }} />
110
+ ) : null}
105
111
  </body>
106
112
  </html>
107
113
  );
package/server/types.tsx CHANGED
@@ -142,4 +142,8 @@ export interface RenderState {
142
142
  cssBytesByUrl: Record<string, Uint8Array>;
143
143
  /** The newest CSR dev bundle generation; a CSR tab whose own generation differs has missed an update. */
144
144
  csrGeneration?: number;
145
+ /** The newest SSR dev registry generation sent to the tabs; a tab whose registry differs has missed an update. */
146
+ ssrGeneration?: number;
147
+ /** When the SSR dev registry was last built whole; a tab booted from an earlier one reloads. */
148
+ ssrEpoch?: number;
145
149
  }