Compress what the browser downloads, and stop one tile taking the page

**nginx served the bundle uncompressed and uncacheable.** The base image
ships gzip commented out and nothing set `Cache-Control`, so every load
carried the whole thing and every reload cost a 304 per asset. Measured on
the built image: the entry chunk 838 kB → 311 kB, the Monaco chunk 2.66 MB
→ 832 kB, and the ~50 content-hashed assets are now immutable for a year.
`index.html` is explicitly `no-cache`, since it is what names the rest.

**A widget that throws no longer blanks the screen.** There was one error
boundary in the app, on the root route, so anything that threw replaced
everything including the navigation — on `/view/{name}`, an unattended wall
panel with no way back. Each tile has its own boundary now, and the app
shell has one inside it so a screen that fails leaves the sidebar standing.
`react-error-boundary` was already a dependency and imported nowhere.

**`localStorage` cannot take the app down.** Reaching it raises where the
browser blocks site data, and `setItem` raises once the origin's quota is
full — which the flow editor's node clipboard, carrying whole Python
sources, can genuinely reach. Thrown from a key handler that escaped to
`window.onerror`, which the single root boundary then turned into a blank
page. `lib/safeStorage.ts` is the guarded pair the pre-paint theme script in
`index.html` was already using; a copy too large to store now says so.

Queries default to `staleTime: 5000` — below every poll interval on any
screen, so nothing polls less often than it did, but a route mounting twice
in a few seconds stops refetching everything it touches. Window-focus
refetching is off: the socket pushes what changes and a reconnect
invalidates what it feeds, so a focus event has nothing of its own to say.
Home alone reads about ten queries on every one of those.

Render cost, two that showed up in the audit:

- `LogsPanel` was rendered unconditionally by the dock and decided inside
  itself whether to draw, so with the panel *shut* it still subscribed to
  the log store and re-filtered five hundred lines per line a flow
  published. It returns before any of that now.
- `HealthActivity` subscribed to the whole engine-event array and used one
  number from it, so a flapping node re-rendered the component that draws
  Home's two uPlot charts — each of which rebuilds its series on every
  render by design. It subscribes to that number.
- the global search bucketed the index nine times per keystroke, once per
  group. One pass, and each group offers at most twenty.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M6hPWS6YEbT1P8LxhhFb2T
This commit is contained in:
2026-08-29 21:00:02 +02:00
co-authored by Claude Opus 5
parent 57eace2226
commit 1873787ee6
12 changed files with 178 additions and 20 deletions
+10 -2
View File
@@ -45,6 +45,8 @@ import {
import useCustomToast from "@/hooks/useCustomToast"
import { useIsMobile } from "@/hooks/useMobile"
import { scaleIn } from "@/lib/motion"
import { notify } from "@/lib/notificationStore"
import { safeStorage } from "@/lib/safeStorage"
import { inCodeEditor, useShortcuts } from "@/lib/shortcuts"
import { cn } from "@/lib/utils"
import { CanvasTitle } from "./CanvasTitle"
@@ -999,10 +1001,16 @@ function FlowEditorInner({
}),
).catch(() => undefined)
localStorage.setItem(
// A multi-node copy carries whole Python sources, which can genuinely
// reach the origin's quota — and a throw from a key handler would take
// the app down rather than the copy.
const stored = safeStorage.set(
CLIPBOARD_KEY,
JSON.stringify({ nodes: picked, sources } satisfies NodeClipboard),
)
if (!stored) {
notify("That is too much to copy — the browser store is full.", "error")
}
}, [canvasNodes, definitions, flowName, selectedId, sourceTypes])
/**
@@ -1011,7 +1019,7 @@ function FlowEditorInner({
* the definition is on its way.
*/
const pasteNodes = useCallback(() => {
const stored = localStorage.getItem(CLIPBOARD_KEY)
const stored = safeStorage.get(CLIPBOARD_KEY)
if (!stored) return
let clipboard: NodeClipboard
try {
+10 -1
View File
@@ -82,7 +82,16 @@ export function LogsTrigger({
* Opening it is not only the dock's to do: a failing node points straight at
* its own traceback, which is why the open state lives in the editor.
*/
export function LogsPanel({
export function LogsPanel(props: { flow: string } & LogsFilter) {
// The dock renders this unconditionally and the `AnimatePresence` inside
// decides whether to draw — so with the panel shut it still subscribed to
// the log store and re-filtered five hundred lines on every line a flow
// published. Nothing below runs until it is open.
if (!props.open) return null
return <OpenLogsPanel {...props} />
}
function OpenLogsPanel({
flow,
open,
node,
+19
View File
@@ -297,6 +297,25 @@ export function useEngineEvents(): EngineEvent[] {
)
}
/**
* The minute the newest engine event landed in, or 0 for none yet.
*
* A scalar, so a subscriber that only wants "has something gone wrong
* lately" re-renders when the answer changes rather than on every event.
* `recordEngineEvent` allocates a new array each time, so subscribing to the
* array itself means a flapping node re-renders whatever is watching — which
* on Home is two uPlot charts that rebuild their series from scratch.
*/
export function useEngineEventMinute(): number {
return useSyncExternalStore(
(listener) => subscribeKey("engine", listener),
() =>
engineEvents.length
? Math.floor(engineEvents[engineEvents.length - 1].ts / 60)
: 0,
)
}
/** Increments each time the node publishes something. */
export function useNodeEmits(nodeId: string): number {
return useSyncExternalStore(