8000 fix: correctly invalidate static analysis cache of child nodes during dev by eltigerchino · Pull Request #13793 · sveltejs/kit · GitHub
[go: up one dir, main page]

Skip to content

fix: correctly invalidate static analysis cache of child nodes during dev #13793

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

Merged
Merged
Show file tree
Hide file tree
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
Next Next commit
don't cache during dev
  • Loading branch information
eltigerchino committed May 15, 2025
commit 202c7ca73483d5f76ec41a187404a11126e99b84
20 changes: 11 additions & 9 deletions packages/kit/src/exports/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ export async function dev(vite, vite_config, svelte_config) {
return { module, module_node, url };
}

/** @type {(file: string) => void} */
let invalidate_page_options;
/**
*
* @param {string} server_node
* @returns {Promise<Record<string, any>>}
*/
const resolve_server_node = async (server_node) => {
const { module } = await resolve(server_node);
return module;
};

function update_manifest() {
try {
Expand All @@ -128,12 +135,6 @@ export async function dev(vite, vite_config, svelte_config) {
return;
}

const static_analyser = create_static_analyser(async (server_node) => {
const { module } = await resolve(server_node);
return module;
});
invalidate_page_options = static_analyser.invalidate_page_options;

manifest = {
appDir: svelte_config.kit.appDir,
appPath: svelte_config.kit.appDir,
Expand Down Expand Up @@ -211,6 +212,8 @@ export async function dev(vite, vite_config, svelte_config) {
};
}

const static_analyser = create_static_analyser(resolve_server_node);

if (node.universal) {
const page_options = await static_analyser.get_page_options(node);
if (page_options?.ssr === false) {
Expand Down Expand Up @@ -360,7 +363,6 @@ export async function dev(vite, vite_config, svelte_config) {
if (timeout || restarting) return;

sync.update(svelte_config, manifest_data, file);
invalidate_page_options(path.relative(cwd, file));
});

const { appTemplate, errorTemplate, serviceWorker, hooks } = svelte_config.kit.files;
Expand Down
10 changes: 1 addition & 9 deletions packages/kit/src/exports/vite/static_analysis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,5 @@ export function create_static_analyser(resolve) {
return page_options;
};

/**
* @param {string} file
* @returns {void}
*/
const invalidate_page_options = (file) => {
static_exports.delete(file);
};

return { get_page_options, invalidate_page_options };
return { get_page_options };
}
17 changes: 12 additions & 5 deletions packages/kit/test/apps/writes/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,27 @@ test.describe('Filesystem updates', () => {
const file = fileURLToPath(new URL('../src/routes/universal/+page.js', import.meta.url));
const contents = fs.readFileSync(file, 'utf-8');

await page.goto('/universal');
try {
fs.writeFileSync(file, contents.replace(/export const ssr = false;\n/, ''));
await page.goto('/universal', { wait_for_started: false });
expect(await get_computed_style('body', 'background-color')).not.toBe('rgb(255, 0, 0)');
await expect(page.locator('h1')).toHaveText('Internal Error');
} finally {
fs.writeFileSync(file, contents);
}

await page.waitForTimeout(500); // this is the rare time we actually need waitForTimeout; we have no visibility into whether the module graph has been invalidated
await page.reload();
expect(await get_computed_style('body', 'background-color')).toBe('rgb(255, 0, 0)');

try {
fs.writeFileSync(file, contents.replace(/export const ssr = .*;/, 'export const ssr = !1;'));
await page.waitForTimeout(500); // this is the rare time we actually need waitForTimeout; we have no visibility into whether the module graph has been invalidated
await page.goto('/universal', { wait_for_started: false });
51AE expect(await get_computed_style('body', 'background-color')).not.toBe('rgb(255, 0, 0)');
await expect(page.locator('h1')).toHaveText('Internal Error');
} finally {
fs.writeFileSync(
file,
contents.replace(/export const ssr = .*;/, 'export const ssr = false;')
);
fs.writeFileSync(file, contents.replace(/\\nexport const ssr = false;\\n/, ''));
}
});
});
0