Skip to content

Design: keep big boards responsive while selecting, zooming and panning - #10197

Open
shomix wants to merge 6 commits into
mainfrom
shomix-p-design-imprv
Open

shomix wants to merge 6 commits into
mainfrom
shomix-p-design-imprv

Conversation

@shomix

@shomix shomix commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

A batch of Design editor fixes for large boards: screens you're looking at always load, off-screen and overview screens stop animating, marquee selection and the layers panel stop doing per-move work that grows with node count, and the hot paths that scan whole screen HTML get cheaper.

What changes

1. Screens in view load past the byte budget. Source demand now reports inView (the previews on screen now, nearest first) next to pinned and preview. Hydration admits up to SOURCE_HYDRATION_MAX_IN_VIEW (16) of those regardless of the byte budget, so a few multi-megabyte screens nearby can't leave the one you're looking at as a gray placeholder. In-view sources don't count against the budget and are never evicted while in view. While the camera moves, the previous inView list is kept so panning doesn't churn it.

2. Animations pause where nobody is editing. The canvas sends set-animations-paused to each screen's iframes when the screen leaves the visible tier, or for every screen when zoom drops below 25% (overview). The focused interact screen is always exempt. Inside the frame this pauses CSS animations with a style, running Web Animations with pause(), SVG with pauseAnimations(), and stops the shader runtime's loop (it still draws one frame when a canvas scrolls into view). A frame that boots while its screen is paused gets the message on load.

3. Marquee selection without per-move re-renders. The marquee rectangle is written straight to the DOM during the drag instead of through state, which re-rendered the whole canvas every frame. Resolving hit layers no longer scans linearly: source ids get a per-projection index and ancestor chains are built once per tree, both in WeakMaps keyed by the array so a rebuilt projection gets fresh ones. A clear-selection request mid-drag is ignored, since the next move sets selection and rectangle again. Passive selection overlays now read every placement before writing any, so placing many overlays costs one layout. There's a new canvas-bench action for this:

pnpm perf:canvas-bench --action marquee --design HWQT49x1B75KY8b-Hn3EV

4. Layers panel mounts only the rows near the viewport. Rows are windowed (12 rows of overscan, scroll position bucketed to 6 rows) with spacer divs above and below. The row being renamed and the row being dragged stay mounted. Selection for shift/cmd clicks is read from the row data instead of the DOM, and scroll-to-selected works for rows that aren't mounted. LayerGlyph is memoized on the fields it reads.

5. Selection measurement stops retrying pointless misses. The bridge's measure reply now carries ready (document finished loading). A loaded frame that says "not found" ends the retry loop right away; silence and not-yet-loaded frames still retry. Layer actions pass share: true, so concurrent first attempts for the same screen, selector and windows join one request. Re-measures after an edit don't share, so they never get the pre-edit size.

6. Editing-safety sync runs at most once per frame. The embedded-wheel bridge used to walk document.getAnimations() on every mutation batch, resize and gesture-mode message. Now mutations and resizes schedule one sync per animation frame, gesture-mode messages only sync when the flag flips, and managed motion names are cached until a stylesheet changes. Two gaps closed on the way: page script removing the freeze style re-syncs, and a managed (non-infinite) animation starting from :hover or similar also triggers a sync.

7. Cheaper scans of full screen HTML. Several paths run over multi-megabyte screen content on render or mount:

  • The tag scanner behind injectDocumentMarkup in core jumps between tags with sticky regexes instead of stepping characters. The spec checks it places markup exactly where the old character-by-character tokenizer did.
  • mayHaveFrameTypeMarker (HubSpot) no longer lowercases a copy of the whole screen.
  • sourceReferences matches attribute values with a negated class instead of a lazy .*?\1, which walked inlined data URLs one character at a time:
// before
/<(?:link|script|img|source|use)\b[^>]*?\b(?:href|src)\s*=\s*(["'])(.*?)\1/gi
// after
/<(?:link|script|img|source|use)\b[^>]*?\b(?:href|src)\s*=\s*(?:"([^"\n\r

]*)"|'([^'\n\r

]*)')/gi
  • ensureNativeShaderRuntime and selectedNativeInstances skip parsing when the marker string isn't present, and the effects-manifest check in Screen is memoized.

8. Fewer canvas and chat re-renders. Zoom steps, source demand updates and the hydration revision bump run in startTransition. areScreenPropsEqual ignores renderBreakpointContent for screens without breakpoint frames, and the screen layer selection keeps its identity when the rect didn't change. ReviewCanvasPins only sets up its observers when it renders pins, and skips a re-render when a camera move left the canvas where it was. In the toolkit, adding or removing a chat context item without focusing the composer goes through a transition, so it no longer blocks the page.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved issues leave canvas pins stale, break animation pause/resume behavior, defer visible screens, and trigger unnecessary rendering during chat updates and layer dragging.

