-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: allow await
in components
#15844
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
Draft
Rich-Harris
wants to merge
387
commits into
main
Choose a base branch
from
async
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+3,880
−504
Conversation
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
🦋 Changeset detectedLatest commit: 77e0e60 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 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This is the PR to go with #15845. Feedback and questions should happen on the discussion rather than here.
How this works
I'll likely flesh this out in more detail later, but a few quick bullet points:
Batch
. This was always implied (we would flush effects in a microtask, if aflushSync
didn't get there first, so thata++; b++
would result in one flush rather than two) but now it's explicitBatch
has aprocess
method that is responsible for callingprocess_effects
. Whereas previously this would result in effects running immediately (albeit in two phases, so that e.g.$effect
effects happen after other updates), this now only happens for async effects (so that we can know if a state change resulted in async work) and block effects (so that we can know if a newly-created branch has async work, or if newly-destroyed branches can be skipped). All other effects (i.e. user effects, or those that update the DOM) are added to the batch{#if ...}
etc no longer append or remove branches directly. Instead, they do that in a commit callback belonging to the batch, which runs when everything is settledprocess_effects
run it eagerly) in a trenchcoat. This is because deriveds are lazy and would never update in time$derived
with anawait
expression (that isn't inside a function), or whenever you have anawait
expression in a template effect$.template_effect
now takes a third argument, which is an array of all async deriveds{#if ...}
et al) can also containawait
expressions, in which case they are wrapped in an$.async
block. These simply pass the async derived to the inner logic, so that the blocks themselves don't need to be aware that they're dealing with async valuesI'm sure I'm overlooking a ton of stuff but that's as much braindump as I can give right now. Will add comments to more of the source code as and when I can.
WIP
This is not finished; there are bugs, and parts of the code are a little messy. Some stuff could possibly be extracted into a separate PR so that this one is smaller and more focused (e.g. converting boundaries to the
Boundary
class).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 test
and lint the project withpnpm lint