Skip to content

Commit 3928ce9

Browse files
committed
Merge remote-tracking branch 'origin/main' into inlined-attribute-static
2 parents 805327c + ae9f53a commit 3928ce9

File tree

12 files changed

+86
-10
lines changed

12 files changed

+86
-10
lines changed
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: do not treat reassigned synthetic binds as state in runes mode

.changeset/good-laws-sin.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: account for mutations in script module in ownership check

.changeset/nice-chicken-wonder.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: consider img with loading attribute not static

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ export function analyze_component(root, source, options) {
276276
/** @type {Template} */
277277
const template = { ast: root.fragment, scope, scopes };
278278

279+
let synthetic_stores_legacy_check = [];
280+
279281
// create synthetic bindings for store subscriptions
280282
for (const [name, references] of module.scope.references) {
281283
if (name[0] !== '$' || RESERVED.includes(name)) continue;
@@ -351,16 +353,21 @@ export function analyze_component(root, source, options) {
351353
}
352354
}
353355

354-
// if we are creating a synthetic binding for a let declaration we should also declare
355-
// the declaration as state in case it's reassigned
356-
if (
357-
declaration !== null &&
358-
declaration.kind === 'normal' &&
359-
declaration.declaration_kind === 'let' &&
360-
declaration.reassigned
361-
) {
362-
declaration.kind = 'state';
363-
}
356+
// we push to the array because at this moment in time we can't be sure if we are in legacy
357+
// mode yet because we are still changing the module scope
358+
synthetic_stores_legacy_check.push(() => {
359+
// if we are creating a synthetic binding for a let declaration we should also declare
360+
// the declaration as state in case it's reassigned and we are not in runes mode (the function will
361+
// not be called if we are not in runes mode, that's why there's no !runes check here)
362+
if (
363+
declaration !== null &&
364+
declaration.kind === 'normal' &&
365+
declaration.declaration_kind === 'let' &&
366+
declaration.reassigned
367+
) {
368+
declaration.kind = 'state';
369+
}
370+
});
364371

365372
const binding = instance.scope.declare(b.id(name), 'store_sub', 'synthetic');
366373
binding.references = references;
@@ -373,6 +380,12 @@ export function analyze_component(root, source, options) {
373380

374381
const runes = options.runes ?? Array.from(module.scope.references.keys()).some(is_rune);
375382

383+
if (!runes) {
384+
for (let check of synthetic_stores_legacy_check) {
385+
check();
386+
}
387+
}
388+
376389
if (runes && root.module) {
377390
const context = root.module.attributes.find((attribute) => attribute.name === 'context');
378391
if (context) {

packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ function is_static_element(node, state) {
157157
return false;
158158
}
159159

160+
// We need to apply src and loading after appending the img to the DOM for lazy loading to work
161+
if (node.name === 'img' && attribute.name === 'loading') {
162+
return false;
163+
}
164+
160165
if (node.name.includes('-')) {
161166
return false; // we're setting all attributes on custom elements through properties
162167
}

packages/svelte/src/internal/client/dev/ownership.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export function get_component() {
5959
}
6060

6161
for (const module of modules) {
62+
if (module.end == null) {
63+
return null;
64+
}
6265
if (module.start.line < entry.line && module.end.line > entry.line) {
6366
return module.component;
6467
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<h1></h1><img src="..." loading="lazy" />`
5+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1></h1>
2+
<img src="..." loading="lazy">
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
compileOptions: {
5+
dev: true
6+
}
7+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script module>
2+
let obj = $state({});
3+
obj.test = "hi!";
4+
</script>
5+
6+
<h1>Values: {JSON.stringify(obj)}</h1>

0 commit comments

Comments
 (0)