6 open issues
What changed in this PR

This PR targets large-board responsiveness in the Design editor, with supporting optimizations in core HTML processing and toolkit chat rendering.

Changes:

  • Adds in-view source admission and animation pausing for overview and off-screen content.
  • Reduces selection and rendering work through indexed layer lookups, windowed rows, batched overlay placement, and shared measurements.
  • Optimizes full-document scans and adds regression tests, a marquee benchmark, and package changesets.
File Description
templates/​design/​shared/​shader-fills.ts Skips runtime parsing when the native marker is absent.
templates/​design/​shared/​shader-fills.runtime-memo.test.ts Updates runtime parsing coverage.
templates/​design/​shared/​hubspot-email.ts Avoids lowercasing whole documents during marker detection.
templates/​design/​shared/​hubspot-email.spec.ts Checks marker-scan equivalence and case handling.
templates/​design/​scripts/​canvas-bench/​actions/​marquee.ts Adds marquee correctness and latency benchmarking.
templates/​design/​app/​pages/​design-editor/​use-design-source-hydration.ts Passes in-view demand and transitions hydration updates.
templates/​design/​app/​pages/​design-editor/​source-hydration.ts Exempts admitted in-view sources from byte limits.
templates/​design/​app/​pages/​design-editor/​source-hydration.test.ts Covers admission, eviction, and changing demand.
templates/​design/​app/​pages/​design-editor/​source-dependencies.ts Optimizes HTML reference matching.
templates/​design/​app/​pages/​design-editor/​source-dependencies.test.ts Covers large attributes and dependency rescanning.
templates/​design/​app/​pages/​design-editor/​domains/​use-editor-layer-actions.ts Enables shared initial selection measurements.
templates/​design/​app/​pages/​design-editor/​domains/​use-editor-generation-and-access.ts Tracks and transitions in-view source demand.
templates/​design/​app/​pages/​design-editor/​domains/​use-editor-generation-and-access.source-persistence.test.tsx Updates source-demand fixtures.
templates/​design/​app/​pages/​design-editor/​domains/​use-editor-active-screen-and-geometry.ts Transitions zoom-step updates.
templates/​design/​app/​pages/​design-editor/​commands/​layer-marquee-selection-change.ts Supplies computed styles when marquee payloads omit them.
templates/​design/​app/​pages/​design-editor/​code-layer-state.ts Indexes source IDs and caches ancestor links.
templates/​design/​app/​pages/​design-editor/​code-layer-state.spec.ts Tests cached ancestor lookup behavior.
templates/​design/​app/​components/​visual-editor/​ReviewCanvasPins.tsx Limits observer setup and filters layout updates.
templates/​design/​app/​components/​design/​MultiScreenCanvas.tsx Coordinates animation pausing, source demand, and cheaper rendering.
templates/​design/​app/​components/​design/​MultiScreenCanvas.screen-props-equal.test.ts Tests breakpoint-renderer comparison behavior.
templates/​design/​app/​components/​design/​multi-screen/​types.ts Adds in-view source-demand metadata.
templates/​design/​app/​components/​design/​multi-screen/​source-demand.ts Reports currently visible preview sources.
templates/​design/​app/​components/​design/​multi-screen/​measure-selection.ts Shares measurements and distinguishes retry outcomes.
templates/​design/​app/​components/​design/​multi-screen/​measure-selection.spec.ts Covers measurement sharing and readiness handling.
templates/​design/​app/​components/​design/​multi-screen/​culling.ts Defines animation-pause eligibility.
templates/​design/​app/​components/​design/​multi-screen/​culling.animation-pause.test.ts Tests zoom thresholds and focused-screen exemptions.
templates/​design/​app/​components/​design/​LayersPanel.windowed-selection.test.tsx Tests selection across unmounted rows.
templates/​design/​app/​components/​design/​LayersPanel.tsx Windows rows and memoizes layer glyphs.
templates/​design/​app/​components/​design/​inspector/​NativeShaderPanel.tsx Skips effects parsing when no marker is present.
templates/​design/​app/​components/​design/​bridge/​shader-runtime.frame-budget.spec.ts Tests shader mounting while paused.
templates/​design/​app/​components/​design/​bridge/​shader-runtime.bridge.ts Stops continuous shader rendering while paused.
templates/​design/​app/​components/​design/​bridge/​passive-overlay-placement.bridge.spec.ts Checks batched overlay placement across transforms.
templates/​design/​app/​components/​design/​bridge/​embedded-wheel.bridge.ts Batches safety synchronization and handles animation pausing.
templates/​design/​app/​components/​design/​bridge/​editor-chrome.bridge.ts Batches overlay reads and reports document readiness.
templates/​design/​app/​components/​design/​bridge/​editing-safety-sync.bridge.spec.ts Tests safety synchronization and pause/resume behavior.
templates/​design/​.generated/​bridge/​shader-runtime.generated.ts Regenerates shader pause handling.
templates/​design/​.generated/​bridge/​embedded-wheel.generated.ts Regenerates safety and animation controls.
templates/​design/​.generated/​bridge/​editor-chrome.generated.ts Regenerates overlay and measurement changes.
packages/​toolkit/​src/​app/​chat/​AgentKitAssistantChat.tsx Transitions non-focusing context-item updates.
packages/​core/​src/​shared/​html-document.ts Replaces character scanning with tag-oriented regex scans.
packages/​core/​src/​shared/​html-document.spec.ts Checks equivalence with the previous tokenizer.
.changeset/​html-document-tag-scan.md Records the core performance patch.
.changeset/​chat-context-items-transition.md Records the toolkit rendering patch.

