-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
base: main
Are you sure you want to change the base?
Conversation
🦋 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 |
…ses a double flush and makes debugging harder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More feedback -- still looking really good
export function async(node, expressions, fn) { | ||
var boundary = get_pending_boundary(); | ||
|
||
// TODO why is this necessary? doesn't it happen inside `async_derived` inside `flatten`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
packages/svelte/src/compiler/phases/3-transform/server/visitors/CallExpression.js
Show resolved
Hide resolved
Co-authored-by: Elliott Johnson <[email protected]>
This is the PR to go with #15845. Feedback and questions should happen on the discussion rather than here.
Closes #1857, closes #3203, closes #5501
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).preserve_context
more accurategetAbortSignal
into separate 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 test
and lint the project withpnpm lint