Fix preview pane getting stuck during auto-refresh on rapid builds

The refresh mechanism posted a JSON-RPC `refresh` command to the nested
iframe.diy frames. During rapid build cycles, the command could be
silently dropped when the inner iframe was mid-reload, not yet mounted,
or when the outer frame's handshake was still pending \u2014 leaving the
preview stuck on a stale build with no way to recover short of reloading
the whole page.

Switch to remounting the iframe via a React key bump, which always works
regardless of handshake state. Also fix a bug in the injected preview
script where `++rpcId` (a function) silently corrupted the id generator
to NaN, breaking navigation state and uncaught error reporting.
This commit is contained in:
Alex Gleason committed 2026-04-17 17:40:34 -05:00
1 parent 565ae93aed
commit 6da4b63a85
2 files changed
+18 -6

No files matched your search

+3 -3
View File
@@ -142,7 +142,7 @@ export function getPreviewInjectedScript(): string {
try {
window.parent.postMessage({
jsonrpc: '2.0',
id: ++rpcId,
id: rpcId(),
method: 'updateNavigationState',
params: {
currentUrl: semanticPath,
@@ -259,7 +259,7 @@ export function getPreviewInjectedScript(): string {
try {
window.parent.postMessage({
jsonrpc: '2.0',
id: ++rpcId,
id: rpcId(),
method: 'console',
params: {
level: 'error',
@@ -279,7 +279,7 @@ export function getPreviewInjectedScript(): string {
try {
window.parent.postMessage({
jsonrpc: '2.0',
id: ++rpcId,
id: rpcId(),
method: 'console',
params: {
level: 'error',