From 477aecdd9379a545d6b0294837603c15e2cc558a Mon Sep 17 00:00:00 2001 From: nehaaaa8 Date: Sun, 13 Jul 2025 22:40:19 +0530 Subject: [PATCH 1/2] fix: ensure store updates go through scheduler during SPA navigation --- .../src/runtime/src/qwik-city-component.tsx | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx index 6bb2099a849..5948f4d1a2f 100644 --- a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx +++ b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx @@ -13,6 +13,7 @@ import { _weakSerialize, useStyles$, _waitUntilRendered, + untrack, type QRL, } from '@builder.io/qwik'; import { isBrowser, isDev, isServer } from '@builder.io/qwik'; @@ -291,7 +292,9 @@ export const QwikCityProvider = component$((props) => { } actionState.value = undefined; - routeLocation.isNavigating = true; + untrack(() => { + routeLocation.isNavigating = true; + }); return new Promise((resolve) => { navResolver.r = resolve; @@ -390,11 +393,17 @@ export const QwikCityProvider = component$((props) => { // Update route location if (!isSamePath(trackUrl, prevUrl)) { - routeLocation.prevUrl = prevUrl; + untrack(() => { + routeLocation.prevUrl = prevUrl; + }); } - routeLocation.url = trackUrl; - routeLocation.params = { ...params }; + untrack(() => { + routeLocation.url = trackUrl; + }); + untrack(() => { + routeLocation.params = { ...params }; + }); (routeInternal as any).untrackedValue = { type: navType, dest: trackUrl }; @@ -402,17 +411,21 @@ export const QwikCityProvider = component$((props) => { const resolvedHead = resolveHead(clientPageData!, routeLocation, contentModules, locale); // Update content - content.headings = pageModule.headings; - content.menu = menu; - contentInternal.value = noSerialize(contentModules); + untrack(() => { + content.headings = pageModule.headings; + content.menu = menu; + contentInternal.value = noSerialize(contentModules); + }); // Update document head - documentHead.links = resolvedHead.links; - documentHead.meta = resolvedHead.meta; - documentHead.styles = resolvedHead.styles; - documentHead.scripts = resolvedHead.scripts; - documentHead.title = resolvedHead.title; - documentHead.frontmatter = resolvedHead.frontmatter; + untrack(() => { + documentHead.links = resolvedHead.links; + documentHead.meta = resolvedHead.meta; + documentHead.styles = resolvedHead.styles; + documentHead.scripts = resolvedHead.scripts; + documentHead.title = resolvedHead.title; + documentHead.frontmatter = resolvedHead.frontmatter; + }); if (isBrowser) { if (props.viewTransition !== false) { @@ -617,7 +630,9 @@ export const QwikCityProvider = component$((props) => { saveScrollHistory(scrollState); win._qCityScrollEnabled = true; - routeLocation.isNavigating = false; + untrack(() => { + routeLocation.isNavigating = false; + }); navResolver.r?.(); }); } From cc71d6ba8779923b0706b924b881995a830e8900 Mon Sep 17 00:00:00 2001 From: naaa760 Date: Mon, 14 Jul 2025 02:06:59 +0530 Subject: [PATCH 2/2] refactor: combine store updates into single untrack() block --- .../src/runtime/src/qwik-city-component.tsx | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx index 5948f4d1a2f..657453435ea 100644 --- a/packages/qwik-city/src/runtime/src/qwik-city-component.tsx +++ b/packages/qwik-city/src/runtime/src/qwik-city-component.tsx @@ -392,33 +392,22 @@ export const QwikCityProvider = component$((props) => { } // Update route location - if (!isSamePath(trackUrl, prevUrl)) { - untrack(() => { - routeLocation.prevUrl = prevUrl; - }); - } - untrack(() => { + if (!isSamePath(trackUrl, prevUrl)) { + routeLocation.prevUrl = prevUrl; + } routeLocation.url = trackUrl; - }); - untrack(() => { routeLocation.params = { ...params }; - }); - (routeInternal as any).untrackedValue = { type: navType, dest: trackUrl }; + // Needs to be done after routeLocation is updated + const resolvedHead = resolveHead(clientPageData!, routeLocation, contentModules, locale); - // Needs to be done after routeLocation is updated - const resolvedHead = resolveHead(clientPageData!, routeLocation, contentModules, locale); - - // Update content - untrack(() => { + // Update content content.headings = pageModule.headings; content.menu = menu; contentInternal.value = noSerialize(contentModules); - }); - // Update document head - untrack(() => { + // Update document head documentHead.links = resolvedHead.links; documentHead.meta = resolvedHead.meta; documentHead.styles = resolvedHead.styles; @@ -427,6 +416,11 @@ export const QwikCityProvider = component$((props) => { documentHead.frontmatter = resolvedHead.frontmatter; }); + (routeInternal as any).untrackedValue = { type: navType, dest: trackUrl }; + + // Needs to be done after routeLocation is updated + const resolvedHead = resolveHead(clientPageData!, routeLocation, contentModules, locale); + if (isBrowser) { if (props.viewTransition !== false) { // mark next DOM render to use startViewTransition API