Skip to content

Commit

Permalink
omit CSS if ssr=false - fixes #818
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 2, 2021
1 parent 2855f7d commit f3fd750
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-needles-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Only include CSS on an SSR'd page
6 changes: 3 additions & 3 deletions packages/kit/src/runtime/server/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ async function get_response({ request, options, $session, route, status = 200, e
}

// TODO all the `route &&` stuff is messy
const js_deps = route ? route.js : [];
const css_deps = route ? route.css : [];
const style = route ? route.style : '';
const js_deps = route && page_config.ssr ? route.js : [];
const css_deps = route && page_config.ssr ? route.css : [];
const style = route && page_config.ssr ? route.style : '';

const prefix = `${options.paths.assets}/${options.app_dir}`;

Expand Down
2 changes: 2 additions & 0 deletions packages/kit/test/apps/basics/src/routes/ssr/__tests__.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default function (test, is_dev) {
assert.equal(await page.textContent('h1'), 'content was rendered');
} else {
assert.ok(await page.evaluate(() => !document.querySelector('h1')));
assert.ok(await page.evaluate(() => !document.querySelector('style[data-svelte]')));
assert.ok(await page.evaluate(() => !document.querySelector('link[rel=stylesheet]')));
}
});
}
8 changes: 7 additions & 1 deletion packages/kit/test/apps/basics/src/routes/ssr/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
export const ssr = false;
</script>

<h1>content was rendered</h1>
<h1>content was rendered</h1>

<style>
h1 {
color: red;
}
</style>

0 comments on commit f3fd750

Please sign in to comment.