Skip to content

Commit 2e9d8ec

Browse files
committed
feedback
1 parent f511b1b commit 2e9d8ec

File tree

7 files changed

+48
-8
lines changed

7 files changed

+48
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export const STATE_SYMBOL_METADATA = Symbol('$state metadata');
2626
export const LEGACY_PROPS = Symbol('legacy props');
2727
export const LOADING_ATTR_SYMBOL = Symbol('');
2828

29-
export const CTX_CONTAINS_TEARDOWN = 1;
30-
export const CTX_DESTROYED = 2;
29+
export const CTX_CONTAINS_TEARDOWN = 1 << 1;
30+
export const CTX_DESTROYED = 1 << 2;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ export function push(props, runes = false, fn) {
136136
}
137137

138138
teardown(() => {
139-
if (ctx.f !== CTX_CONTAINS_TEARDOWN) {
139+
if ((ctx.f & (CTX_CONTAINS_TEARDOWN | CTX_DESTROYED)) === 0) {
140140
return;
141141
}
142142
// Mark the context as destroyed, so any derived props can use
143143
// the latest known value before teardown
144-
ctx.f = CTX_DESTROYED;
144+
ctx.f ^= CTX_DESTROYED;
145145

146146
var teardown_props = ctx.tp;
147147
// Apply the latest known props before teardown over existing props
@@ -195,7 +195,7 @@ export function pop(component) {
195195
context_stack_item.m = true;
196196

197197
effect(() => {
198-
if (context_stack_item.f === CTX_CONTAINS_TEARDOWN) {
198+
if ((context_stack_item.f & CTX_CONTAINS_TEARDOWN) !== 0) {
199199
context_stack_item.tp = { ...context_stack_item.s };
200200
}
201201
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export function prop(props, key, flags, fallback) {
370370
var current_value = derived(() => {
371371
var ctx = component_context;
372372

373-
if (ctx !== null && ctx.f === CTX_DESTROYED) {
373+
if (ctx !== null && (ctx.f & CTX_DESTROYED) !== 0) {
374374
return get(inner_current_value);
375375
}
376376

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ export function update_effect(effect) {
570570

571571
if (typeof teardown === 'function') {
572572
var ctx = effect.ctx;
573-
if (ctx !== null && ctx.f === 0) {
574-
ctx.f = CTX_CONTAINS_TEARDOWN;
573+
if (ctx !== null && (ctx.f & CTX_CONTAINS_TEARDOWN) === 0) {
574+
ctx.f ^= CTX_CONTAINS_TEARDOWN;
575575
}
576576
effect.teardown = teardown;
577577
} else {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import { onDestroy } from 'svelte';
3+
4+
let { my_prop } = $props();
5+
6+
onDestroy(() => {
7+
console.log(my_prop.foo);
8+
});
9+
</script>
10+
11+
{my_prop.foo}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test } from '../../test';
2+
import { flushSync } from 'svelte';
3+
4+
export default test({
5+
async test({ assert, target, logs }) {
6+
const [btn1] = target.querySelectorAll('button');
7+
8+
flushSync(() => {
9+
btn1.click();
10+
});
11+
12+
assert.deepEqual(logs, ['bar']);
13+
}
14+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
import Component from './Component.svelte';
3+
4+
let value = $state({ foo: 'bar' });
5+
</script>
6+
7+
<button
8+
onclick={() => {
9+
value = undefined;
10+
}}>Reset value</button
11+
>
12+
13+
{#if value !== undefined}
14+
<Component my_prop={value} />
15+
{/if}

0 commit comments

Comments
 (0)