fix: resolve stale deriveds with latest value#18167
Conversation
🦋 Changeset detectedLatest commit: 3697573 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
dummdidumm
left a comment
There was a problem hiding this comment.
Nice discovery! This works in this case but it might show temporarily inconsistent values in case batch A is superseeded by batch B in one derived but not another. Then when batch A resolves, but batch B hasn't yet, batch A shows a value of B already. What I tried in PR 17971 is to have logic that tracks which pending work of a batch is already superseeded, and if everything is it's discarded. Otherwise the later batches that superseed it have to wait until the batch's own pending work resolves. But as you can see in that PR it adds quite a bit complexity for marginal gain, and if we say "eventual consistency is enough" this is definitely good to go 👍
|
Hey Is this bug eligible for bounty if submitted via hackerone by @Rich-Harris |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## svelte@5.55.6 ### Patch Changes - fix: leave stale promises to wait for a later resolution, instead of rejecting ([#18180](#18180)) - fix: keep dependencies of `$state.eager/pending` ([#18218](#18218)) - fix: reapply context after transforming error during SSR ([#18099](#18099)) - fix: don't rebase just-created batches ([#18117](#18117)) - chore: allow `null` for `pending` in typings ([#18201](#18201)) - fix: flush eager effects in production ([#18107](#18107)) - fix: rethrow error of failed iterable after calling `return()` ([#18169](#18169)) - fix: account for proxified instance when updating `bind:this` ([#18147](#18147)) - fix: ensure scheduled batch is flushed if not obsolete ([#18131](#18131)) - fix: resolve stale deriveds with latest value ([#18167](#18167)) - chore: remove unnecessary `increment_pending` calls ([#18183](#18183)) - fix: correctly compile component member expressions for SSR ([#18192](#18192)) - fix: reset `source.updated` stack traces after `flush` ([#18196](#18196)) - fix: replacing async 'blocking' strategy with 'merging' ([#18205](#18205)) - fix: allow `@debug` tags to reference awaited variables ([#18138](#18138)) - fix: re-run fallback props if dependencies update ([#18146](#18146)) - fix: abort running obsolete async branches ([#18118](#18118)) - fix: ignore comments when reading CSS values ([#18153](#18153)) - fix: wrap `Promise.all` in `save` during SSR ([#18178](#18178)) - fix: ignore false-positive errors of `$inspect` dependencies ([#18106](#18106)) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
While looking into #18162 I found an adjacent bug. Currently, if an async derived resolves in batch 2 before it resolves in batch 1, we reject the promise belonging to batch 1 and by extension the batch itself. This means that any other changes in batch 1 are silently discarded, incorrectly.
The fix is almost comically simple: rather than rejecting the earlier promise, we just resolve it with the latest value.
I have a hunch that this might also enable us to simplify the rebase logic, though I haven't investigated that in this PR.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint