Skip to content

Commit c2c2edd

Browse files
committed
fix: other blocks
1 parent 8bd65ca commit c2c2edd

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function AwaitBlock(node, context) {
2222
if (node.then) {
2323
const then_context = {
2424
...context,
25-
state: { ...context.state, transform: { ...context.state.transform } }
25+
state: { ...context.state, transform: { ...context.state.transform }, needs_safe_props: true }
2626
};
2727
const argument = node.value && create_derived_block_argument(node.value, then_context);
2828

@@ -37,7 +37,7 @@ export function AwaitBlock(node, context) {
3737
}
3838

3939
if (node.catch) {
40-
const catch_context = { ...context, state: { ...context.state } };
40+
const catch_context = { ...context, state: { ...context.state, needs_safe_props: true } };
4141
const argument = node.error && create_derived_block_argument(node.error, catch_context);
4242

4343
/** @type {Pattern[]} */
@@ -59,7 +59,12 @@ export function AwaitBlock(node, context) {
5959
context.state.node,
6060
expression,
6161
node.pending
62-
? b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.pending)))
62+
? b.arrow(
63+
[b.id('$$anchor')],
64+
/** @type {BlockStatement} */ (
65+
context.visit(node.pending, { ...context.state, needs_safe_props: true })
66+
)
67+
)
6368
: b.literal(null),
6469
then_block,
6570
catch_block

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ export function EachBlock(node, context) {
144144
const child_state = {
145145
...context.state,
146146
transform: { ...context.state.transform },
147-
store_to_invalidate
147+
store_to_invalidate,
148+
needs_safe_props: true
148149
};
149150

150151
/** The state used when generating the key function, if necessary */
@@ -308,7 +309,15 @@ export function EachBlock(node, context) {
308309

309310
if (node.fallback) {
310311
args.push(
311-
b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.fallback)))
312+
b.arrow(
313+
[b.id('$$anchor')],
314+
/** @type {BlockStatement} */ (
315+
context.visit(node.fallback, {
316+
...context.state,
317+
needs_safe_props: true
318+
})
319+
)
320+
)
312321
);
313322
}
314323

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export function KeyBlock(node, context) {
1111
context.state.template.push('<!>');
1212

1313
const key = /** @type {Expression} */ (context.visit(node.expression));
14-
const body = /** @type {Expression} */ (context.visit(node.fragment));
14+
const body = /** @type {Expression} */ (
15+
context.visit(node.fragment, { ...context.state, needs_safe_props: true })
16+
);
1517

1618
context.state.init.push(
1719
b.stmt(b.call('$.key', context.state.node, b.thunk(key), b.arrow([b.id('$$anchor')], body)))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function SnippetBlock(node, context) {
2222
const declarations = [];
2323

2424
const transform = { ...context.state.transform };
25-
const child_state = { ...context.state, transform };
25+
const child_state = { ...context.state, transform, needs_safe_props: true };
2626

2727
for (let i = 0; i < node.parameters.length; i++) {
2828
const argument = node.parameters[i];

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

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,17 @@ import {
77
PROPS_IS_RUNES,
88
PROPS_IS_UPDATED
99
} from '../../../constants.js';
10+
import { legacy_mode_flag } from '../../flags/index.js';
1011
import { get_descriptor, is_function } from '../../shared/utils.js';
11-
import { mutable_source, set, source, update } from './sources.js';
12-
import { derived, derived_safe_equal } from './deriveds.js';
13-
import {
14-
active_effect,
15-
get,
16-
captured_signals,
17-
set_active_effect,
18-
untrack,
19-
active_reaction,
20-
set_active_reaction
21-
} from '../runtime.js';
22-
import { safe_equals } from './equality.js';
12+
import { LEGACY_DERIVED_PROP, LEGACY_PROPS, STATE_SYMBOL } from '../constants.js';
2313
import * as e from '../errors.js';
24-
import {
25-
BRANCH_EFFECT,
26-
LEGACY_DERIVED_PROP,
27-
LEGACY_PROPS,
28-
ROOT_EFFECT,
29-
STATE_SYMBOL
30-
} from '../constants.js';
3114
import { proxy } from '../proxy.js';
32-
import { capture_store_binding } from './store.js';
33-
import { legacy_mode_flag } from '../../flags/index.js';
15+
import { captured_signals, get, is_flushing_effect, untrack } from '../runtime.js';
16+
import { derived, derived_safe_equal } from './deriveds.js';
3417
import { teardown } from './effects.js';
18+
import { safe_equals } from './equality.js';
19+
import { inspect_effects, mutable_source, set, source, update } from './sources.js';
20+
import { capture_store_binding } from './store.js';
3521

3622
/**
3723
* @param {((value?: number) => number)} fn
@@ -428,28 +414,31 @@ export function safe_props(props) {
428414
unmounting = true;
429415
});
430416
const deriveds = new Map();
431-
/**
432-
* @type {Map<string|symbol, unknown>}
433-
*/
434-
const olds = new Map(untrack(() => Object.entries(props)));
435-
return new Proxy(
436-
{},
437-
{
438-
get(_, key) {
439-
if (!deriveds.has(key)) {
440-
deriveds.set(
441-
key,
442-
derived(() => {
443-
if (unmounting) {
444-
return olds.get(key);
445-
}
446-
olds.set(key, props[key]);
447-
return props[key];
448-
})
449-
);
417+
return untrack(() => {
418+
/**
419+
* @type {Map<string|symbol, unknown>}
420+
*/
421+
const olds = new Map(Object.entries(props));
422+
423+
return new Proxy(
424+
{},
425+
{
426+
get(_, key) {
427+
if (!deriveds.has(key)) {
428+
deriveds.set(
429+
key,
430+
derived(() => {
431+
if (unmounting) {
432+
return olds.get(key);
433+
}
434+
olds.set(key, props[key]);
435+
return props[key];
436+
})
437+
);
438+
}
439+
return get(deriveds.get(key));
450440
}
451-
return get(deriveds.get(key));
452441
}
453-
}
454-
);
442+
);
443+
});
455444
}

0 commit comments

Comments
 (0)