feat(preview): make address bar interactive for routing inside iframe

This commit is contained in:
2026-06-12 11:57:36 -07:00
parent c1a43d18a6
commit 5ed10c4077
3 changed files with 38 additions and 7 deletions

View File

@@ -152,6 +152,7 @@ export default function PreviewTab() {
const deviceMode = usePreviewToolbarStore((s) => s.deviceMode);
const refreshKey = usePreviewToolbarStore((s) => s.refreshKey);
const currentPath = usePreviewToolbarStore((s) => s.currentPath);
// When the user clicks the manual refresh button in the toolbar, we don't
// just want to reload the iframe — we also want to trigger the same ghost/zombie
@@ -166,8 +167,16 @@ export default function PreviewTab() {
}, [refreshKey]);
useLayoutEffect(() => {
setIframeSrc(primaryRunning?.url ?? null);
}, [primaryRunning?.url]);
if (!primaryRunning?.url) {
setIframeSrc(null);
} else {
const base = primaryRunning.url.replace(/\/$/, "");
const path = currentPath.startsWith("/")
? currentPath
: `/${currentPath}`;
setIframeSrc(`${base}${path}`);
}
}, [primaryRunning?.url, currentPath]);
useEffect(() => {
if (!bridge || !iframeSrc || !iframeDomRef.current) return;