-
-
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
…y but evidently it isn't
…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
block(() => { | ||
if (component === (component = get_component())) return; | ||
/** @type {DocumentFragment | null} */ | ||
var offscreen_fragment = null; |
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.
this whole thing is so crazy in such a cool way
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
this.#pending_effect = branch(() => pending(this.#anchor)); | ||
} | ||
} else if (this.parent) { | ||
throw new Error('TODO show pending snippet on parent'); |
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
} | ||
|
||
/** @param {1 | -1} d */ | ||
update_pending_count(d) { |
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.
this is really nicely expressive
let has_await = false; | ||
|
||
walk(expression.body.argument, null, { | ||
AwaitExpression(node, context) { |
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.
AwaitExpression(node, context) { | |
AwaitExpression(_node, context) { |
silence warning
@@ -5,6 +5,7 @@ import type { ICompileDiagnostic } from '../utils/compile_diagnostic.js'; | |||
import type { StateCreationRuneName } from '../../utils.js'; | |||
import type { | |||
AssignmentExpression, | |||
AwaitExpression, |
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.
AwaitExpression, |
AwaitExpression, | ||
CallExpression, | ||
ClassBody, | ||
Comment, |
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.
AwaitExpression, | |
CallExpression, | |
ClassBody, | |
Comment, | |
CallExpression, | |
ClassBody, |
walk(ast, state, { | ||
AwaitExpression(node, context) { |
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.
should we add a TODO: Remove in 6 comment, since we won't need heuristic runes detection then?
@@ -25,6 +25,10 @@ export function CallExpression(node, context) { | |||
return b.arrow([], b.block([])); | |||
} | |||
|
|||
if (rune === '$effect.pending') { |
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.
would this not be true
because we always render the pending snippet during SSR? or is $effect.pending
only true
after the initial pending render? if so confusing naming
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