Skip to content

Commit 7a3002c

Browse files
committed
update
1 parent 7cfff11 commit 7a3002c

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

.changeset/gorgeous-jokes-sit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'svelte': patch
33
---
44

5-
breaking: array proxy toPrimitive is no longer reactive
5+
breaking: array proxy coercion is no longer reactive in template

packages/svelte/src/internal/client/constants.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ export const EFFECT = 1 << 2;
33
export const RENDER_EFFECT = 1 << 3;
44
export const BLOCK_EFFECT = 1 << 4;
55
export const BRANCH_EFFECT = 1 << 5;
6-
export const ROOT_EFFECT = 1 << 6;
7-
export const UNOWNED = 1 << 7;
8-
export const DISCONNECTED = 1 << 8;
9-
export const CLEAN = 1 << 9;
10-
export const DIRTY = 1 << 10;
11-
export const MAYBE_DIRTY = 1 << 11;
12-
export const INERT = 1 << 12;
13-
export const DESTROYED = 1 << 13;
14-
export const EFFECT_RAN = 1 << 14;
6+
export const TEMPLATE_EFFECT = 1 << 6;
7+
export const ROOT_EFFECT = 1 << 7;
8+
export const UNOWNED = 1 << 8;
9+
export const DISCONNECTED = 1 << 9;
10+
export const CLEAN = 1 << 10;
11+
export const DIRTY = 1 << 11;
12+
export const MAYBE_DIRTY = 1 << 12;
13+
export const INERT = 1 << 13;
14+
export const DESTROYED = 1 << 14;
15+
export const EFFECT_RAN = 1 << 15;
1516
/** 'Transparent' effects do not create a transition boundary */
16-
export const EFFECT_TRANSPARENT = 1 << 15;
17+
export const EFFECT_TRANSPARENT = 1 << 16;
1718
/** Svelte 4 legacy mode props need to be handled with deriveds and be recognized elsewhere, hence the dedicated flag */
18-
export const LEGACY_DERIVED_PROP = 1 << 16;
19-
export const INSPECT_EFFECT = 1 << 17;
20-
export const HEAD_EFFECT = 1 << 18;
21-
export const EFFECT_HAS_DERIVED = 1 << 19;
19+
export const LEGACY_DERIVED_PROP = 1 << 17;
20+
export const INSPECT_EFFECT = 1 << 18;
21+
export const HEAD_EFFECT = 1 << 19;
22+
export const EFFECT_HAS_DERIVED = 1 << 20;
2223

2324
export const STATE_SYMBOL = Symbol('$state');
2425
export const STATE_SYMBOL_METADATA = Symbol('$state metadata');

packages/svelte/src/internal/client/proxy.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../shared/utils.js';
1111
import { check_ownership, widen_ownership } from './dev/ownership.js';
1212
import { source, set } from './reactivity/sources.js';
13-
import { STATE_SYMBOL, STATE_SYMBOL_METADATA } from './constants.js';
13+
import { STATE_SYMBOL, STATE_SYMBOL_METADATA, TEMPLATE_EFFECT } from './constants.js';
1414
import { UNINITIALIZED } from '../../constants.js';
1515
import * as e from './errors.js';
1616

@@ -115,9 +115,14 @@ export function proxy(value, parent = null, prev) {
115115
if (DEV && prop === STATE_SYMBOL_METADATA) {
116116
return metadata;
117117
}
118-
// We untrack Symbol.toPrimitive cases. If people want explicit reactivity, they should
119-
// use toString() or some other coercion method instead
120-
if (is_proxied_array && prop === Symbol.toPrimitive) {
118+
// We untrack Symbol.toPrimitive when used within a template effect. If people want explicit reactivity,
119+
// they should use toString() or some other coercion method instead
120+
if (
121+
is_proxied_array &&
122+
prop === Symbol.toPrimitive &&
123+
active_effect !== null &&
124+
(active_effect.f & TEMPLATE_EFFECT) !== 0
125+
) {
121126
return (/** @type {'string' | 'number' | 'default'} */ hint) =>
122127
untrack(() => (hint === 'number' ? Number(target) : String(target)));
123128
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import {
3535
INSPECT_EFFECT,
3636
HEAD_EFFECT,
3737
MAYBE_DIRTY,
38-
EFFECT_HAS_DERIVED
38+
EFFECT_HAS_DERIVED,
39+
TEMPLATE_EFFECT
3940
} from '../constants.js';
4041
import { set } from './sources.js';
4142
import * as e from '../errors.js';
@@ -324,7 +325,7 @@ export function template_effect(fn) {
324325
value: '{expression}'
325326
});
326327
}
327-
return render_effect(fn);
328+
return create_effect(RENDER_EFFECT | TEMPLATE_EFFECT, fn, true);
328329
}
329330

330331
/**

0 commit comments

Comments
 (0)