Skip to content

Commit 7c31b96

Browse files
committed
fix
1 parent 40a8b66 commit 7c31b96

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,13 @@ export function prop(props, key, flags, fallback) {
242242

243243
var get_fallback = () => {
244244
fallback_used = true;
245-
if (lazy && fallback_dirty) {
245+
if (fallback_dirty) {
246246
fallback_dirty = false;
247-
fallback_value = untrack(/** @type {() => V} */ (fallback));
247+
if (lazy) {
248+
fallback_value = untrack(/** @type {() => V} */ (fallback));
249+
} else {
250+
fallback_value = /** @type {V} */ (fallback);
251+
}
248252
}
249253

250254
return fallback_value;
@@ -266,6 +270,7 @@ export function prop(props, key, flags, fallback) {
266270
var value = /** @type {V} */ (props[key]);
267271
if (value === undefined) return get_fallback();
268272
fallback_dirty = true;
273+
fallback_used = false;
269274
return value;
270275
};
271276
} else {
@@ -355,7 +360,7 @@ export function prop(props, key, flags, fallback) {
355360
set(inner_current_value, new_value);
356361
// To ensure the fallback value is consistent when used with proxies, we
357362
// update the local fallback_value, but only if the fallback is actively used
358-
if (fallback_dirty && fallback_used && fallback_value !== undefined) {
363+
if (fallback_used && fallback_value !== undefined) {
359364
fallback_value = new_value;
360365
}
361366
get(current_value); // force a synchronisation immediately

packages/svelte/tests/runtime-runes/samples/props-default-value-rest/_config.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ export default test({
55
accessors: false,
66

77
test({ assert, target }) {
8-
const [btn] = target.querySelectorAll('button');
8+
const [btn1, btn2] = target.querySelectorAll('button');
99

10-
btn.click();
10+
btn1.click();
1111
flushSync();
12+
assert.htmlEqual(
13+
target.innerHTML,
14+
`<button>set color</button> <button>set options</button> bar bar`
15+
);
1216

13-
assert.htmlEqual(target.innerHTML, `<button>change</button>\nbar\nbar`);
17+
btn2.click();
18+
flushSync();
19+
assert.htmlEqual(
20+
target.innerHTML,
21+
`<button>set color</button> <button>set options</button> baz bar`
22+
);
23+
24+
btn1.click();
25+
flushSync();
26+
assert.htmlEqual(
27+
target.innerHTML,
28+
`<button>set color</button> <button>set options</button> foo bar`
29+
);
1430
}
1531
});

packages/svelte/tests/runtime-runes/samples/props-default-value-rest/main.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
testProps = {
1111
color: "blue"
1212
};
13-
}}>change</button>
13+
}}>set color</button>
14+
15+
<button onclick={() => {
16+
testProps = {
17+
color: "pink",
18+
options: 'baz'
19+
};
20+
}}>set options</button>
1421

1522
<Inner {...testProps} />
1623

0 commit comments

Comments
 (0)