Merge branch 'main' into customizable-select-for-real

pull/17429/head
Paolo Ricciuti 7 months ago committed by GitHub
commit d1c2992acf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: don't transform references of function declarations in legacy mode

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: notify deriveds of changes to sources inside forks

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: prevent derives without dependencies from ever re-running

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: correctly update writable deriveds inside forks

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: remove `$inspect` calls after await expressions when compiling for production server code

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: clear batch between runs

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: adjust `loc` property of `Program` nodes created from `<script>` elements

@ -1,5 +0,0 @@
---
'svelte': patch
---
fix: don't revert source to UNINITIALIZED state when time travelling

@ -1,5 +1,35 @@
# svelte
## 5.46.3
### Patch Changes
- fix: reconnect clean deriveds when they are read in a reactive context ([#17362](https://github.com/sveltejs/svelte/pull/17362))
- fix: don't transform references of function declarations in legacy mode ([#17431](https://github.com/sveltejs/svelte/pull/17431))
- fix: notify deriveds of changes to sources inside forks ([#17437](https://github.com/sveltejs/svelte/pull/17437))
- fix: always reconnect deriveds in get, when appropriate ([#17451](https://github.com/sveltejs/svelte/pull/17451))
- fix: prevent derives without dependencies from ever re-running ([`286b40c4526ce9970cb81ddd5e65b93b722fe468`](https://github.com/sveltejs/svelte/commit/286b40c4526ce9970cb81ddd5e65b93b722fe468))
- fix: correctly update writable deriveds inside forks ([#17437](https://github.com/sveltejs/svelte/pull/17437))
- fix: remove `$inspect` calls after await expressions when compiling for production server code ([#17407](https://github.com/sveltejs/svelte/pull/17407))
- fix: clear batch between runs ([#17424](https://github.com/sveltejs/svelte/pull/17424))
- fix: adjust `loc` property of `Program` nodes created from `<script>` elements ([#17428](https://github.com/sveltejs/svelte/pull/17428))
- fix: don't revert source to UNINITIALIZED state when time travelling ([#17409](https://github.com/sveltejs/svelte/pull/17409))
## 5.46.2
### Notice
Not published due to CI issue
## 5.46.1
### Patch Changes

@ -2,7 +2,7 @@
"name": "svelte",
"description": "Cybernetically enhanced web apps",
"license": "MIT",
"version": "5.46.1",
"version": "5.46.3",
"type": "module",
"types": "./types/index.d.ts",
"engines": {

@ -596,14 +596,14 @@ export function get(signal) {
}
}
if (is_destroying_effect) {
if (old_values.has(signal)) {
return old_values.get(signal);
}
if (is_destroying_effect && old_values.has(signal)) {
return old_values.get(signal);
}
if (is_derived) {
var derived = /** @type {Derived} */ (signal);
if (is_derived) {
var derived = /** @type {Derived} */ (signal);
if (is_destroying_effect) {
var value = derived.v;
// if the derived is dirty and has reactions, or depends on the values that just changed, re-execute
@ -619,17 +619,28 @@ export function get(signal) {
return value;
}
} else if (
is_derived &&
(!batch_values?.has(signal) || (current_batch?.is_fork && !effect_tracking()))
) {
derived = /** @type {Derived} */ (signal);
// connect disconnected deriveds if we are reading them inside an effect,
// or inside another derived that is already connected
var should_connect =
(derived.f & CONNECTED) === 0 &&
!untracking &&
active_reaction !== null &&
(is_updating_effect || (active_reaction.f & CONNECTED) !== 0);
var is_new = derived.deps === null;
if (is_dirty(derived)) {
if (should_connect) {
// set the flag before `update_derived`, so that the derived
// is added as a reaction to its dependencies
derived.f |= CONNECTED;
}
update_derived(derived);
}
if (is_updating_effect && effect_tracking() && (derived.f & CONNECTED) === 0) {
if (should_connect && !is_new) {
reconnect(derived);
}
}
@ -653,7 +664,7 @@ export function get(signal) {
function reconnect(derived) {
if (derived.deps === null) return;
derived.f ^= CONNECTED;
derived.f |= CONNECTED;
for (const dep of derived.deps) {
(dep.reactions ??= []).push(derived);

@ -4,5 +4,5 @@
* The current version, as set in package.json.
* @type {string}
*/
export const VERSION = '5.46.1';
export const VERSION = '5.46.3';
export const PUBLIC_VERSION = '5';

@ -0,0 +1,24 @@
import { tick } from 'svelte';
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
async test({ assert, target }) {
const [fork] = target.querySelectorAll('button');
fork.click();
await tick();
assert.htmlEqual(target.innerHTML, '<button>fork</button><button>false</button>');
const [, toggle] = target.querySelectorAll('button');
toggle.click();
await tick();
assert.htmlEqual(target.innerHTML, '<button>fork</button><button>true</button>');
}
});

@ -0,0 +1,26 @@
<script>
import { fork } from 'svelte';
let condition = $state(false);
let checked = $state(false);
const d = $derived({ checked });
</script>
<button onclick={() => {
fork(() => {
condition = true;
}).commit();
}}>fork</button>
{#if condition}
<!-- in dev, snippet arguments are read eagerly, outside a tracking context -->
<!-- this test checks that doing so doesn't prevent the derived from connecting -->
{#snippet foo({ checked })}
{checked}
{/snippet}
<button onclick={() => (checked = !checked)}>
{@render foo(d)}
</button>
{/if}

@ -0,0 +1,47 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: `
<button>+1</button>
<button>add number</button>
<p>1, 2, 3</p>
`,
test({ assert, target }) {
const [button1, button2] = target.querySelectorAll('button');
button1.click();
flushSync();
assert.htmlEqual(
target.innerHTML,
`
<button>+1</button>
<button>add number</button>
<p>2, 4, 6</p>
`
);
button2.click();
flushSync();
assert.htmlEqual(
target.innerHTML,
`
<button>+1</button>
<button>add number</button>
<p>2, 4, 6, 8</p>
`
);
button1.click();
flushSync();
assert.htmlEqual(
target.innerHTML,
`
<button>+1</button>
<button>add number</button>
<p>3, 6, 9, 12</p>
`
);
}
});

@ -0,0 +1,30 @@
<script lang="ts">
class Item {
product: number;
constructor(n: number) {
this.product = $derived(multiplier * n);
}
}
let numbers = $state([1, 2, 3]);
let multiplier = $state(1);
let items = $derived(numbers.map((n) => new Item(n)))
let products = $derived(items.map(item => item.product));
</script>
<button onclick={() => {
multiplier += 1;
}}>+1</button>
<button onclick={() => {
numbers.push(numbers.length + 1);
// this is load-bearing — by reading it outside a reaction, we recompute
// `products`, removing it as a reaction from `Item.product` dependencies,
// but we don't add it as a reaction to the new `Item.product` dependencies
products;
}}>add number</button>
<p>{products.join(', ')}</p>
Loading…
Cancel
Save