Skip to content

Commit 1c5a06a

Browse files
committed
fix: remove View Transitions from same-layout swap + cache-bust fetches
Two fixes: - Remove startViewTransition from swapSlotContent to eliminate race conditions where custom elements aren't upgraded during the transition animation. Add a deferred microtask upgrade pass instead. - Add cache: 'no-store' to client router fetches so navigating back to a page always gets fresh server-rendered HTML (critical for seeing newly created posts without a full reload).
1 parent 306c512 commit 1c5a06a

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

packages/core/src/router-client.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ async function performNavigation(href, isPopState) {
149149
const resp = await fetch(href, {
150150
headers: { 'x-webjs-router': '1' },
151151
credentials: 'same-origin',
152+
cache: 'no-store',
152153
});
153154
if (!resp.ok) {
154155
// Fall back to full navigation on error.
@@ -250,21 +251,13 @@ async function performNavigation(href, isPopState) {
250251
* @param {ChildNode[]} children
251252
*/
252253
function swapSlotContent(shell, children) {
253-
const doSwap = () => {
254-
shell.replaceChildren(...children);
255-
reactivateScripts(shell);
256-
upgradeCustomElements(shell);
257-
};
258-
259-
if (/** @type any */ (document).startViewTransition) {
260-
const t = /** @type any */ (document).startViewTransition(doSwap);
261-
// After the View Transition completes, run another upgrade pass.
262-
// During transitions the DOM may not be fully "settled" when the
263-
// callback runs synchronously — a deferred pass catches stragglers.
264-
t.finished.then(() => upgradeCustomElements(shell)).catch(() => {});
265-
} else {
266-
doSwap();
267-
}
254+
shell.replaceChildren(...children);
255+
reactivateScripts(shell);
256+
upgradeCustomElements(shell);
257+
// Schedule a deferred upgrade pass — some browsers delay custom element
258+
// upgrades when elements are inserted during layout/paint. A microtask
259+
// pass catches any stragglers.
260+
queueMicrotask(() => upgradeCustomElements(shell));
268261
}
269262

270263
/**

0 commit comments

Comments
 (0)