Skip to content

Commit dce2563

Browse files
committed
Merge branch 'main' into boundary-batch-nullpointer-fix
2 parents 28be8c9 + 9d1aa69 commit dce2563

File tree

22 files changed

+254
-26
lines changed

22 files changed

+254
-26
lines changed

.changeset/cool-garlics-fail.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/silent-pigs-relax.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

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/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

packages/svelte/src/internal/client/dom/elements/bindings/input.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as e from '../../../errors.js';
66
import { is } from '../../../proxy.js';
77
import { queue_micro_task } from '../../task.js';
88
import { hydrating } from '../../hydration.js';
9-
import { untrack } from '../../../runtime.js';
9+
import { tick, untrack } from '../../../runtime.js';
1010
import { is_runes } from '../../../context.js';
1111
import { current_batch, previous_batch } from '../../../reactivity/batch.js';
1212

@@ -17,11 +17,9 @@ import { current_batch, previous_batch } from '../../../reactivity/batch.js';
1717
* @returns {void}
1818
*/
1919
export function bind_value(input, get, set = get) {
20-
var runes = is_runes();
21-
2220
var batches = new WeakSet();
2321

24-
listen_to_event_and_reset_event(input, 'input', (is_reset) => {
22+
listen_to_event_and_reset_event(input, 'input', async (is_reset) => {
2523
if (DEV && input.type === 'checkbox') {
2624
// TODO should this happen in prod too?
2725
e.bind_invalid_checkbox_value();
@@ -36,9 +34,13 @@ export function bind_value(input, get, set = get) {
3634
batches.add(current_batch);
3735
}
3836

39-
// In runes mode, respect any validation in accessors (doesn't apply in legacy mode,
40-
// because we use mutable state which ensures the render effect always runs)
41-
if (runes && value !== (value = get())) {
37+
// Because `{#each ...}` blocks work by updating sources inside the flush,
38+
// we need to wait a tick before checking to see if we should forcibly
39+
// update the input and reset the selection state
40+
await tick();
41+
42+
// Respect any validation in accessors
43+
if (value !== (value = get())) {
4244
var start = input.selectionStart;
4345
var end = input.selectionEnd;
4446

packages/svelte/src/internal/client/reactivity/batch.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class Batch {
190190
// if there are multiple batches, we are 'time travelling' —
191191
// we need to undo the changes belonging to any batch
192192
// other than the current one
193-
if (batches.size > 1) {
193+
if (async_mode_flag && batches.size > 1) {
194194
current_values = new Map();
195195
batch_deriveds = new Map();
196196

@@ -525,6 +525,7 @@ export class Batch {
525525
*/
526526
export function flushSync(fn) {
527527
if (async_mode_flag && active_effect !== null) {
528+
// We disallow this because it creates super-hard to reason about stack trace and because it's generally a bad idea
528529
e.flush_sync_in_effect();
529530
}
530531

@@ -663,7 +664,9 @@ function flush_queued_effects(effects) {
663664
}
664665
}
665666

666-
if (eager_block_effects.length > 0) {
667+
// If update_effect() has a flushSync() in it, we may have flushed another flush_queued_effects(),
668+
// which already handled this logic and did set eager_block_effects to null.
669+
if (eager_block_effects?.length > 0) {
667670
// TODO this feels incorrect! it gets the tests passing
668671
old_values.clear();
669672

packages/svelte/src/internal/client/reactivity/deriveds.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ export function async_derived(fn, location) {
120120

121121
try {
122122
var p = fn();
123+
// Make sure to always access the then property to read any signals
124+
// it might access, so that we track them as dependencies.
125+
if (prev) Promise.resolve(p).catch(() => {}); // avoid unhandled rejection
123126
} catch (error) {
124127
p = Promise.reject(error);
125128
}

0 commit comments

Comments
 (0)