Skip to content

Commit 6ed0e99

Browse files
Varixowmertens
authored andcommitted
feat: use manifest hash instead of instance hash
1 parent 9038640 commit 6ed0e99

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

packages/qwik-router/src/runtime/src/link-component.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import {
1313
} from '@qwik.dev/core';
1414
import { preloadRouteBundles } from './client-navigate';
1515
import { loadClientData } from './use-endpoint';
16-
import { useInstanceHash, useLocation, useNavigate } from './use-functions';
16+
import { useManifestHash, useLocation, useNavigate } from './use-functions';
1717
import { getClientNavPath, shouldPreload } from './utils';
1818

1919
/** @public */
2020
export const Link = component$<LinkProps>((props) => {
2121
const nav = useNavigate();
2222
const loc = useLocation();
23-
const instanceHash = useInstanceHash();
23+
const manifestHash = useManifestHash();
2424
const originalHref = props.href;
2525
const anchorRef = useSignal<HTMLAnchorElement>();
2626
const {
@@ -54,8 +54,8 @@ export const Link = component$<LinkProps>((props) => {
5454
const url = new URL(elm.href);
5555
preloadRouteBundles(url.pathname);
5656

57-
if (elm.hasAttribute('data-prefetch') && instanceHash) {
58-
loadClientData(url, instanceHash, {
57+
if (elm.hasAttribute('data-prefetch') && manifestHash) {
58+
loadClientData(url, manifestHash, {
5959
preloadRouteBundles: false,
6060
isPrefetch: true,
6161
});

packages/qwik-router/src/runtime/src/qwik-router-component.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import type {
7171
ScrollState,
7272
} from './types';
7373
import { loadClientData } from './use-endpoint';
74-
import { useInstanceHash, useQwikRouterEnv } from './use-functions';
74+
import { useManifestHash, useQwikRouterEnv } from './use-functions';
7575
import { createLoaderSignal, isSameOrigin, isSamePath, toUrl } from './utils';
7676
import { startViewTransition } from './view-transition';
7777

@@ -134,7 +134,7 @@ export const useQwikRouter = (props?: QwikRouterProps) => {
134134
throw new Error(`Missing Qwik URL Env Data`);
135135
}
136136
const serverHead = useServerData<DocumentHeadValue>('documentHead');
137-
const instanceHash = useInstanceHash();
137+
const manifestHash = useManifestHash();
138138

139139
if (isServer) {
140140
if (
@@ -181,7 +181,7 @@ export const useQwikRouter = (props?: QwikRouterProps) => {
181181
key,
182182
url,
183183
getSerializationStrategy(key),
184-
instanceHash!,
184+
manifestHash!,
185185
container
186186
);
187187
}
@@ -355,8 +355,8 @@ export const useQwikRouter = (props?: QwikRouterProps) => {
355355
routeInternal.value = { type, dest, forceReload, replaceState, scroll };
356356

357357
if (isBrowser) {
358-
if (instanceHash) {
359-
loadClientData(dest, instanceHash);
358+
if (manifestHash) {
359+
loadClientData(dest, manifestHash);
360360
}
361361
loadRoute(
362362
qwikRouterConfig.routes,
@@ -421,8 +421,8 @@ export const useQwikRouter = (props?: QwikRouterProps) => {
421421
);
422422
elm = _getContextElement();
423423
const pageData =
424-
instanceHash &&
425-
(clientPageData = await loadClientData(trackUrl, instanceHash, {
424+
manifestHash &&
425+
(clientPageData = await loadClientData(trackUrl, manifestHash, {
426426
action,
427427
clearCache: true,
428428
}));
@@ -547,7 +547,7 @@ export const useQwikRouter = (props?: QwikRouterProps) => {
547547
key,
548548
trackUrl,
549549
DEFAULT_LOADERS_SERIALIZATION_STRATEGY,
550-
instanceHash!,
550+
manifestHash!,
551551
container
552552
);
553553
} else {

packages/qwik-router/src/runtime/src/use-endpoint.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ interface LoaderDataResponse {
88
route: string;
99
}
1010

11-
export const loadClientLoaderData = async (url: URL, loaderId: string, instanceHash: string) => {
11+
export const loadClientLoaderData = async (url: URL, loaderId: string, manifestHash: string) => {
1212
const pagePathname = url.pathname.endsWith('/') ? url.pathname : url.pathname + '/';
13-
return fetchLoader(loaderId, pagePathname, instanceHash);
13+
return fetchLoader(loaderId, pagePathname, manifestHash);
1414
};
1515

1616
export const loadClientData = async (
1717
url: URL,
18-
instanceHash: string,
18+
manifestHash: string,
1919
opts?: {
2020
action?: RouteActionValue;
2121
loaderIds?: string[];
@@ -33,7 +33,7 @@ export const loadClientData = async (
3333
if (!opts?.loaderIds) {
3434
// we need to load all the loaders
3535
// first we need to get the loader urls
36-
loaderData = (await fetchLoaderData(pagePathname, instanceHash)).loaderData;
36+
loaderData = (await fetchLoaderData(pagePathname, manifestHash)).loaderData;
3737
} else {
3838
loaderData = opts.loaderIds.map((loaderId) => {
3939
return {
@@ -47,7 +47,7 @@ export const loadClientData = async (
4747
if (loaderData.length > 0) {
4848
// load specific loaders
4949
const loaderPromises = loaderData.map((loader) =>
50-
fetchLoader(loader.id, loader.route, instanceHash)
50+
fetchLoader(loader.id, loader.route, manifestHash)
5151
);
5252
const loaderResults = await Promise.all(loaderPromises);
5353
for (let i = 0; i < loaderData.length; i++) {
@@ -116,19 +116,19 @@ export const loadClientData = async (
116116

117117
export async function fetchLoaderData(
118118
routePath: string,
119-
instanceHash: string
119+
manifestHash: string
120120
): Promise<{ loaderData: LoaderDataResponse[] }> {
121-
const url = `${routePath}q-loader-data.${instanceHash}.json`;
121+
const url = `${routePath}q-loader-data.${manifestHash}.json`;
122122
const response = await fetch(url);
123123
return response.json();
124124
}
125125

126126
export async function fetchLoader(
127127
loaderId: string,
128128
routePath: string,
129-
instanceHash: string
129+
manifestHash: string
130130
): Promise<unknown> {
131-
const url = `${routePath}q-loader-${loaderId}.${instanceHash}.json`;
131+
const url = `${routePath}q-loader-${loaderId}.${manifestHash}.json`;
132132

133133
const response = await fetch(url);
134134
if (!response.ok) {

packages/qwik-router/src/runtime/src/use-functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export const useAction = (): RouteAction => useContext(RouteActionContext);
9696

9797
export const useQwikRouterEnv = () => noSerialize(useServerData<QwikRouterEnvData>('qwikrouter'));
9898

99-
export const useInstanceHash = () =>
100-
useServerData<Record<string, string>>('containerAttributes')?.['q:instance'];
99+
export const useManifestHash = () =>
100+
useServerData<Record<string, string>>('containerAttributes')?.['q:manifest-hash'];
101101

102102
/** @deprecated Use `useQwikRouterEnv` instead. Will be removed in v3 */
103103
export const useQwikCityEnv = useQwikRouterEnv;

packages/qwik-router/src/runtime/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ export const createLoaderSignal = (
9393
loaderId: string,
9494
url: URL,
9595
serializationStrategy: SerializationStrategy,
96-
instanceHash: string,
96+
manifestHash: string,
9797
container?: ClientContainer
9898
) => {
9999
return createAsyncComputed$(
100100
async () => {
101101
if (isBrowser && loadersObject[loaderId] === _UNINITIALIZED) {
102-
const data = await loadClientLoaderData(url, loaderId, instanceHash);
102+
const data = await loadClientLoaderData(url, loaderId, manifestHash);
103103
loadersObject[loaderId] = data ?? _UNINITIALIZED;
104104
}
105105
return loadersObject[loaderId];

0 commit comments

Comments
 (0)