MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / browserEnvironment

Function browserEnvironment

packages/app/src/server-disconnected.ts:81–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79 * while the app reload-loops.
80 */
81export const browserEnvironment = (): PreloadErrorEnvironment => {
82 const storage = sessionFlag();
83 return {
84 target: window,
85 probeServer,
86 showDisconnected: showDisconnectedOverlay,
87 reload: () => window.location.reload(),
88 // Routed through the same reporter the rest of the UI uses, so a chunk that
89 // stays missing with a healthy server arrives as a HANDLED error carrying
90 // its surface and action — not as a bare global `reportError`, which the
91 // crash reporter files as an unhandled crash with that context dropped.
92 report: (error) =>
93 reportRendererHandledError(error, {
94 surface: "renderer",
95 action: "load-route-chunk",
96 message: "A route chunk stayed unreachable with the server answering",
97 }),
98 // Without storage the guard degrades to "never auto-reload", which is the
99 // safe direction: a missing chunk gets reported instead of looping.
100 readReloadFlag: () => (storage ? storage.getItem(RELOAD_FLAG_KEY) !== null : true),
101 writeReloadFlag: () => storage?.setItem(RELOAD_FLAG_KEY, "1"),
102 delay: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
103 };
104};
105
106/**
107 * Install the preload-error recovery path. Safe to call outside a browser

Callers 2

environmentFunction · 0.90

Calls 2

sessionFlagFunction · 0.85

Tested by 1

environmentFunction · 0.72