Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions packages/qwik-city/src/runtime/src/qwik-city-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
_weakSerialize,
useStyles$,
_waitUntilRendered,
untrack,
type QRL,
} from '@builder.io/qwik';
import { isBrowser, isDev, isServer } from '@builder.io/qwik';
Expand Down Expand Up @@ -291,7 +292,9 @@ export const QwikCityProvider = component$<QwikCityProps>((props) => {
}

actionState.value = undefined;
routeLocation.isNavigating = true;
untrack(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you put all the assignments into a single untrack?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right @wmertens !
I fixed the SPA navigation bug by implementing a single untrack() block for all store mutations, ensuring proper scheduling and preventing unnecessary re-executions during navigation.

routeLocation.isNavigating = true;
});

return new Promise<void>((resolve) => {
navResolver.r = resolve;
Expand Down Expand Up @@ -390,29 +393,39 @@ export const QwikCityProvider = component$<QwikCityProps>((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 };

// Needs to be done after routeLocation is updated
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) {
Expand Down Expand Up @@ -617,7 +630,9 @@ export const QwikCityProvider = component$<QwikCityProps>((props) => {
saveScrollHistory(scrollState);
win._qCityScrollEnabled = true;

routeLocation.isNavigating = false;
untrack(() => {
routeLocation.isNavigating = false;
});
navResolver.r?.();
});
}
Expand Down