Skip to content

fix(preview): rebuild runtime previews after the draft settles, keep the last build meanwhile - #646

Open
ngocht wants to merge 1 commit into
CoreBunch:mainfrom
ngocht:fix/runtime-preview-debounce
Open

ngocht wants to merge 1 commit into
CoreBunch:mainfrom
ngocht:fix/runtime-preview-debounce

Conversation

@ngocht

@ngocht ngocht commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Each runtime preview build POSTs the whole site document to /admin/api/cms/runtime/preview, and the server re-validates it, re-bundles the page scripts and renders the page. The Preview overlay and the Site Explorer hover card rebuilt on every site change. Typing, or a collaborator's edits arriving over collab, aborted the in-flight build and started another. Production nginx logs show bursts of 8 cancelled (499) requests within two seconds, 41 cancelled vs 88 completed in one day. The preview also blanked to "Building…" on each change.

Changes:

  • useRuntimePreviewDocument builds from the draft only once it has stayed unchanged for 400ms (PREVIEW_SITE_SETTLE_MS).
  • While a newer build runs, html keeps the previous build for the same page and template context. PreviewOverlay and SiteExplorerHoverPreview show their loading state only when there is nothing to show yet.

Impact: far fewer full-site uploads and server builds while editing; previews update in place instead of flashing.

Verification

  • bun run build — ran tsc -p tsconfig.app.json (clean)
  • bun test — ran bun test src/__tests__/publisher/previewOverlay.test.tsx src/__tests__/panels: 450 pass. New runtimePreviewSettle.test.tsx: five edits inside the settle window cause one rebuild and the previous build stays visible; fails on main.
  • bun run lint — eslint on the changed files (clean)
  • Docker/deployment check, if relevant

Checklist

  • Tests cover behavior changes.
  • Docs were updated when behavior, config, deployment, or public surfaces changed.
  • No compatibility shim was added for old pre-release behavior.
  • No secrets, local databases, uploads, or generated artifacts are included.

🤖 Generated with Claude Code

…the last build meanwhile

Each runtime preview build POSTs the whole site document and the server
re-validates it, re-bundles the page scripts and renders the page. The
Preview overlay and the Site Explorer hover card rebuilt on every `site`
change, so typing or a collaborator's edits aborted the in-flight build and
started another — production logs show bursts of 8 cancelled requests within
two seconds — and the preview blanked to "Building…" each time.

- useRuntimePreviewDocument builds from the draft only once it has stayed
  unchanged for 400ms (PREVIEW_SITE_SETTLE_MS).
- While a newer build runs, `html` keeps the previous build for the same page
  and context; both callers show the loading state only when there is
  nothing to show yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ngocht
ngocht marked this pull request as ready for review October 14, 2026 18:12

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.

1 participant