Skip to content

Commit 4c9a776

Browse files
committed
Merge branch 'main' into ensure-reactivity
2 parents 5d0a916 + e40e9eb commit 4c9a776

File tree

16 files changed

+140
-47
lines changed

16 files changed

+140
-47
lines changed

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ A `:global` selector cannot modify an existing selector
274274
A `:global` selector can only be modified if it is a descendant of other selectors
275275
```
276276

277+
### css_global_block_invalid_placement
278+
279+
```
280+
A `:global` selector cannot be inside a pseudoclass
281+
```
282+
277283
### css_global_invalid_placement
278284

279285
```

packages/svelte/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# svelte
22

3+
## 5.28.1
4+
5+
### Patch Changes
6+
7+
- fix: ensure `<svelte:boundary>` properly removes error content in production mode ([#15793](https://github.com/sveltejs/svelte/pull/15793))
8+
9+
- fix: `update_version` after `delete` if `source` is `undefined` and `prop` in `target` ([#15796](https://github.com/sveltejs/svelte/pull/15796))
10+
11+
- fix: emit error on wrong placement of the `:global` block selector ([#15794](https://github.com/sveltejs/svelte/pull/15794))
12+
313
## 5.28.0
414

515
### Minor Changes

packages/svelte/messages/compile-errors/style.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ x y {
5050

5151
> A `:global` selector can only be modified if it is a descendant of other selectors
5252
53+
## css_global_block_invalid_placement
54+
55+
> A `:global` selector cannot be inside a pseudoclass
56+
5357
## css_global_invalid_placement
5458

5559
> `:global(...)` can be at the start or end of a selector sequence, but not in the middle

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.28.0",
5+
"version": "5.28.1",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/src/compiler/errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,15 @@ export function css_global_block_invalid_modifier_start(node) {
581581
e(node, 'css_global_block_invalid_modifier_start', `A \`:global\` selector can only be modified if it is a descendant of other selectors\nhttps://svelte.dev/e/css_global_block_invalid_modifier_start`);
582582
}
583583

584+
/**
585+
* A `:global` selector cannot be inside a pseudoclass
586+
* @param {null | number | NodeLike} node
587+
* @returns {never}
588+
*/
589+
export function css_global_block_invalid_placement(node) {
590+
e(node, 'css_global_block_invalid_placement', `A \`:global\` selector cannot be inside a pseudoclass\nhttps://svelte.dev/e/css_global_block_invalid_placement`);
591+
}
592+
584593
/**
585594
* `:global(...)` can be at the start or end of a selector sequence, but not in the middle
586595
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/2-analyze/css/css-analyze.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ const css_visitors = {
6868
const global = node.children.find(is_global);
6969

7070
if (global) {
71-
const idx = node.children.indexOf(global);
71+
const is_nested = context.path.at(-2)?.type === 'PseudoClassSelector';
72+
if (is_nested && !global.selectors[0].args) {
73+
e.css_global_block_invalid_placement(global.selectors[0]);
74+
}
7275

76+
const idx = node.children.indexOf(global);
7377
if (global.selectors[0].args !== null && idx !== 0 && idx !== node.children.length - 1) {
7478
// ensure `:global(...)` is not used in the middle of a selector (but multiple `global(...)` in sequence are ok)
7579
for (let i = idx + 1; i < node.children.length; i++) {

packages/svelte/src/internal/client/proxy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export function proxy(value) {
100100
prop,
101101
with_parent(() => source(UNINITIALIZED, stack))
102102
);
103+
update_version(version);
103104
}
104105
} else {
105106
// When working with arrays, we need to also ensure we update the length when removing

packages/svelte/src/internal/client/runtime.js

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -291,67 +291,58 @@ export function handle_error(error, effect, previous_effect, component_context)
291291
is_throwing_error = true;
292292
}
293293

294-
if (
295-
!DEV ||
296-
component_context === null ||
297-
!(error instanceof Error) ||
298-
handled_errors.has(error)
299-
) {
300-
propagate_error(error, effect);
301-
return;
302-
}
303-
304-
handled_errors.add(error);
294+
if (DEV && component_context !== null && error instanceof Error && !handled_errors.has(error)) {
295+
handled_errors.add(error);
305296

306-
const component_stack = [];
297+
const component_stack = [];
307298

308-
const effect_name = effect.fn?.name;
299+
const effect_name = effect.fn?.name;
309300

310-
if (effect_name) {
311-
component_stack.push(effect_name);
312-
}
301+
if (effect_name) {
302+
component_stack.push(effect_name);
303+
}
313304

314-
/** @type {ComponentContext | null} */
315-
let current_context = component_context;
305+
/** @type {ComponentContext | null} */
306+
let current_context = component_context;
316307

317-
while (current_context !== null) {
318-
if (DEV) {
308+
while (current_context !== null) {
319309
/** @type {string} */
320310
var filename = current_context.function?.[FILENAME];
321311

322312
if (filename) {
323313
const file = filename.split('/').pop();
324314
component_stack.push(file);
325315
}
316+
317+
current_context = current_context.p;
326318
}
327319

328-
current_context = current_context.p;
329-
}
320+
const indent = is_firefox ? ' ' : '\t';
321+
define_property(error, 'message', {
322+
value:
323+
error.message + `\n${component_stack.map((name) => `\n${indent}in ${name}`).join('')}\n`
324+
});
325+
define_property(error, 'component_stack', {
326+
value: component_stack
327+
});
330328

331-
const indent = is_firefox ? ' ' : '\t';
332-
define_property(error, 'message', {
333-
value: error.message + `\n${component_stack.map((name) => `\n${indent}in ${name}`).join('')}\n`
334-
});
335-
define_property(error, 'component_stack', {
336-
value: component_stack
337-
});
338-
339-
const stack = error.stack;
340-
341-
// Filter out internal files from callstack
342-
if (stack) {
343-
const lines = stack.split('\n');
344-
const new_lines = [];
345-
for (let i = 0; i < lines.length; i++) {
346-
const line = lines[i];
347-
if (line.includes('svelte/src/internal')) {
348-
continue;
329+
const stack = error.stack;
330+
331+
// Filter out internal files from callstack
332+
if (stack) {
333+
const lines = stack.split('\n');
334+
const new_lines = [];
335+
for (let i = 0; i < lines.length; i++) {
336+
const line = lines[i];
337+
if (line.includes('svelte/src/internal')) {
338+
continue;
339+
}
340+
new_lines.push(line);
349341
}
350-
new_lines.push(line);
342+
define_property(error, 'stack', {
343+
value: new_lines.join('\n')
344+
});
351345
}
352-
define_property(error, 'stack', {
353-
value: new_lines.join('\n')
354-
});
355346
}
356347

357348
propagate_error(error, effect);

packages/svelte/src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* The current version, as set in package.json.
55
* @type {string}
66
*/
7-
export const VERSION = '5.28.0';
7+
export const VERSION = '5.28.1';
88
export const PUBLIC_VERSION = '5';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: {
5+
code: 'css_global_block_invalid_placement',
6+
message: 'A `:global` selector cannot be inside a pseudoclass',
7+
position: [28, 35]
8+
}
9+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<style>
2+
/* invalid */
3+
:is(:global) { color: red }
4+
</style>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test } from '../../test';
2+
import { flushSync } from 'svelte';
3+
4+
export default test({
5+
html: `<button>delete</button><p>test</p>`,
6+
7+
async test({ assert, target }) {
8+
const btn = target.querySelector('button');
9+
10+
flushSync(() => btn?.click());
11+
assert.htmlEqual(target.innerHTML, '<button>delete</button>');
12+
}
13+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
let obj = $state({test: 0})
3+
4+
let keys = $derived(Object.keys(obj));
5+
</script>
6+
7+
<button onclick={() => delete obj.test}>
8+
delete
9+
</button>
10+
11+
{#each keys as key}
12+
<p>{key}</p>
13+
{/each}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
throw new Error();
3+
</script>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
mode: ['client'],
6+
test({ assert, target }) {
7+
flushSync();
8+
9+
assert.htmlEqual(target.innerHTML, '<p>error occurred</p>');
10+
}
11+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import Child from "./Child.svelte"
3+
</script>
4+
5+
<svelte:boundary>
6+
<p>This should be removed</p>
7+
8+
{#if true}
9+
<Child />
10+
{/if}
11+
12+
{#snippet failed()}
13+
<p>error occurred</p>
14+
{/snippet}
15+
</svelte:boundary>

0 commit comments

Comments
 (0)