Skip to content

Conversation

@RazinShafayet2007
Copy link
Contributor

Description

In Svelte 5, reading state after an await causes silent reactivity loss. The function resumes execution without tracking context, so the UI simply fails to update without any feedback.

This PR re-enables the await_reactivity_loss warning in runtime.js. It now correctly detects when execution resumes after an await and warns the user if they try to read a signal, preventing hard-to-debug "silent failures."

Verification

  1. Set up a test app (with experimental: { async: true }).
  2. Created an async function that reads a $state variable after an await.
  3. Before: The update failed silently.
  4. After: The console now warns:
    [svelte] await_reactivity_loss: Detected reactivity loss when reading...

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: bdde972

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17364

@RazinShafayet2007 RazinShafayet2007 force-pushed the fix/async-reactivity-warning branch 2 times, most recently from 11d2693 to d75681f Compare December 15, 2025 18:19
@RazinShafayet2007 RazinShafayet2007 force-pushed the fix/async-reactivity-warning branch from d75681f to 4a93f38 Compare December 15, 2025 18:25
@svelte-docs-bot
Copy link

Comment on lines +550 to +561
if (current_async_effect) {
var tracking = (current_async_effect.f & REACTION_IS_UPDATING) !== 0;
var was_read = current_async_effect.deps?.includes(signal);

if (!tracking && !untracking && !was_read) {
w.await_reactivity_loss(/** @type {string} */ (signal.label));

var stack_trace = get_error('traced at');
// eslint-disable-next-line no-console
if (stack_trace) console.warn(stack_trace);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed one part of the TODO. It was not working properly before, so just uncommenting it will not make it work correctly no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up! I dug into the runtime code, and since .includes is syntactically valid here, I suspect the original issue was about reference equality (e.g. comparing a signal wrapper against a raw node causing false negatives). If that's the case, I can switch to .some() to check properly. Does that sound like the right fix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much insight on why this was commented but I suspect if the problem was just a reference equality it would've been fixed instead of commented. What I would do is git blame it, go check the pr that introduce it and try to understand why it was commented (possibly even asking whoever introduced it if it's not clear from the pr) and move on from there. Thanks for the effort 🤟🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes total sense. I'll check the git blame history to track down the original PR and understand the context for why it was disabled. Thanks for the tip! I'll report back with what I find. 🤜🤛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants