Skip to content

Commit d4d8253

Browse files
committed
Merge branch 'main' into parallelize-async-work
2 parents 06d43df + 2344b40 commit d4d8253

File tree

38 files changed

+501
-38
lines changed

38 files changed

+501
-38
lines changed

.changeset/ninety-olives-report.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: replace `undefined` with `void(0)` in CallExpressions

.changeset/wise-schools-report.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: place store setup inside async body

documentation/docs/07-misc/04-custom-elements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Custom elements
44

55
<!-- - [basically what we have today](https://svelte.dev/docs/custom-elements-api) -->
66

7-
Svelte components can also be compiled to custom elements (aka web components) using the `customElement: true` compiler option. You should specify a tag name for the component using the `<svelte:options>` [element](svelte-options).
7+
Svelte components can also be compiled to custom elements (aka web components) using the `customElement: true` compiler option. You should specify a tag name for the component using the `<svelte:options>` [element](svelte-options). Within the custom element you can access the host element via the [`$host`](https://svelte.dev/docs/svelte/$host) rune.
88

99
```svelte
1010
<svelte:options customElement="my-element" />

packages/svelte/CHANGELOG.md

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

3+
## 5.38.6
4+
5+
### Patch Changes
6+
7+
- fix: don't fail on `flushSync` while flushing effects ([#16674](https://github.com/sveltejs/svelte/pull/16674))
8+
9+
## 5.38.5
10+
11+
### Patch Changes
12+
13+
- fix: ensure async deriveds always get dependencies from thennable ([#16672](https://github.com/sveltejs/svelte/pull/16672))
14+
15+
## 5.38.4
16+
17+
### Patch Changes
18+
19+
- fix: place instance-level snippets inside async body ([#16666](https://github.com/sveltejs/svelte/pull/16666))
20+
21+
- fix: Add check for builtin custom elements in `set_custom_element_data` ([#16592](https://github.com/sveltejs/svelte/pull/16592))
22+
23+
- fix: restore batch along with effect context ([#16668](https://github.com/sveltejs/svelte/pull/16668))
24+
25+
- fix: wait until changes propagate before updating input selection state ([#16649](https://github.com/sveltejs/svelte/pull/16649))
26+
27+
- fix: add "Accept-CH" as valid value for `http-equiv` ([#16671](https://github.com/sveltejs/svelte/pull/16671))
28+
329
## 5.38.3
430

531
### Patch Changes

packages/svelte/elements.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ export interface HTMLMetaAttributes extends HTMLAttributes<HTMLMetaElement> {
12681268
charset?: string | undefined | null;
12691269
content?: string | undefined | null;
12701270
'http-equiv'?:
1271+
| 'accept-ch'
12711272
| 'content-security-policy'
12721273
| 'content-type'
12731274
| 'default-style'

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

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,41 @@ export function client_component(analysis, options) {
362362

363363
let component_block = b.block([
364364
store_init,
365-
...store_setup,
366365
...legacy_reactive_declarations,
367-
...group_binding_declarations,
368-
...state.instance_level_snippets
366+
...group_binding_declarations
369367
]);
370368

369+
const should_inject_context =
370+
dev ||
371+
analysis.needs_context ||
372+
analysis.reactive_statements.size > 0 ||
373+
component_returned_object.length > 0;
374+
371375
if (analysis.instance.has_await) {
376+
if (should_inject_context && component_returned_object.length > 0) {
377+
component_block.body.push(b.var('$$exports'));
378+
}
372379
const body = b.block([
380+
...store_setup,
381+
...state.instance_level_snippets,
373382
.../** @type {ESTree.Statement[]} */ (instance.body),
383+
...(should_inject_context && component_returned_object.length > 0
384+
? [b.stmt(b.assignment('=', b.id('$$exports'), b.object(component_returned_object)))]
385+
: []),
374386
b.if(b.call('$.aborted'), b.return()),
375387
.../** @type {ESTree.Statement[]} */ (template.body)
376388
]);
377389

378390
component_block.body.push(b.stmt(b.call(`$.async_body`, b.arrow([], body, true))));
379391
} else {
380-
component_block.body.push(.../** @type {ESTree.Statement[]} */ (instance.body));
392+
component_block.body.push(
393+
...state.instance_level_snippets,
394+
.../** @type {ESTree.Statement[]} */ (instance.body)
395+
);
396+
if (should_inject_context && component_returned_object.length > 0) {
397+
component_block.body.push(b.var('$$exports', b.object(component_returned_object)));
398+
}
399+
component_block.body.unshift(...store_setup);
381400

382401
if (!analysis.runes && analysis.needs_context) {
383402
component_block.body.push(b.stmt(b.call('$.init', analysis.immutable ? b.true : undefined)));
@@ -392,12 +411,6 @@ export function client_component(analysis, options) {
392411
);
393412
}
394413

395-
const should_inject_context =
396-
dev ||
397-
analysis.needs_context ||
398-
analysis.reactive_statements.size > 0 ||
399-
component_returned_object.length > 0;
400-
401414
let should_inject_props =
402415
should_inject_context ||
403416
analysis.needs_props ||
@@ -444,7 +457,7 @@ export function client_component(analysis, options) {
444457
let to_push;
445458

446459
if (component_returned_object.length > 0) {
447-
let pop_call = b.call('$.pop', b.object(component_returned_object));
460+
let pop_call = b.call('$.pop', b.id('$$exports'));
448461
to_push = needs_store_cleanup ? b.var('$$pop', pop_call) : b.return(pop_call);
449462
} else {
450463
to_push = b.stmt(b.call('$.pop'));
@@ -455,6 +468,7 @@ export function client_component(analysis, options) {
455468

456469
if (needs_store_cleanup) {
457470
component_block.body.push(b.stmt(b.call('$$cleanup')));
471+
458472
if (component_returned_object.length > 0) {
459473
component_block.body.push(b.return(b.id('$$pop')));
460474
}

packages/svelte/src/compiler/utils/builders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ export function call(callee, ...args) {
100100
if (typeof callee === 'string') callee = id(callee);
101101
args = args.slice();
102102

103-
// replacing missing arguments with `undefined`, unless they're at the end in which case remove them
103+
// replacing missing arguments with `void(0)`, unless they're at the end in which case remove them
104104
let i = args.length;
105105
let popping = true;
106106
while (i--) {
107107
if (!args[i]) {
108108
if (popping) {
109109
args.pop();
110110
} else {
111-
args[i] = id('undefined');
111+
args[i] = void0;
112112
}
113113
} else {
114114
popping = false;

packages/svelte/src/internal/client/dom/blocks/boundary.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/** @import { Effect, Source, TemplateNode, } from '#client' */
2-
import {
3-
BOUNDARY_EFFECT,
4-
EFFECT_PRESERVED,
5-
EFFECT_RAN,
6-
EFFECT_TRANSPARENT
7-
} from '#client/constants';
2+
import { BOUNDARY_EFFECT, EFFECT_PRESERVED, EFFECT_TRANSPARENT } from '#client/constants';
83
import { component_context, set_component_context } from '../../context.js';
94
import { handle_error, invoke_error_boundary } from '../../error-handling.js';
105
import { block, branch, destroy_effect, pause_effect } from '../../reactivity/effects.js';

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ export function set_custom_element_data(node, prop, value) {
238238
// Don't compute setters for custom elements while they aren't registered yet,
239239
// because during their upgrade/instantiation they might add more setters.
240240
// Instead, fall back to a simple "an object, then set as property" heuristic.
241-
(setters_cache.has(node.nodeName) ||
241+
(setters_cache.has(node.getAttribute('is') || node.nodeName) ||
242242
// customElements may not be available in browser extension contexts
243243
!customElements ||
244-
customElements.get(node.tagName.toLowerCase())
244+
customElements.get(node.getAttribute('is') || node.tagName.toLowerCase())
245245
? get_setters(node).includes(prop)
246246
: value && typeof value === 'object')
247247
) {
@@ -546,9 +546,10 @@ var setters_cache = new Map();
546546

547547
/** @param {Element} element */
548548
function get_setters(element) {
549-
var setters = setters_cache.get(element.nodeName);
549+
var cache_key = element.getAttribute('is') || element.nodeName;
550+
var setters = setters_cache.get(cache_key);
550551
if (setters) return setters;
551-
setters_cache.set(element.nodeName, (setters = []));
552+
setters_cache.set(cache_key, (setters = []));
552553

553554
var descriptors;
554555
var proto = element; // In the case of custom elements there might be setters on the instance

0 commit comments

Comments
 (0)