Skip to content

Commit 61a11a5

Browse files
authored
chore: merge main into async branch (#16197)
* chore: merge main into async branch * adjust test * fix: make effects depend on state created inside them (#16198) * make effects depend on state created inside them * fix, add github action * disable test in async mode
1 parent 6efdc23 commit 61a11a5

File tree

77 files changed

+795
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+795
-166
lines changed

.changeset/fair-laws-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: match class and style directives against attribute selector

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ jobs:
4343
- run: pnpm test
4444
env:
4545
CI: true
46+
TestNoAsync:
47+
permissions: {}
48+
runs-on: ubuntu-latest
49+
timeout-minutes: 10
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: pnpm/action-setup@v4
53+
- uses: actions/setup-node@v4
54+
with:
55+
node-version: 22
56+
cache: pnpm
57+
- run: pnpm install --frozen-lockfile
58+
- run: pnpm playwright install chromium
59+
- run: pnpm test runtime-runes
60+
env:
61+
CI: true
62+
SVELTE_NO_ASYNC: true
4663
Lint:
4764
permissions: {}
4865
runs-on: ubuntu-latest

documentation/docs/07-misc/02-testing.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ test('Effect', () => {
129129
// effects normally run after a microtask,
130130
// use flushSync to execute all pending effects synchronously
131131
flushSync();
132-
expect(log.value).toEqual([0]);
132+
expect(log).toEqual([0]);
133133

134134
count = 1;
135135
flushSync();
136136

137-
expect(log.value).toEqual([0, 1]);
137+
expect(log).toEqual([0, 1]);
138138
});
139139

140140
cleanup();
@@ -148,17 +148,13 @@ test('Effect', () => {
148148
*/
149149
export function logger(getValue) {
150150
/** @type {any[]} */
151-
let log = $state([]);
151+
let log = [];
152152

153153
$effect(() => {
154154
log.push(getValue());
155155
});
156156

157-
return {
158-
get value() {
159-
return log;
160-
}
161-
};
157+
return log;
162158
}
163159
```
164160

packages/svelte/CHANGELOG.md

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

3+
## 5.34.5
4+
5+
### Patch Changes
6+
7+
- fix: keep spread non-delegated event handlers up to date ([#16180](https://github.com/sveltejs/svelte/pull/16180))
8+
9+
- fix: remove undefined attributes on hydration ([#16178](https://github.com/sveltejs/svelte/pull/16178))
10+
11+
- fix: ensure sources within nested effects still register correctly ([#16193](https://github.com/sveltejs/svelte/pull/16193))
12+
13+
- fix: avoid shadowing a variable in dynamic components ([#16185](https://github.com/sveltejs/svelte/pull/16185))
14+
15+
## 5.34.4
16+
17+
### Patch Changes
18+
19+
- fix: don't set state withing `with_parent` in proxy ([#16176](https://github.com/sveltejs/svelte/pull/16176))
20+
21+
- fix: use compiler-driven reactivity in legacy mode template expressions ([#16100](https://github.com/sveltejs/svelte/pull/16100))
22+
323
## 5.34.3
424

525
### Patch Changes

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.34.3",
5+
"version": "5.34.5",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/src/compiler/phases/1-parse/state/tag.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ function open(parser) {
247247
error: null,
248248
pending: null,
249249
then: null,
250-
catch: null
250+
catch: null,
251+
metadata: {
252+
expression: create_expression_metadata()
253+
}
251254
});
252255

253256
if (parser.eat('then')) {
@@ -711,6 +714,9 @@ function special(parser) {
711714
declarations: [{ type: 'VariableDeclarator', id, init, start: id.start, end: init.end }],
712715
start: start + 2, // start at const, not at @const
713716
end: parser.index - 1
717+
},
718+
metadata: {
719+
expression: create_expression_metadata()
714720
}
715721
});
716722
}
@@ -737,6 +743,7 @@ function special(parser) {
737743
end: parser.index,
738744
expression: /** @type {AST.RenderTag['expression']} */ (expression),
739745
metadata: {
746+
expression: create_expression_metadata(),
740747
dynamic: false,
741748
arguments: [],
742749
path: [],

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,7 @@ function relative_selector_might_apply_to_node(relative_selector, rule, element,
532532
}
533533

534534
case 'ClassSelector': {
535-
if (
536-
!attribute_matches(element, 'class', name, '~=', false) &&
537-
!element.attributes.some(
538-
(attribute) => attribute.type === 'ClassDirective' && attribute.name === name
539-
)
540-
) {
535+
if (!attribute_matches(element, 'class', name, '~=', false)) {
541536
return false;
542537
}
543538

@@ -633,6 +628,16 @@ function attribute_matches(node, name, expected_value, operator, case_insensitiv
633628
if (attribute.type === 'SpreadAttribute') return true;
634629
if (attribute.type === 'BindDirective' && attribute.name === name) return true;
635630

631+
// match attributes against the corresponding directive but bail out on exact matching
632+
if (attribute.type === 'StyleDirective' && name.toLowerCase() === 'style') return true;
633+
if (attribute.type === 'ClassDirective' && name.toLowerCase() === 'class') {
634+
if (operator == '~=') {
635+
if (attribute.name === expected_value) return true;
636+
} else {
637+
return true;
638+
}
639+
}
640+
636641
if (attribute.type !== 'Attribute') continue;
637642
if (attribute.name.toLowerCase() !== name.toLowerCase()) continue;
638643

packages/svelte/src/compiler/phases/2-analyze/visitors/AssignmentExpression.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ export function AssignmentExpression(node, context) {
2323
}
2424
}
2525

26+
if (context.state.expression) {
27+
context.state.expression.has_assignment = true;
28+
}
29+
2630
context.next();
2731
}

packages/svelte/src/compiler/phases/2-analyze/visitors/AwaitBlock.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ export function AwaitBlock(node, context) {
4141

4242
mark_subtree_dynamic(context.path);
4343

44-
context.next();
44+
context.visit(node.expression, { ...context.state, expression: node.metadata.expression });
45+
if (node.pending) context.visit(node.pending);
46+
if (node.then) context.visit(node.then);
47+
if (node.catch) context.visit(node.catch);
4548
}

packages/svelte/src/compiler/phases/2-analyze/visitors/ConstTag.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ export function ConstTag(node, context) {
3232
e.const_tag_invalid_placement(node);
3333
}
3434

35-
context.next();
35+
const declaration = node.declaration.declarations[0];
36+
37+
context.visit(declaration.id);
38+
context.visit(declaration.init, { ...context.state, expression: node.metadata.expression });
3639
}

0 commit comments

Comments
 (0)