⠀
🟢 Review complete.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical scope-change bug can retain context chips from a previous thread or namespace and include them in the next message because the self-publication check skips re-filtering.

4 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Add pause and resume handling to the native shader renderer

templates/​design/​app/​components/​design/​MultiScreenCanvas.tsx:235

Visible screens with animated native fills continue scheduling and submitting GPU frames below 25% zoom because native-shader-runtime.bridge.ts does not handle set-animations-paused; its compact preview mode only throttles rendering. The new handler in shader-runtime.bridge.ts covers the legacy GLSL renderer, not the native-effects renderer. Add pause/resume handling to the native renderer and regenerate its bridge, preserving one-shot redraws.

Medium severity Allow encoded native-effects markers through the manifest gate

templates/​design/​app/​components/​design/​inspector/​NativeShaderPanel.tsx:478

This literal-string gate rejects valid manifests whose type attribute uses a character reference, such as type="application/x-agent-native-&#101;ffects". parseEffectsFromHtml recognizes that decoded value, but this new early return hides its instances and definitions from the inspector. Keep the gate conservative by allowing possible encoded markers through to the parser, as the HubSpot marker gate already does.

5 resolved since last review

Review effort: Balanced

Comment on lines +18 to +21
style.setAttribute("data-agent-native-animations-paused", "");
style.textContent =
"*,*::before,*::after{animation-play-state:paused!important}";
document.head.appendChild(style);
Comment on lines +28 to +30
pausedAnimations = document.getAnimations().filter(function (animation) {
return animation.playState === "running";
});

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Chat submissions can read stale context during pending transitions, sending a previous selection or an item the user just removed.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

High severity Submit the staged context selection during transitions

packages/​toolkit/​src/​app/​chat/​AgentKitAssistantChat.tsx:4860

If submission occurs while this transition is pending, the send paths still read committed contextItems/visibleContextItems and can send the previous selection instead of the newly staged context. The removal transition at line 4886 can likewise send an item that was just removed. Snapshot submission context from synchronous, scoped state—including provider-owned items—and defer only its visual rendering.

Medium severity Accept character references in supported manifest types

templates/​design/​app/​components/​design/​inspector/​NativeShaderPanel.tsx:478

The literal gate skips valid manifests such as type="application/x-agent-native-&#101;ffects", which the HTML parser decodes to the supported manifest type. Their effects disappear from the inspector because parsing is skipped. Conservatively allow content containing character references through the gate; an extra parse is preferable to hiding an existing effect.

2 resolved since last review

Review effort: Balanced

@steve8708

Copy link
Copy Markdown
Contributor

Failing checks: Design changed-spec diagnostics (changed-31), Design changed-spec diagnostics (changed-39), Design core regression (drag-2b), Fast tests, Runtime budget.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Context cleanup can delete unsent or restaged items during asynchronous preparation, and the pause bridge fails to pause newly created Web Animations and SVG roots.

3 open issues

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The chat send path can transmit removed or outdated context and delete an unsent replacement because sent content and cleanup identities can come from different versions.

5 open issues
1 resolved since last review

Review effort: Balanced

mergeHiddenComposerContextItems(
options.contextItems ?? visibleContextItems,
composerContextItems.hidden,
options.contextItems ?? stagedContextItems,
);
})}
) : null,
...visibleRows.slice(segment.start, segment.end).map((row) => {
if (
!content ||
(!nodeId && !selector) ||
!NATIVE_EFFECT_MANIFEST_MARKER.test(content)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants