svelte 5.57.1 → 5.57.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/index.js +1 -1
- package/package.json +1 -1
- package/src/compiler/errors.js +10 -0
- package/src/compiler/migrate/index.js +15 -4
- package/src/compiler/phases/1-parse/state/tag.js +2 -0
- package/src/compiler/phases/2-analyze/visitors/LetDirective.js +22 -0
- package/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js +32 -7
- package/src/compiler/phases/3-transform/client/visitors/AwaitExpression.js +2 -1
- package/src/compiler/phases/3-transform/client/visitors/shared/events.js +3 -2
- package/src/compiler/phases/scope.js +8 -0
- package/src/compiler/print/index.js +3 -1
- package/src/index-client.js +1 -1
- package/src/internal/client/dev/debug.js +14 -0
- package/src/internal/client/dev/tracing.js +3 -1
- package/src/internal/client/dom/blocks/boundary.js +43 -15
- package/src/internal/client/dom/blocks/each.js +8 -6
- package/src/internal/client/dom/blocks/svelte-element.js +3 -1
- package/src/internal/client/dom/css.js +1 -1
- package/src/internal/client/dom/elements/attributes.js +178 -150
- package/src/internal/client/dom/elements/bindings/document.js +3 -2
- package/src/internal/client/dom/elements/transitions.js +3 -3
- package/src/internal/client/error-handling.js +5 -1
- package/src/internal/client/proxy.js +2 -1
- package/src/internal/client/reactivity/async.js +5 -0
- package/src/internal/client/reactivity/batch.js +82 -116
- package/src/internal/client/reactivity/deriveds.js +2 -1
- package/src/internal/client/reactivity/sources.js +5 -5
- package/src/internal/client/reactivity/utils.js +5 -6
- package/src/internal/client/runtime.js +13 -16
- package/src/internal/server/errors.js +2 -2
- package/src/internal/server/index.js +1 -1
- package/src/reactivity/date.js +2 -2
- package/src/reactivity/url-search-params.js +1 -1
- package/src/version.js +1 -1
- package/types/index.d.ts.map +1 -1
package/package.json
CHANGED
package/src/compiler/errors.js
CHANGED
|
@@ -1213,6 +1213,16 @@ export function let_directive_invalid_placement(node) {
|
|
|
1213
1213
|
e(node, 'let_directive_invalid_placement', `\`let:\` directive at invalid position\nhttps://svelte.dev/e/let_directive_invalid_placement`);
|
|
1214
1214
|
}
|
|
1215
1215
|
|
|
1216
|
+
/**
|
|
1217
|
+
* Cannot use `let:` directives on a component that has a `children` snippet. Use snippet parameters instead (e.g. `{#snippet children({ %name% })}`)
|
|
1218
|
+
* @param {null | number | NodeLike} node
|
|
1219
|
+
* @param {string} name
|
|
1220
|
+
* @returns {never}
|
|
1221
|
+
*/
|
|
1222
|
+
export function let_directive_snippet_conflict(node, name) {
|
|
1223
|
+
e(node, 'let_directive_snippet_conflict', `Cannot use \`let:\` directives on a component that has a \`children\` snippet. Use snippet parameters instead (e.g. \`{#snippet children({ ${name} })}\`)\nhttps://svelte.dev/e/let_directive_snippet_conflict`);
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1216
1226
|
/**
|
|
1217
1227
|
* Mixing old (on:%name%) and new syntaxes for event handling is not allowed. Use only the on%name% syntax
|
|
1218
1228
|
* @param {null | number | NodeLike} node
|
|
@@ -910,8 +910,10 @@ const instance_script = {
|
|
|
910
910
|
start = /** @type {number} */ (parent.start);
|
|
911
911
|
end = /** @type {number} */ (parent.end);
|
|
912
912
|
}
|
|
913
|
-
|
|
914
|
-
|
|
913
|
+
// remove the declaration's whole line, or what there is of it inside the script
|
|
914
|
+
const script = /** @type {{ start: number; end: number }} */ (state.analysis.instance.ast);
|
|
915
|
+
while (start > script.start && state.str.original[start] !== '\n') start--;
|
|
916
|
+
while (end < script.end && state.str.original[end] !== '\n') end++;
|
|
915
917
|
state.str.update(start, end, '');
|
|
916
918
|
}
|
|
917
919
|
},
|
|
@@ -987,8 +989,11 @@ const instance_script = {
|
|
|
987
989
|
return;
|
|
988
990
|
}
|
|
989
991
|
|
|
992
|
+
let declared = 0;
|
|
990
993
|
for (const binding of bindings) {
|
|
991
|
-
|
|
994
|
+
// a binding this statement declares needs its `let` whether or not it is reassigned
|
|
995
|
+
if (ids.includes(binding.node) || (binding.reassigned && expression_ids.length === 0)) {
|
|
996
|
+
declared++;
|
|
992
997
|
check_rune_binding('state');
|
|
993
998
|
const init =
|
|
994
999
|
binding.kind === 'state'
|
|
@@ -1004,7 +1009,13 @@ const instance_script = {
|
|
|
1004
1009
|
}
|
|
1005
1010
|
}
|
|
1006
1011
|
|
|
1007
|
-
|
|
1012
|
+
// the statement goes only once every target has a declaration standing in for it
|
|
1013
|
+
if (
|
|
1014
|
+
expression_ids.length === 0 &&
|
|
1015
|
+
bindings.length > 0 &&
|
|
1016
|
+
declared === bindings.length &&
|
|
1017
|
+
bindings.every((b) => b.kind !== 'store_sub')
|
|
1018
|
+
) {
|
|
1008
1019
|
state.str.remove(/** @type {number} */ (node.start), /** @type {number} */ (node.end));
|
|
1009
1020
|
return;
|
|
1010
1021
|
}
|
|
@@ -532,6 +532,7 @@ function next(parser) {
|
|
|
532
532
|
if (block.type === 'IfBlock') {
|
|
533
533
|
if (!parser.eat('else')) e.expected_token(start, '{:else} or {:else if}');
|
|
534
534
|
if (parser.eat('if')) e.block_invalid_elseif(start);
|
|
535
|
+
if (block.alternate) e.block_duplicate_clause(start, '{:else}');
|
|
535
536
|
|
|
536
537
|
parser.allow_whitespace();
|
|
537
538
|
|
|
@@ -580,6 +581,7 @@ function next(parser) {
|
|
|
580
581
|
|
|
581
582
|
if (block.type === 'EachBlock') {
|
|
582
583
|
if (!parser.eat('else')) e.expected_token(start, '{:else}');
|
|
584
|
+
if (block.fallback) e.block_duplicate_clause(start, '{:else}');
|
|
583
585
|
|
|
584
586
|
parser.allow_whitespace();
|
|
585
587
|
parser.eat('}', true);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @import { AST } from '#compiler' */
|
|
2
2
|
/** @import { Context } from '../types' */
|
|
3
3
|
import * as e from '../../../errors.js';
|
|
4
|
+
import { determine_slot } from '../../../utils/slot.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @param {AST.LetDirective} node
|
|
@@ -21,4 +22,25 @@ export function LetDirective(node, context) {
|
|
|
21
22
|
) {
|
|
22
23
|
e.let_directive_invalid_placement(node);
|
|
23
24
|
}
|
|
25
|
+
|
|
26
|
+
// an explicit `children` snippet replaces the default slot content, so the `let:`
|
|
27
|
+
// directive would never be provided. if the component has a `slot` attribute, the
|
|
28
|
+
// directive applies to the component itself instead, which is fine
|
|
29
|
+
if (
|
|
30
|
+
(parent.type === 'Component' ||
|
|
31
|
+
parent.type === 'SvelteComponent' ||
|
|
32
|
+
parent.type === 'SvelteSelf') &&
|
|
33
|
+
!determine_slot(parent) &&
|
|
34
|
+
parent.fragment.nodes.some(
|
|
35
|
+
(child) => child.type === 'SnippetBlock' && child.expression.name === 'children'
|
|
36
|
+
)
|
|
37
|
+
) {
|
|
38
|
+
const { expression } = node;
|
|
39
|
+
const pattern =
|
|
40
|
+
expression === null || (expression.type === 'Identifier' && expression.name === node.name)
|
|
41
|
+
? node.name
|
|
42
|
+
: `${node.name}: ${context.state.analysis.source.slice(expression.start, expression.end)}`;
|
|
43
|
+
|
|
44
|
+
e.let_directive_snippet_conflict(node, pattern);
|
|
45
|
+
}
|
|
24
46
|
}
|
|
@@ -40,7 +40,8 @@ import {
|
|
|
40
40
|
regex_not_whitespace,
|
|
41
41
|
regex_redundant_img_alt,
|
|
42
42
|
regex_starts_with_vowel,
|
|
43
|
-
regex_whitespaces
|
|
43
|
+
regex_whitespaces,
|
|
44
|
+
regex_whitespaces_strict
|
|
44
45
|
} from '../../../../patterns.js';
|
|
45
46
|
import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js';
|
|
46
47
|
import { list } from '../../../../../utils/string.js';
|
|
@@ -158,9 +159,7 @@ export function check_element(node, context) {
|
|
|
158
159
|
if (typeof value !== 'string') {
|
|
159
160
|
break;
|
|
160
161
|
}
|
|
161
|
-
for (const
|
|
162
|
-
const current_role = /** @type {ARIARoleDefinitionKey} current_role */ (c_r);
|
|
163
|
-
|
|
162
|
+
for (const current_role of get_role_tokens(value)) {
|
|
164
163
|
if (current_role && is_abstract_role(current_role)) {
|
|
165
164
|
w.a11y_no_abstract_role(attribute, current_role);
|
|
166
165
|
} else if (current_role && !aria_roles.includes(current_role)) {
|
|
@@ -173,8 +172,8 @@ export function check_element(node, context) {
|
|
|
173
172
|
current_role === get_implicit_role(node.name, attribute_map) &&
|
|
174
173
|
// <ul role="list"> is ok because CSS list-style:none removes the semantics and this is a way to bring them back
|
|
175
174
|
!['ul', 'ol', 'li', 'menu'].includes(node.name) &&
|
|
176
|
-
// <a role="link" />
|
|
177
|
-
!(node.name === 'a' && !attribute_map.has('href'))
|
|
175
|
+
// <a role="link" /> and <area role="link" /> are ok because without href they don't have a role of link
|
|
176
|
+
!((node.name === 'a' || node.name === 'area') && !attribute_map.has('href'))
|
|
178
177
|
) {
|
|
179
178
|
w.a11y_no_redundant_roles(attribute, current_role);
|
|
180
179
|
}
|
|
@@ -286,7 +285,9 @@ export function check_element(node, context) {
|
|
|
286
285
|
}
|
|
287
286
|
|
|
288
287
|
const role = attribute_map.get('role');
|
|
289
|
-
const role_static_value = /** @type {ARIARoleDefinitionKey} */ (
|
|
288
|
+
const role_static_value = /** @type {ARIARoleDefinitionKey} */ (
|
|
289
|
+
get_effective_role(get_static_text_value(role))
|
|
290
|
+
);
|
|
290
291
|
|
|
291
292
|
// click-events-have-key-events
|
|
292
293
|
if (handlers.has('click')) {
|
|
@@ -778,6 +779,30 @@ function is_abstract_role(role) {
|
|
|
778
779
|
return abstract_roles.includes(role);
|
|
779
780
|
}
|
|
780
781
|
|
|
782
|
+
/**
|
|
783
|
+
* Role tokens use ASCII whitespace and ASCII case-insensitive matching.
|
|
784
|
+
* @param {string} value
|
|
785
|
+
*/
|
|
786
|
+
function get_role_tokens(value) {
|
|
787
|
+
return /** @type {ARIARoleDefinitionKey[]} */ (
|
|
788
|
+
// we use this instead of value.toLowerCase() to avoid lowercasing non-ASCII characters
|
|
789
|
+
value.replace(/[A-Z]/g, (char) => char.toLowerCase()).split(regex_whitespaces_strict)
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* The `role` attribute can list fallback roles, in which case the element
|
|
795
|
+
* gets the first one that is a known, non-abstract role. Preserve the original
|
|
796
|
+
* value if none match, so invalid roles retain their existing diagnostics.
|
|
797
|
+
* @param {string | null} value
|
|
798
|
+
*/
|
|
799
|
+
function get_effective_role(value) {
|
|
800
|
+
if (value === null) return null;
|
|
801
|
+
const roles = get_role_tokens(value);
|
|
802
|
+
// we return the whole value here in case there's no known, non-abstract role in the list
|
|
803
|
+
return roles.find((role) => aria_roles.includes(role) && !is_abstract_role(role)) ?? value;
|
|
804
|
+
}
|
|
805
|
+
|
|
781
806
|
/**
|
|
782
807
|
* @param {AST.Attribute | undefined} attribute
|
|
783
808
|
*/
|
|
@@ -18,7 +18,8 @@ export function AwaitExpression(node, context) {
|
|
|
18
18
|
// in dev, note which values are read inside a reactive expression,
|
|
19
19
|
// but don't track them
|
|
20
20
|
else if (dev && !is_ignored(node, 'await_reactivity_loss')) {
|
|
21
|
-
|
|
21
|
+
// don't use b.await here, this way we preserve location information
|
|
22
|
+
return b.call({ ...node, argument: b.call('$.track_reactivity_loss', argument) });
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
return argument === node.argument ? node : { ...node, argument };
|
|
@@ -119,8 +119,9 @@ export function build_event_handler(node, metadata, context) {
|
|
|
119
119
|
|
|
120
120
|
// local variable can be assigned directly
|
|
121
121
|
// except in dev mode where when need $.apply()
|
|
122
|
-
// in order to handle warnings
|
|
123
|
-
|
|
122
|
+
// in order to handle warnings, or when it is
|
|
123
|
+
// assigned after a top-level `await`
|
|
124
|
+
if (!dev && binding?.declaration_kind !== 'import' && !binding?.blocker) {
|
|
124
125
|
return handler;
|
|
125
126
|
}
|
|
126
127
|
}
|
|
@@ -1343,6 +1343,14 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
|
|
|
1343
1343
|
}
|
|
1344
1344
|
|
|
1345
1345
|
context.next({ scope: child_scope });
|
|
1346
|
+
|
|
1347
|
+
// the parameters and what the body declares end up in the same function
|
|
1348
|
+
const body_scope = /** @type {Scope} */ (scopes.get(node.body));
|
|
1349
|
+
for (const [name, binding] of body_scope.declarations) {
|
|
1350
|
+
if (child_scope.declarations.has(name)) {
|
|
1351
|
+
e.declaration_duplicate(binding.node, name);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1346
1354
|
},
|
|
1347
1355
|
|
|
1348
1356
|
Fragment: (node, context) => {
|
|
@@ -754,7 +754,9 @@ const svelte_visitors = (comments, state) => ({
|
|
|
754
754
|
if (node.pending) {
|
|
755
755
|
context.write('}');
|
|
756
756
|
block(context, node.pending, state.preserve_whitespace > 0);
|
|
757
|
-
|
|
757
|
+
if (node.then || node.catch) {
|
|
758
|
+
context.write('{:');
|
|
759
|
+
}
|
|
758
760
|
} else {
|
|
759
761
|
context.write(' ');
|
|
760
762
|
}
|
package/src/index-client.js
CHANGED
|
@@ -17,7 +17,7 @@ if (DEV) {
|
|
|
17
17
|
if (!(rune in globalThis)) {
|
|
18
18
|
// TODO if people start adjusting the "this can contain runes" config through v-p-s more, adjust this message
|
|
19
19
|
/** @type {any} */
|
|
20
|
-
let value; // let's hope
|
|
20
|
+
let value; // let's hope no one modifies this global, but belts and braces
|
|
21
21
|
Object.defineProperty(globalThis, rune, {
|
|
22
22
|
configurable: true,
|
|
23
23
|
// eslint-disable-next-line getter-return
|
|
@@ -514,3 +514,17 @@ export function log_inconsistent_branches(effect) {
|
|
|
514
514
|
|
|
515
515
|
return true;
|
|
516
516
|
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Stringify a derived function, removing `$.track_reactivity_loss` and `$.get` etc
|
|
520
|
+
* @param {Function} fn
|
|
521
|
+
*/
|
|
522
|
+
export function stringify_derived(fn) {
|
|
523
|
+
return `{${fn
|
|
524
|
+
.toString()
|
|
525
|
+
.replace(/^async \(\) => /, '')
|
|
526
|
+
.replace(/^\(/, '')
|
|
527
|
+
.replace(/\$\.get\((.+?)\)/g, (_, name) => name)
|
|
528
|
+
.replace(/\$\.track_reactivity_loss\((.+?)\)\(\)/g, (_, name) => name)
|
|
529
|
+
.replace(/\)$/, '')}}`;
|
|
530
|
+
}
|
|
@@ -131,8 +131,10 @@ export function trace(label, fn) {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
|
-
* @
|
|
134
|
+
* @template {Value} T
|
|
135
|
+
* @param {T} source
|
|
135
136
|
* @param {string} label
|
|
137
|
+
* @returns {T}
|
|
136
138
|
*/
|
|
137
139
|
export function tag(source, label) {
|
|
138
140
|
source.label = label;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/** @import { Effect, Source, TemplateNode, } from '#client' */
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
BOUNDARY_EFFECT,
|
|
4
|
+
DESTROYED,
|
|
5
|
+
DESTROYING,
|
|
6
|
+
EFFECT_PRESERVED,
|
|
7
|
+
EFFECT_TRANSPARENT
|
|
8
|
+
} from '#client/constants';
|
|
9
|
+
import {
|
|
10
|
+
HYDRATION_ERROR,
|
|
11
|
+
HYDRATION_START_ELSE,
|
|
12
|
+
HYDRATION_START_FAILED
|
|
13
|
+
} from '../../../../constants.js';
|
|
4
14
|
import { component_context, set_component_context } from '../../context.js';
|
|
5
15
|
import { invoke_error_boundary } from '../../error-handling.js';
|
|
6
16
|
import {
|
|
@@ -22,6 +32,7 @@ import {
|
|
|
22
32
|
hydrate_node,
|
|
23
33
|
hydrating,
|
|
24
34
|
next,
|
|
35
|
+
read_hydration_instruction,
|
|
25
36
|
skip_nodes,
|
|
26
37
|
set_hydrate_node
|
|
27
38
|
} from '../hydration.js';
|
|
@@ -101,11 +112,8 @@ export class Boundary {
|
|
|
101
112
|
#pending_count = 0;
|
|
102
113
|
#pending_count_update_queued = false;
|
|
103
114
|
|
|
104
|
-
/** @type {
|
|
105
|
-
#
|
|
106
|
-
|
|
107
|
-
/** @type {Set<Effect>} */
|
|
108
|
-
#maybe_dirty_effects = new Set();
|
|
115
|
+
/** @type {Map<Effect, number>} */
|
|
116
|
+
#dirty_reactions = new Map();
|
|
109
117
|
|
|
110
118
|
/**
|
|
111
119
|
* A source containing the number of pending async deriveds/expressions.
|
|
@@ -154,16 +162,18 @@ export class Boundary {
|
|
|
154
162
|
|
|
155
163
|
this.#effect = block(() => {
|
|
156
164
|
if (hydrating) {
|
|
157
|
-
const
|
|
165
|
+
const comment_data = read_hydration_instruction(
|
|
166
|
+
/** @type {TemplateNode} */ (this.#hydrate_open)
|
|
167
|
+
);
|
|
158
168
|
hydrate_next();
|
|
159
169
|
|
|
160
|
-
const server_rendered_pending =
|
|
161
|
-
const server_rendered_failed =
|
|
170
|
+
const server_rendered_pending = comment_data === HYDRATION_START_ELSE;
|
|
171
|
+
const server_rendered_failed = comment_data.startsWith(HYDRATION_START_FAILED);
|
|
162
172
|
|
|
163
173
|
if (server_rendered_failed) {
|
|
164
174
|
// Server rendered the failed snippet - hydrate it.
|
|
165
175
|
// The serialized error is embedded in the comment: <!--[?<json>-->
|
|
166
|
-
const serialized_error = JSON.parse(
|
|
176
|
+
const serialized_error = JSON.parse(comment_data.slice(HYDRATION_START_FAILED.length));
|
|
167
177
|
this.#hydrate_failed_content(serialized_error);
|
|
168
178
|
} else if (server_rendered_pending) {
|
|
169
179
|
this.#hydrate_pending_content();
|
|
@@ -220,6 +230,8 @@ export class Boundary {
|
|
|
220
230
|
var calling_on_error = false;
|
|
221
231
|
|
|
222
232
|
const reset = () => {
|
|
233
|
+
if (this.#is_destroyed()) return;
|
|
234
|
+
|
|
223
235
|
if (did_reset) {
|
|
224
236
|
w.svelte_boundary_reset_noop();
|
|
225
237
|
return;
|
|
@@ -243,6 +255,8 @@ export class Boundary {
|
|
|
243
255
|
};
|
|
244
256
|
|
|
245
257
|
const invoke_onerror = () => {
|
|
258
|
+
if (this.#is_destroyed()) return;
|
|
259
|
+
|
|
246
260
|
try {
|
|
247
261
|
calling_on_error = true;
|
|
248
262
|
this.#props.onerror?.(error, reset);
|
|
@@ -255,6 +269,10 @@ export class Boundary {
|
|
|
255
269
|
return { reset, invoke_onerror };
|
|
256
270
|
}
|
|
257
271
|
|
|
272
|
+
#is_destroyed() {
|
|
273
|
+
return (this.#effect.f & (DESTROYED | DESTROYING)) !== 0;
|
|
274
|
+
}
|
|
275
|
+
|
|
258
276
|
#hydrate_pending_content() {
|
|
259
277
|
const pending = this.#props.pending;
|
|
260
278
|
if (!pending) return;
|
|
@@ -263,6 +281,8 @@ export class Boundary {
|
|
|
263
281
|
this.#pending_effect = branch(() => pending(this.#anchor));
|
|
264
282
|
|
|
265
283
|
queue_micro_task(() => {
|
|
284
|
+
if (this.#is_destroyed()) return;
|
|
285
|
+
|
|
266
286
|
var fragment = (this.#offscreen_fragment = document.createDocumentFragment());
|
|
267
287
|
var anchor = create_text();
|
|
268
288
|
var handled = false;
|
|
@@ -335,7 +355,7 @@ export class Boundary {
|
|
|
335
355
|
|
|
336
356
|
// any effects that were previously deferred should be transferred
|
|
337
357
|
// to the batch, which will flush in the next microtask
|
|
338
|
-
batch.
|
|
358
|
+
batch.transfer_reactions(this.#dirty_reactions);
|
|
339
359
|
}
|
|
340
360
|
|
|
341
361
|
/**
|
|
@@ -343,7 +363,7 @@ export class Boundary {
|
|
|
343
363
|
* @param {Effect} effect
|
|
344
364
|
*/
|
|
345
365
|
defer_effect(effect) {
|
|
346
|
-
defer_effect(effect, this.#
|
|
366
|
+
defer_effect(effect, this.#dirty_reactions);
|
|
347
367
|
}
|
|
348
368
|
|
|
349
369
|
/**
|
|
@@ -445,6 +465,10 @@ export class Boundary {
|
|
|
445
465
|
|
|
446
466
|
/** @param {unknown} error */
|
|
447
467
|
error(error) {
|
|
468
|
+
if (error === HYDRATION_ERROR) {
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
|
|
448
472
|
// If we have nothing to capture the error, or if we hit an error while
|
|
449
473
|
// rendering the fallback, re-throw for another boundary to handle
|
|
450
474
|
if (!this.#props.onerror && !this.#props.failed) {
|
|
@@ -457,7 +481,7 @@ export class Boundary {
|
|
|
457
481
|
if (this.#failed_effect) current_batch.skip_effect(this.#failed_effect);
|
|
458
482
|
|
|
459
483
|
current_batch.oncommit(() => {
|
|
460
|
-
this.#handle_error(error);
|
|
484
|
+
if (!this.#is_destroyed()) this.#handle_error(error);
|
|
461
485
|
});
|
|
462
486
|
} else {
|
|
463
487
|
this.#handle_error(error);
|
|
@@ -493,11 +517,13 @@ export class Boundary {
|
|
|
493
517
|
|
|
494
518
|
/** @param {unknown} transformed_error */
|
|
495
519
|
const handle_error_result = (transformed_error) => {
|
|
520
|
+
if (this.#is_destroyed()) return;
|
|
521
|
+
|
|
496
522
|
const { reset, invoke_onerror } = this.#create_reset(transformed_error);
|
|
497
523
|
|
|
498
524
|
invoke_onerror();
|
|
499
525
|
|
|
500
|
-
if (failed) {
|
|
526
|
+
if (failed && !this.#is_destroyed()) {
|
|
501
527
|
this.#failed_effect = this.#run(() => {
|
|
502
528
|
try {
|
|
503
529
|
return branch(() => {
|
|
@@ -523,6 +549,8 @@ export class Boundary {
|
|
|
523
549
|
};
|
|
524
550
|
|
|
525
551
|
queue_micro_task(() => {
|
|
552
|
+
if (this.#is_destroyed()) return;
|
|
553
|
+
|
|
526
554
|
// Run the error through the API-level transformError transform (e.g. SvelteKit's handleError)
|
|
527
555
|
/** @type {unknown} */
|
|
528
556
|
var result;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @import { EachItem, EachOutroGroup, EachState, Effect, EffectNodes, MaybeSource,
|
|
1
|
+
/** @import { EachItem, EachOutroGroup, EachState, Effect, EffectNodes, MaybeSource, TemplateNode, TransitionManager } from '#client' */
|
|
2
2
|
/** @import { Batch } from '../../reactivity/batch.js'; */
|
|
3
3
|
import {
|
|
4
4
|
EACH_INDEX_REACTIVE,
|
|
@@ -216,9 +216,6 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
216
216
|
tag(each_array, '{#each ...}');
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
/** @type {V[]} */
|
|
220
|
-
var array;
|
|
221
|
-
|
|
222
219
|
/** @type {Map<Batch, Set<any>>} */
|
|
223
220
|
var pending = new Map();
|
|
224
221
|
|
|
@@ -234,6 +231,11 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
234
231
|
|
|
235
232
|
state.pending.delete(batch);
|
|
236
233
|
|
|
234
|
+
// The effect doesn't necessarily re-run in a batch right before that batch commits
|
|
235
|
+
// (its view of the collection may not have changed), so we read the collection
|
|
236
|
+
// as the committing batch sees it rather than using the most recent block run's result
|
|
237
|
+
var array = get(each_array);
|
|
238
|
+
|
|
237
239
|
state.fallback = fallback;
|
|
238
240
|
reconcile(state, array, anchor, flags, get_key);
|
|
239
241
|
|
|
@@ -264,7 +266,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
264
266
|
}
|
|
265
267
|
|
|
266
268
|
var effect = block(() => {
|
|
267
|
-
array = /** @type {V[]} */ (get(each_array));
|
|
269
|
+
var array = /** @type {V[]} */ (get(each_array));
|
|
268
270
|
var length = array.length;
|
|
269
271
|
|
|
270
272
|
/** `true` if there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
|
|
@@ -664,7 +666,7 @@ function reconcile(state, array, anchor, flags, get_key) {
|
|
|
664
666
|
* @param {V} value
|
|
665
667
|
* @param {unknown} key
|
|
666
668
|
* @param {number} index
|
|
667
|
-
* @param {(anchor: Node, item:
|
|
669
|
+
* @param {(anchor: Node, item: MaybeSource<V>, index: MaybeSource<number>, collection: () => V[]) => void} render_fn
|
|
668
670
|
* @param {number} flags
|
|
669
671
|
* @param {() => V[]} get_collection
|
|
670
672
|
* @returns {EachItem}
|
|
@@ -71,6 +71,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
|
|
|
71
71
|
|
|
72
72
|
branches.ensure(next_tag, (anchor) => {
|
|
73
73
|
if (next_tag) {
|
|
74
|
+
var is_hydrating = hydrating;
|
|
74
75
|
element = hydrating ? /** @type {Element} */ (element) : create_element(next_tag, ns);
|
|
75
76
|
|
|
76
77
|
if (DEV && location) {
|
|
@@ -123,7 +124,8 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
|
|
|
123
124
|
// we do this after calling `render_fn` so that child effects don't override `nodes.end`
|
|
124
125
|
/** @type {Effect & { nodes: EffectNodes }} */ (active_effect).nodes.end = element;
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
// we only move the node if we are not hydrating since a claimed element is already in place
|
|
128
|
+
if (!is_hydrating) anchor.before(element);
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
if (hydrating) {
|
|
@@ -12,7 +12,7 @@ export function append_styles(anchor, css) {
|
|
|
12
12
|
// Use an effect to ensure `anchor` is in the DOM, otherwise getRootNode() will yield wrong results
|
|
13
13
|
effect(() => {
|
|
14
14
|
// Bit of a hack: branches.js/each.js use offscreen fragments with temporary text nodes that will
|
|
15
|
-
// never be connected to the real dom.
|
|
15
|
+
// never be connected to the real dom. Therefore walk up to the branch that has created the component
|
|
16
16
|
// whose styles we want to append, and check its node instead. It will be connected by the time we get here.
|
|
17
17
|
anchor = active_effect?.parent?.nodes?.start ?? anchor;
|
|
18
18
|
var root = anchor.getRootNode();
|