Skip to content

Conversation

@Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Oct 22, 2025

Definitely WIP. Opening this so that we can discuss the API and start coming up with more test cases. I've no doubt that this is missing all sorts of details, though at the same time I'm very pleasantly surprised at how little code it took to get this far. It gives me faith in the primitives we've built.

The idea is that you need to be able to change some state 'offscreen' in such a way that you can discover any async work resulting from the state change without committing it to the screen. This allows you to, for example, load the data that will be needed on the next page before the user navigates there. Future SvelteKit will use this to preload remote function calls, much as it preloads load functions today.

You can see an example here — if you click on the <a> elements fast enough, there will be a delay before navigation occurs, since it's doing async work (though the nav bar updates immediately, courtesy of $state.eager(...). But if you hover for a beat before clicking — which users generally do — the fork will be ready by the time navigation occurs.

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 Oct 22, 2025

🦋 Changeset detected

Latest commit: 3a27726

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@17004

@Rich-Harris Rich-Harris marked this pull request as ready for review October 24, 2025 13:21
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Great stuff! Added a few comments + we might have a short description of this in the await documentation

@Rich-Harris
Copy link
Member Author

Added some docs and whatnot, though realised in the course of creating this example that there's a memory leak at the moment — if you discard a fork, the effects that were created inside it don't get destroyed. You can see that my hovering over the button, hovering out, waiting a second, then immediately clicking on it — that should redo the work (since we discard() on pointerleave), but since the effect already exists in the tree that doesn't happen. Looking into it

Copy link
Contributor

Choose a reason for hiding this comment

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

love it, just a nit. it's amazing that this is as simple as it is

@Rich-Harris Rich-Harris merged commit c08ecba into main Oct 24, 2025
18 checks passed
@Rich-Harris Rich-Harris deleted the forking-hell branch October 24, 2025 18:12
@github-actions github-actions bot mentioned this pull request Oct 24, 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.

3 participants