-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: add a warning when the misuse of reset
in an error:boundary
causes an error to be thrown when flushing the boundary content
#16171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dummdidumm
merged 12 commits into
sveltejs:main
from
raythurnvoid:fix/@sveltejs/svelte/16134
Jul 17, 2025
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
997ccef
Add a warning when the misuse of `reset` in an `error:boundary` cause…
raythurnvoid 6255301
Prevent uncaught errors to make test fails when they are expected and…
raythurnvoid 0554c51
Add tests
raythurnvoid 28b0310
Add changeset
raythurnvoid 0ebb878
reset should just be a noop after the first call
Rich-Harris a49a088
changeset
Rich-Harris 3ad0519
correctly handle errors inside boundary during reset
Rich-Harris 942cda7
handle errors in the correct boundary
Rich-Harris f686128
update changeset
Rich-Harris c0ade24
merge main
Rich-Harris d78ab67
regenerate
Rich-Harris 8891015
simplify
Rich-Harris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/svelte/tests/runtime-runes/samples/error-boundary-reset-with-error/_config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
test({ assert, target, warnings }) { | ||
const [toggle] = target.querySelectorAll('button'); | ||
|
||
flushSync(() => toggle.click()); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
// TODO the synthetic stack shouldn't be part of the message here | ||
`<button>toggle</button><p>yikes! in {expression} in undefined</p><button>reset</button>` | ||
); | ||
|
||
const [, reset] = target.querySelectorAll('button'); | ||
flushSync(() => reset.click()); | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
`<button>toggle</button><p>yikes! in {expression} in undefined</p><button>reset</button>` | ||
); | ||
|
||
flushSync(() => toggle.click()); | ||
|
||
const [, reset2] = target.querySelectorAll('button'); | ||
flushSync(() => reset2.click()); | ||
assert.htmlEqual(target.innerHTML, `<button>toggle</button><p>hello!</p>`); | ||
} | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/svelte/tests/runtime-runes/samples/error-boundary-reset-with-error/main.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
let must_throw = $state(false); | ||
|
||
function throw_error() { | ||
throw new Error('yikes!'); | ||
} | ||
</script> | ||
|
||
<button onclick={() => must_throw = !must_throw}>toggle</button> | ||
|
||
<svelte:boundary> | ||
<p>{must_throw ? throw_error() : 'hello!'}</p> | ||
|
||
{#snippet failed(error, reset)} | ||
<p>{error.message}</p> | ||
<button onclick={reset}>reset</button> | ||
{/snippet} | ||
</svelte:boundary> | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rich-Harris People might want to auto-fix the state of the application inside the onerror for instance they might decide to show an error snackbar and reset a form without any confirmation from the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't work — the update is still in progress and everything gets torn. The
svelte_boundary_reset_onerror
message has an example of fixing it by waiting for atick()
before callingreset()