Skip to content

Commit f1e2f1b

Browse files
author
Rich Harris
committed
Merge branch 'master' into update-vite-devalue
2 parents 3f51b34 + ef69b7d commit f1e2f1b

File tree

7 files changed

+59
-55
lines changed

7 files changed

+59
-55
lines changed

.changeset/eleven-ravens-turn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: avoid trying to inline raw or url css imports

.changeset/hot-actors-hope.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/kit": patch
3+
---
4+
5+
feat: prerender in worker rather than subprocess to support Deno

packages/kit/src/exports/vite/dev/index.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,17 @@ export async function dev(vite, vite_config, svelte_config) {
176176
const styles = {};
177177

178178
for (const dep of deps) {
179-
const url = new URL(dep.url, 'http://localhost/');
179+
const url = new URL(dep.url, 'dummy:/');
180180
const query = url.searchParams;
181181

182182
if (
183-
isCSSRequest(dep.file) ||
184-
(query.has('svelte') && query.get('type') === 'style')
183+
(isCSSRequest(dep.file) ||
184+
(query.has('svelte') && query.get('type') === 'style')) &&
185+
!(query.has('raw') || query.has('url') || query.has('inline'))
185186
) {
186-
// setting `?inline` to load CSS modules as css string
187-
query.set('inline', '');
188-
189187
try {
190-
const mod = await loud_ssr_load_module(
191-
`${url.pathname}${url.search}${url.hash}`
192-
);
188+
query.set('inline', '');
189+
const mod = await vite.ssrLoadModule(`${url.pathname}${url.search}${url.hash}`);
193190
styles[dep.url] = mod.default;
194191
} catch {
195192
// this can happen with dynamically imported modules, I think

packages/kit/src/utils/fork.js

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fileURLToPath } from 'node:url';
2-
import child_process from 'node:child_process';
2+
import { Worker, parentPort } from 'node:worker_threads';
33

44
/**
55
* Runs a task in a subprocess so any dangling stuff gets killed upon completion.
@@ -11,23 +11,21 @@ import child_process from 'node:child_process';
1111
* @returns {(opts: T) => Promise<U>} A function that when called starts the subprocess
1212
*/
1313
export function forked(module, callback) {
14-
if (process.env.SVELTEKIT_FORK && process.send) {
15-
process.send({ type: 'ready', module });
16-
17-
process.on(
14+
if (process.env.SVELTEKIT_FORK && parentPort) {
15+
parentPort.on(
1816
'message',
1917
/** @param {any} data */ async (data) => {
2018
if (data?.type === 'args' && data.module === module) {
21-
if (process.send) {
22-
process.send({
23-
type: 'result',
24-
module,
25-
payload: await callback(data.payload)
26-
});
27-
}
19+
parentPort?.postMessage({
20+
type: 'result',
21+
module,
22+
payload: await callback(data.payload)
23+
});
2824
}
2925
}
3026
);
27+
28+
parentPort.postMessage({ type: 'ready', module });
3129
}
3230

3331
/**
@@ -36,34 +34,32 @@ export function forked(module, callback) {
3634
*/
3735
const fn = function (opts) {
3836
return new Promise((fulfil, reject) => {
39-
const child = child_process.fork(fileURLToPath(module), {
40-
stdio: 'inherit',
37+
const worker = new Worker(fileURLToPath(module), {
4138
env: {
4239
...process.env,
4340
SVELTEKIT_FORK: 'true'
44-
},
45-
serialization: 'advanced'
41+
}
4642
});
4743

48-
child.on(
44+
worker.on(
4945
'message',
5046
/** @param {any} data */ (data) => {
5147
if (data?.type === 'ready' && data.module === module) {
52-
child.send({
48+
worker.postMessage({
5349
type: 'args',
5450
module,
5551
payload: opts
5652
});
5753
}
5854

5955
if (data?.type === 'result' && data.module === module) {
60-
child.kill();
56+
worker.terminate();
6157
fulfil(data.payload);
6258
}
6359
}
6460
);
6561

66-
child.on('exit', (code) => {
62+
worker.on('exit', (code) => {
6763
if (code) {
6864
reject(new Error(`Failed with code ${code}`));
6965
}

packages/kit/test/apps/basics/src/routes/css/+page.svelte

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<script>
22
import './_styles.css';
3+
import './_manual.css?url';
4+
import './_manual.css?raw';
5+
import './_manual.css?inline';
36
</script>
47

5-
<div class="styled">
6-
this text is red
7-
</div>
8+
<div class="styled">this text is red</div>
89

9-
<div class="also-styled">
10-
this text is blue
11-
</div>
10+
<div class="also-styled">this text is blue</div>
1211

13-
<div class="overridden">
14-
this text is green
15-
</div>
12+
<div class="overridden">this text is green</div>
13+
14+
<div class="not">this text is black</div>
1615

1716
<a href="/css/other">other</a>
1817

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.not {
2+
color: blue;
3+
}

packages/kit/test/apps/basics/test/cross-platform/test.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,28 @@ import { test } from '../../../../utils.js';
66
test.describe.configure({ mode: 'parallel' });
77

88
test.describe('CSS', () => {
9-
test('applies imported styles', async ({ page, get_computed_style }) => {
9+
test('applies styles correctly', async ({ page, get_computed_style }) => {
1010
await page.goto('/css');
1111

12-
expect(await get_computed_style('.styled', 'color')).toBe('rgb(255, 0, 0)');
13-
});
14-
15-
test('applies layout styles', async ({ page, get_computed_style }) => {
16-
await page.goto('/css');
17-
18-
expect(await get_computed_style('footer', 'color')).toBe('rgb(128, 0, 128)');
19-
});
12+
test.step('applies imported styles', async () => {
13+
expect(await get_computed_style('.styled', 'color')).toBe('rgb(255, 0, 0)');
14+
});
2015

21-
test('applies local styles', async ({ page, get_computed_style }) => {
22-
await page.goto('/css');
16+
test.step('applies imported styles in the correct order', async () => {
17+
expect(await get_computed_style('.overridden', 'color')).toBe('rgb(0, 128, 0)');
18+
});
2319

24-
expect(await get_computed_style('.also-styled', 'color')).toBe('rgb(0, 0, 255)');
25-
});
20+
test.step('applies layout styles', async () => {
21+
expect(await get_computed_style('footer', 'color')).toBe('rgb(128, 0, 128)');
22+
});
2623

27-
test('applies imported styles in the correct order', async ({ page, get_computed_style }) => {
28-
await page.goto('/css');
24+
test.step('applies local styles', async () => {
25+
expect(await get_computed_style('.also-styled', 'color')).toBe('rgb(0, 0, 255)');
26+
});
2927

30-
const color = await get_computed_style('.overridden', 'color');
31-
expect(color).toBe('rgb(0, 128, 0)');
28+
test.step('does not apply raw and url', async () => {
29+
expect(await get_computed_style('.not', 'color')).toBe('rgb(0, 0, 0)');
30+
});
3231
});
3332
});
3433

0 commit comments

Comments
 (0)