Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qwik-city): Avoided unexpected caching for dynamic q-data #6797

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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,
wmertens marked this conversation as resolved.
Show resolved Hide resolved
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