Skip to content

Commit

Permalink
fix(qwik-city): Avoided unexpected caching for dynamic q-data (#6797)
Browse files Browse the repository at this point in the history
  • Loading branch information
genki authored Aug 16, 2024
1 parent 6083989 commit 7adb75a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/docs/src/repl/worker/app-bundle-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const appBundleClient = async (
srcInputs: getInputs(options),
// Older versions don't support `segment`
entryStrategy:
options.entryStrategy.type === 'segment' ? { type: 'hook' } : options.entryStrategy,
options.entryStrategy?.type === 'segment' ? { type: 'hook' } : options.entryStrategy,
manifestOutput: (m) => {
result.manifest = m;
},
Expand Down
16 changes: 14 additions & 2 deletions packages/qwik-city/src/runtime/src/use-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const loadClientData = async (
let resolveFn: () => void | undefined;

if (!qData) {
const fetchOptions = getFetchOptions(opts?.action);
const fetchOptions = getFetchOptions(opts?.action, opts?.clearCache);
if (opts?.action) {
opts.action.data = undefined;
}
Expand Down Expand Up @@ -88,9 +88,21 @@ export const loadClientData = async (
});
};

const getFetchOptions = (action: RouteActionValue | undefined): RequestInit | undefined => {
const getFetchOptions = (
action: RouteActionValue | undefined,
noCache: boolean | undefined
): RequestInit | undefined => {
const actionData = action?.data;
if (!actionData) {
if (noCache) {
return {
cache: 'no-cache',
headers: {
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
},
};
}
return undefined;
}
if (actionData instanceof FormData) {
Expand Down

0 comments on commit 7adb75a

Please sign in to comment.