Skip to content

Commit fb41649

Browse files
committed
fix(site): report initial URL in visual editing history.subscribe so Presentation enables location navigation
1 parent 6a69d71 commit fb41649

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

‎apps/site/src/layouts/BaseLayout.astro‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,18 @@ const graph = buildGraph([
330330
enableVisualEditing({
331331
history: {
332332
subscribe: (navigate) => {
333+
// Immediately report the current URL on initial mount so Sanity
334+
// Presentation sets frameStateRef.current.url — otherwise
335+
// useNavigatePreviewFrame ignores subsequent location clicks.
336+
navigate({
337+
type: "replace",
338+
url: `${window.location.pathname}${window.location.search}${window.location.hash}`,
339+
});
333340
const onPopState = () => {
334-
navigate({ type: "pop", url: window.location.href });
341+
navigate({
342+
type: "pop",
343+
url: `${window.location.pathname}${window.location.search}${window.location.hash}`,
344+
});
335345
};
336346
window.addEventListener("popstate", onPopState);
337347
return () => window.removeEventListener("popstate", onPopState);
@@ -351,10 +361,12 @@ const graph = buildGraph([
351361
currentPerspective,
352362
);
353363
}
354-
if (update.type === "replace") {
355-
window.location.replace(nextUrl.toString());
356-
} else {
357-
window.location.assign(nextUrl.toString());
364+
if (nextUrl.href !== window.location.href) {
365+
if (update.type === "replace") {
366+
window.location.replace(nextUrl.toString());
367+
} else {
368+
window.location.assign(nextUrl.toString());
369+
}
358370
}
359371
} else if (update.type === "pop") {
360372
window.history.back();

0 commit comments

Comments
 (0)