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

Ensure CSS is applied to nested route layouts #1581

Merged
merged 5 commits into from
Oct 2, 2020
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 src/core/create_compilers/RollupCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class RollupCompiler {
async generateBundle(this: PluginContext, options: NormalizedOutputOptions, bundle: OutputBundle): Promise<void> {

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

function js_deps(chunk: RenderedChunk, opts?: DependencyTreeOptions) {
Expand Down
8 changes: 8 additions & 0 deletions test/apps/css/src/routes/_components/NestedRouteTest.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h3>This is content defined in a component imported by a layout in a nested routes.</h3>

<style>
h3 {
background-color: rgb(255, 0, 0);
color: #fff;
}
</style>
17 changes: 17 additions & 0 deletions test/apps/css/src/routes/nested/_layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
import NestedRouteTest from '../_components/NestedRouteTest.svelte';
</script>

<h2>This is content defined in a layout in a nested route. It should have a green background.</h2>

<NestedRouteTest/>

<slot></slot>

<style>
h2 {
background-color: rgb(0, 128, 0);
color: #fff;
margin-bottom: 2rem;
}
</style>
1 change: 1 addition & 0 deletions test/apps/css/src/routes/nested/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>This is slotted page content in a nested routes.</p>
18 changes: 18 additions & 0 deletions test/apps/css/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ describe('css', function() {
);
});

it('includes CSS defined in nested layout with server render', async () => {
await r.load('/nested');

assert.strictEqual(
await r.page.$eval('h2', node => getComputedStyle(node).backgroundColor),
'rgb(0, 128, 0)'
);
});

it('includes CSS defined in component imported by nested layout with server render', async () => {
await r.load('/nested');

assert.strictEqual(
await r.page.$eval('h3', node => getComputedStyle(node).backgroundColor),
'rgb(255, 0, 0)'
);
});

it('includes CSS on error page', async () => {
await r.load('/doesnotexist');

Expand Down