Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit de7a2cd

Browse files
authored
Ensure CSS is applied to nested route layouts (#1581)
1 parent dbe703e commit de7a2cd

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

src/core/create_compilers/RollupCompiler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export default class RollupCompiler {
241241
async generateBundle(this: PluginContext, options: NormalizedOutputOptions, bundle: OutputBundle): Promise<void> {
242242

243243
function is_route(file_path: string) {
244-
return file_path.includes(that.routes) && !file_path.includes(path.sep + '_') && !file_path.endsWith('.css');
244+
return file_path.includes(that.routes) && !file_path.endsWith('.css');
245245
}
246246

247247
function js_deps(chunk: RenderedChunk, opts?: DependencyTreeOptions) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h3>This is content defined in a component imported by a layout in a nested routes.</h3>
2+
3+
<style>
4+
h3 {
5+
background-color: rgb(255, 0, 0);
6+
color: #fff;
7+
}
8+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
import NestedRouteTest from '../_components/NestedRouteTest.svelte';
3+
</script>
4+
5+
<h2>This is content defined in a layout in a nested route. It should have a green background.</h2>
6+
7+
<NestedRouteTest/>
8+
9+
<slot></slot>
10+
11+
<style>
12+
h2 {
13+
background-color: rgb(0, 128, 0);
14+
color: #fff;
15+
margin-bottom: 2rem;
16+
}
17+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>This is slotted page content in a nested routes.</p>

test/apps/css/test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ describe('css', function() {
2525
);
2626
});
2727

28+
it('includes CSS defined in nested layout with server render', async () => {
29+
await r.load('/nested');
30+
31+
assert.strictEqual(
32+
await r.page.$eval('h2', node => getComputedStyle(node).backgroundColor),
33+
'rgb(0, 128, 0)'
34+
);
35+
});
36+
37+
it('includes CSS defined in component imported by nested layout with server render', async () => {
38+
await r.load('/nested');
39+
40+
assert.strictEqual(
41+
await r.page.$eval('h3', node => getComputedStyle(node).backgroundColor),
42+
'rgb(255, 0, 0)'
43+
);
44+
});
45+
2846
it('includes CSS on error page', async () => {
2947
await r.load('/doesnotexist');
3048

0 commit comments

Comments
 (0)