Skip to content

Commit c3869b7

Browse files
authored
Merge branch 'main' into defer-effects-in-pending-boundary
2 parents d50b4d9 + 7e40186 commit c3869b7

File tree

220 files changed

+3853
-1533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+3853
-1533
lines changed

.changeset/mighty-mice-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: keep batches alive until all async work is complete

.changeset/short-banks-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: don't preserve reactivity context across function boundaries

.changeset/silly-penguins-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: make `$inspect` logs come from the callsite

.changeset/witty-seas-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure guards (eg. if, each, key) run before their contents

.github/workflows/ecosystem-ci-trigger.yml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ on:
44
issue_comment:
55
types: [created]
66

7+
permissions: {}
8+
79
jobs:
810
trigger:
911
runs-on: ubuntu-latest
1012
if: github.repository == 'sveltejs/svelte' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
1113
permissions:
12-
issues: write # to add / delete reactions
14+
issues: write # to add / delete reactions, post comments
1315
pull-requests: write # to read PR data, and to add labels
1416
actions: read # to check workflow status
1517
contents: read # to clone the repo
1618
steps:
17-
- name: monitor action permissions
18-
- name: check user authorization # user needs triage permission
19-
uses: actions/github-script@v7
19+
- name: Check User Permissions
20+
uses: actions/github-script@v8
2021
id: check-permissions
2122
with:
2223
script: |
@@ -55,7 +56,7 @@ jobs:
5556
}
5657
5758
- name: Get PR Data
58-
uses: actions/github-script@v7
59+
uses: actions/github-script@v8
5960
id: get-pr-data
6061
with:
6162
script: |
@@ -65,6 +66,37 @@ jobs:
6566
repo: context.repo.repo,
6667
pull_number: context.issue.number
6768
})
69+
70+
const commentCreatedAt = new Date(context.payload.comment.created_at)
71+
const commitPushedAt = new Date(pr.head.repo.pushed_at)
72+
73+
console.log(`Comment created at: ${commentCreatedAt.toISOString()}`)
74+
console.log(`PR last pushed at: ${commitPushedAt.toISOString()}`)
75+
76+
// Check if any commits were pushed after the comment was created
77+
if (commitPushedAt > commentCreatedAt) {
78+
const errorMsg = [
79+
'⚠️ Security warning: PR was updated after the trigger command was posted.',
80+
'',
81+
`Comment posted at: ${commentCreatedAt.toISOString()}`,
82+
`PR last pushed at: ${commitPushedAt.toISOString()}`,
83+
'',
84+
'This could indicate an attempt to inject code after approval.',
85+
'Please review the latest changes and re-run /ecosystem-ci run if they are acceptable.'
86+
].join('\n')
87+
88+
core.setFailed(errorMsg)
89+
90+
await github.rest.issues.createComment({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
issue_number: context.issue.number,
94+
body: errorMsg
95+
})
96+
97+
throw new Error('PR was pushed to after comment was created')
98+
}
99+
68100
return {
69101
num: context.issue.number,
70102
branchName: pr.head.ref,
@@ -83,15 +115,16 @@ jobs:
83115
svelte-ecosystem-ci
84116
85117
- name: Trigger Downstream Workflow
86-
uses: actions/github-script@v7
118+
uses: actions/github-script@v8
87119
id: trigger
88120
env:
89121
COMMENT: ${{ github.event.comment.body }}
122+
PR_DATA: ${{ steps.get-pr-data.outputs.result }}
90123
with:
91124
github-token: ${{ steps.generate-token.outputs.token }}
92125
script: |
93126
const comment = process.env.COMMENT.trim()
94-
const prData = ${{ steps.get-pr-data.outputs.result }}
127+
const prData = JSON.parse(process.env.PR_DATA)
95128
96129
const suite = comment.split('\n')[0].replace(/^\/ecosystem-ci run/, '').trim()
97130

.github/workflows/pkg.pr.new.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Publish Any Commit
22
on: [push, pull_request]
33

4+
permissions: {}
5+
46
jobs:
57
build:
68
permissions: {}

documentation/docs/01-introduction/02-getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Don't worry if you don't know Svelte yet! You can ignore all the nice features S
1515

1616
## Alternatives to SvelteKit
1717

18-
You can also use Svelte directly with Vite by running `npm create vite@latest` and selecting the `svelte` option. With this, `npm run build` will generate HTML, JS, and CSS files inside the `dist` directory using [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). In most cases, you will probably need to [choose a routing library](faq#Is-there-a-router) as well.
18+
You can also use Svelte directly with Vite by running `npm create vite@latest` and selecting the `svelte` option. With this, `npm run build` will generate HTML, JS, and CSS files inside the `dist` directory using [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). In most cases, you will probably need to [choose a routing library](/packages#routing) as well.
1919

2020
>[!NOTE] Vite is often used in standalone mode to build [single page apps (SPAs)](../kit/glossary#SPA), which you can also [build with SvelteKit](../kit/single-page-apps).
2121
22-
There are also plugins for [Rollup](https://github.com/sveltejs/rollup-plugin-svelte), [Webpack](https://github.com/sveltejs/svelte-loader) [and a few others](https://sveltesociety.dev/packages?category=build-plugins), but we recommend Vite.
22+
There are also [plugins for other bundlers](/packages#bundler-plugins), but we recommend Vite.
2323

2424
## Editor tooling
2525

documentation/docs/02-runes/02-$state.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ To take a static snapshot of a deeply reactive `$state` proxy, use `$state.snaps
166166

167167
This is handy when you want to pass some state to an external library or API that doesn't expect a proxy, such as `structuredClone`.
168168

169+
## `$state.eager`
170+
171+
When state changes, it may not be reflected in the UI immediately if it is used by an `await` expression, because [updates are synchronized](await-expressions#Synchronized-updates).
172+
173+
In some cases, you may want to update the UI as soon as the state changes. For example, you might want to update a navigation bar when the user clicks on a link, so that they get visual feedback while waiting for the new page to load. To do this, use `$state.eager(value)`:
174+
175+
```svelte
176+
<nav>
177+
<a href="/" aria-current={$state.eager(pathname) === '/' ? 'page' : null}>home</a>
178+
<a href="/about" aria-current={$state.eager(pathname) === '/about' ? 'page' : null}>about</a>
179+
</nav>
180+
```
181+
182+
Use this feature sparingly, and only to provide feedback in response to user action — in general, allowing Svelte to coordinate updates will provide a better user experience.
183+
169184
## Passing state into functions
170185

171186
JavaScript is a _pass-by-value_ language — when you call a function, the arguments are the _values_ rather than the _variables_. In other words:

documentation/docs/02-runes/03-$derived.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ Derived expressions are recalculated when their dependencies change, but you can
8585

8686
Unlike `$state`, which converts objects and arrays to [deeply reactive proxies]($state#Deep-state), `$derived` values are left as-is. For example, [in a case like this](/playground/untitled#H4sIAAAAAAAAE4VU22rjMBD9lUHd3aaQi9PdstS1A3t5XvpQ2Ic4D7I1iUUV2UjjNMX431eS7TRdSosxgjMzZ45mjt0yzffIYibvy0ojFJWqDKCQVBk2ZVup0LJ43TJ6rn2aBxw-FP2o67k9oCKP5dziW3hRaUJNjoYltjCyplWmM1JIIAn3FlL4ZIkTTtYez6jtj4w8WwyXv9GiIXiQxLVs9pfTMR7EuoSLIuLFbX7Z4930bZo_nBrD1bs834tlfvsBz9_SyX6PZXu9XaL4gOWn4sXjeyzftv4ZWfyxubpzxzg6LfD4MrooxELEosKCUPigQCMPKCZh0OtQE1iSxcsmdHuBvCiHZXALLXiN08EL3RRkaJ_kDVGle0HcSD5TPEeVtj67O4Nrg9aiSNtBY5oODJkrL5QsHtN2cgXp6nSJMWzpWWGasdlsGEMbzi5jPr5KFr0Ep7pdeM2-TCelCddIhDxAobi1jqF3cMaC1RKp64bAW9iFAmXGIHfd4wNXDabtOLN53w8W53VvJoZLh7xk4Rr3CoL-UNoLhWHrT1JQGcM17u96oES5K-kc2XOzkzqGCKL5De79OUTyyrg1zgwXsrEx3ESfx4Bz0M5UjVMHB24mw9SuXtXFoN13fYKOM1tyUT3FbvbWmSWCZX2Er-41u5xPoml45svRahl9Wb9aasbINJixDZwcPTbyTLZSUsAvrg_cPuCR7s782_WU8343Y72Qtlb8OYatwuOQvuN13M_hJKNfxann1v1U_B1KZ_D_mzhzhz24fw85CSz2irtN9w9HshBK7AQAAA==)...
8787

88-
```svelte
89-
let items = $state([...]);
88+
```js
89+
// @errors: 7005
90+
let items = $state([ /*...*/ ]);
9091

9192
let index = $state(0);
9293
let selected = $derived(items[index]);

documentation/docs/02-runes/07-$inspect.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The `$inspect` rune is roughly equivalent to `console.log`, with the exception t
1818
<input bind:value={message} />
1919
```
2020

21+
On updates, a stack trace will be printed, making it easy to find the origin of a state change (unless you're in the playground, due to technical limitations).
22+
2123
## $inspect(...).with
2224

2325
`$inspect` returns a property `with`, which you can invoke with a callback, which will then be invoked instead of `console.log`. The first argument to the callback is either `"init"` or `"update"`; subsequent arguments are the values passed to `$inspect` ([demo](/playground/untitled#H4sIAAAAAAAACkVQ24qDMBD9lSEUqlTqPlsj7ON-w7pQG8c2VCchmVSK-O-bKMs-DefKYRYx6BG9qL4XQd2EohKf1opC8Nsm4F84MkbsTXAqMbVXTltuWmp5RAZlAjFIOHjuGLOP_BKVqB00eYuKs82Qn2fNjyxLtcWeyUE2sCRry3qATQIpJRyD7WPVMf9TW-7xFu53dBcoSzAOrsqQNyOe2XUKr0Xi5kcMvdDB2wSYO-I9vKazplV1-T-d6ltgNgSG1KjVUy7ZtmdbdjqtzRcphxMS1-XubOITJtPrQWMvKnYB15_1F7KKadA_AQAA)):
@@ -36,13 +38,6 @@ The `$inspect` rune is roughly equivalent to `console.log`, with the exception t
3638
<button onclick={() => count++}>Increment</button>
3739
```
3840

39-
A convenient way to find the origin of some change is to pass `console.trace` to `with`:
40-
41-
```js
42-
// @errors: 2304
43-
$inspect(stuff).with(console.trace);
44-
```
45-
4641
## $inspect.trace(...)
4742

4843
This rune, added in 5.14, causes the surrounding function to be _traced_ in development. Any time the function re-runs as part of an [effect]($effect) or a [derived]($derived), information will be printed to the console about which pieces of reactive state caused the effect to fire.

0 commit comments

Comments
 (0)