Skip to content

Conversation

@paoloricciuti
Copy link
Member

@paoloricciuti paoloricciuti commented Nov 16, 2025

Just a failing test because I tried to fix this without much success. This also causes SvelteKit to fail when preloading happens (I though #17147 would've fixed it, but the problem is with blocks that use deriveds).

The issue is that we update derived.v and increase the version even if the state change happens in a fork. However, this means that if in a later state update (be it in another fork or just normal state update) to determine if the block effect is dirty we try to update the derived and then check the wv of it. But since we already updated the value AND the version in the fork the block effect is not executed.

IMHO we should reserve the same treatment we reserve to sources for deriveds and update the value in the batch and not in the derived itself but when I tried to do that a bunch of tests failed.

EDIT: oh my god I think I actually figured it out! I just pushed a commit to fix the issue, I'm just not sure if it's the right solution.

Basically, if batch_values is defined we don't set derived.v, we just increase the version. Now what this means is that if we are changing the derived AND we are not in a tracking context we kinda wasted one computation because the next time around the derived will be re-computed (during the get) but if this time we are in a tracking context batch_values will be updated and the get will read that (the rest of the logic applies as usual with batch_values so when we commit the value is the updated one).

That said, there might be an issue when accessing a derived in a non tracking context when batch_values is defined, but I wasn't able to think of a situation for that. Can you?

Fixes sveltejs/kit#14827
Fixes #17190

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 Nov 16, 2025

⚠️ No Changeset found

Latest commit: e0165e2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions
Copy link
Contributor

Playground

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

@zqianem
Copy link
Contributor

zqianem commented Nov 17, 2025

This looks like it may have the same cause as #17111.

@paoloricciuti paoloricciuti changed the title chore: failing test for derived + fork + block fix: don't set derived values during time traveling Nov 17, 2025
Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

nice!

@Rich-Harris Rich-Harris merged commit 056b201 into main Nov 19, 2025
18 checks passed
@Rich-Harris Rich-Harris deleted the failing-test-derived-fork branch November 19, 2025 23:13
@Rich-Harris
Copy link
Member

ah crap, forgot a changeset and have to run out now. will fix later if no-one else does

paoloricciuti added a commit that referenced this pull request Nov 20, 2025
@paoloricciuti
Copy link
Member Author

Here we go #17200

Ocean-OS pushed a commit that referenced this pull request Nov 20, 2025
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.

[5.43.10] Two hover preloading issues Preloading query with page param on hover breaks the app

5 participants