* add test sample
* add test for sveltejs/kit#15059
* fix: reconnect deriveds inside branch effects
* add changeset
* fix: derived with no deps always set as MAYBE_DIRTY
fixes#17342
* add test for #17342
* additional changeset
* refactor: extract setting derived status to helper, apply to sources.js
* add test case for #17352
* fix: reconnect child deriveds when evaluating connected parent derived
fixes#17352
* fix import order causing Cannot read properties of undefined on dev load
* remove duplicate iteration over deps
* minor style tweaks
* oops, fix merge
* use update_derived_status, so that we never set a dep-less derived MAYBE_DIRTY
* tweak
* reaction.deps cannot be null for a MAYBE_DIRTY derived
* make it such that reactions without deps are never MAYBE_DIRTY
* since we no longer need to check reaction.deps === null, we can revert this bit
* more explicit check
* tidy up
* more
* gah whoops
* move import
* simplify test
* make dep-less derived behaviour more explicit, move it above is_destroying_effect handling
* remove test - this is adequately covered by #17445
* replace tricky unit test with component-based test
* remove incorrect test
* remove the BRANCH_EFFECT stuff
* tidy up
* DRY
* tweak, add explanatory comment
* tweak
* explanatory comment
* remove changeset
* update changeset
---------
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* feat: type `currentTarget` in `on` function
* `EventTarget &` is redundant, `Element` already extends `EventTarget`
* no need for optional chaining
* add currentTarget for other overloads
* update changeset
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: prevent infinite loop when HMRing a component with an `await`
* update test
* fix
* reintroduce old logic to fix ever-growing stack of block effects
* update snapshot
* tweak names for clarity, simplify `update` slightly
---------
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
* fix: set Root start/end to null when fragment contains only whitespace
* format
* always set root.start to 0 and root.end to template.length
* Update .changeset/fruity-knives-ring.md
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
Co-authored-by: Rich Harris <hello@rich-harris.dev>
In #17105 one line in `update_reaction` was changed that can cause reactivity loss. It checks if the reaction is updated inside of an effect and only then will push to the reactions. The prior version had an additional check to still add to the reactions if there is already at least one reaction on the derived, indicating it is connected. Removing this check fixes#17263 while keeping correctness: a connected derived by definition at least has one reaction and therefore can properly cleanup.
* chore: more effect helpers
This adds two new helpers that helped me tremendously with getting to the bottom of #17197:
- `log_reactions`: Logs the graph of reactions starting from the given signal, and also checks if the effect leafs are reachable and if they are able to schedule a root
- `log_inconsistent_branches`: Logs if there are paths in the graph where a branch is clean above a non-clean branch, which means that the part of the graph cannot schedule batches anymore
* shut up eslint
* fix: link offscreen items and last effect in each block correctly
It's possible that due to how new elements are inserted into the array that `effect.last` is wrong. We need to ensure it is really the last item to keep items properly connected to the graph. In addition we link offscreen items after all onscreen items, to ensure they don't have wrong pointers.
Fixes#17201
* revert #17244
* add test
* use local version of esrap, for now
* WIP
* WIP
* fixes
* more
* add `Declaration` visitor
* add `TransitionDirective`
* `UseDirective`, `OnDirective`
* more directives
* `SpreadAttribute`, directive shorthands
* `{#if ...} {:else ...}`
* fix
* more
* add tags, `AnimateDirective`
* `KeyBlock`
* `SelectorList`, `<svelte:whatever />`
* quote text in `Attribute` visitor
* tweak test logic to reduce false negatives
* fix
* fix
* add separate test suite
* fix
* more
* slightly nicer printing
* install from pkg.pr.new
* merge main
* bump
* fix
* remove any
* fix indentation
* replace TODO with a type error
* bump
* fix
* esrap@2
* lockfile
* try this
* regenerate
* add small comment
* fix test file
* ensure new lines at end of file
* common tests
* tests for A-nodes
* fix interface
* tests for B-nodes
* delete basic test
* tests for C-nodes
* combine css tests
* tests for E-nodes
* tests for H-nodes
* tests for I-nodes
* tests for K-nodes
* tests for L-nodes
* tests for N-nodes
* add todo
* remove other todo
* tests for O-nodes
* tests for P-nodes
* tests for R-nodes
* tests for S-nodes
* tests for T-nodes
* tests for U-nodes
* seperate css and svelte visitors for clarity
* fix failing test
* rename early tests
* fix const test
* fix svelte-element
* move block to css visitors
* fix css output
* fix #if indentation
* fix self closing tag problems
* use common method for attributes
* put attributes into multiple lines if too long
* fix new lines for #each:else
* fix svelte element new lines
* rmeove usless comments & fix playground
* improved formatting
* support formatting for a lot more nodes
* style
* fixes for formatting
* cleanup
* make typescript happy
* add formatting related test
* add docs
* changeset
* regenerate types
* fix self-closing tags
* fix bracket placement
* break length 50
* add support for additional comments
* remove abstract keyword
* strip out more typescript gubbins
---------
Co-authored-by: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com>
Co-authored-by: Manuel Serret <mserret99@gmail.com>
Fixes#17236
* fix: generate correct code for simple destructurings
* add a test (existing one doesn't fail on main)
* adjust existing test so it fails on main
* slightly neater approach (with identical outcome)
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
This ensures that an animation does not run when the element is first transitioning in. Else the animation would mess with the transition (overriding its animation basically). Due to our test setup it's not testable but I veryfied it fixes#17181 (tested all reproductions in there)
It's possible that due to how new elements are inserted into the array that `effect.last` is wrong. We need to ensure it is really the last item to keep items properly connected to the graph.
Fixes#17201
---------
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
Since async-await was introduced into the code base a lot has changed. This lifts the restriction.
Closes#17131 (though I still wonder why Skeleton does that)
We have to take non-tracking contexts into account, especially while in the original `fork(() => ...)` context.
Closes#17206
---------
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
* fix: don't execute attachments and attribute effects eagerly
attributes_effect and attachments are blocks since they need the managed "don't just destroy children effects"-behavior, but they're not block effects in the sense of "run them eagerly while traversing the effect tree or while flushing effects". Since the latter was the case until now, it meant that forks could cause visible UI updates.
This PR introduces a new flag to fix that. `BLOCK_NON_EAGER` is basically a combination of block effects (with respects to the managed behavior) and render effects (with respects to the execution timing).
Fixes https://github.com/sveltejs/kit/issues/14931
* managed_effect
* fix: take async into account for bindings/transitions/animations/attachments
- block on async work
- error at compile time on await expressions. Right now it gives confusing errors later at compile time or at runtime
Fixes#17194
* this was weird
* chore: failing test for derived + fork + block
* fix: don't set derived values during time travel
* fix: skip no async
* fix: only set `derived.v` outside a fork
* chore: simplify
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* tidy up test a bit (missing text makes things confusing in the sandbox)
* update comment
* tweak
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: maintain correct linked list of effects when updating each blocks
* working
* tidy up
* changeset
* remove unnecessary assignment, add comment explaining unidirectionality
* fix: don't cancel transition of already outroing elements
#16977 forgot one detail: While an element is outroing, the block of e.g. an if block can be triggered again, resolving to the same condition. In that case we have an in-between state where the element is still onscreen but already outroing. We have to detect this to not eagerly destroy the corresponding effect when we arrive at the outro/destroy logic.
Fixes#16982
* fix
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* perf: don't use tracing overeager during dev
#17176 is a case where many sources are created and then written to (due to Svelte 4 prop mechanics), and our tracing kicked in eagerly. That combined with the excessive depth of the related stack traces slowed things down tremendously.
The fix is simple: Don't record stack traces until we've seen this source get updated for a couple of times. Additionally we now delete the `updates` map after a flush. Previously it was just an ever-growing stack trace map.
* fix
* fix
* fix: avoid other batches running with queued root effects of main batch
When `#traverse_effect_tree` runs, it can execute block effects, which in turn can create effects which are scheduled, which means `queued_root_effects` is now filled again. We didn't take that into account and assumed that in `#commit` we would have no queued root effects. As a result another batch could wrongfully run with the queued root effects of the main batch. That in turn can mean that `skipped_effects` is different on the other batch, leading to some branches not getting traversed into. As a result part of the tree is marked clean while further below batches are still not marked clean. That then breaks reactivity as soon as you schedule an effect in this still-not-clean sub tree, as it will not bubble all the way up to the root, since it comes across a not-clean branch, assuming something was already scheduled.
The fix is simple: Stash the queued root effects before rebasing branches.
Fixes#17118
* add note to self
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
Execution of eager effects didn't set `is_updating_effect`, which meant the logic in `get` would wrongfully prevent dependencies being added to `reactions` of sources/deriveds.
Fixes#17133
* fix: correctly handle functions when determining async blockers
We didn't properly handle functions (function declarations/expressions/arrow functions) when calculating what is a blocker. More specifically
- we did defer assignment of variable declarations even for arrow functions and function expressions, which is unnecessary and causes bugs when they're then referenced eagerly further below
- we did not compute blockers for functions. They could reference blockers themselves, as such other code referencing them should wait on the related blockers
Fixes#17129
* put into its own function
* fix: take blockers into account when creating `#await` blocks
The unrelated-but-in-the-same-issue-referenced-bug
* oops
* fix
* minimize compiled output changes
* no idea why editor showed these as unused
Use case: Remote queries that are created on one screen, then are used again on another screen. Original parent effect is destroyed in that case but derived should still be reactive. It wasn't prior to this fix because inside `get` the `destroyed` variable would be true and so deps would not properly be recorded.
Fixes https://github.com/sveltejs/kit/issues/14814
* fix: parallelize async `@const`s in the template
This fixes#17075 by solving the TODO of #17038 to add out of order rendering for async `@const` declarations in the template.
It's implemented by a new field on the component state which is set as soon as we come across an async const. All async const declarations and those after it will be added to that field, and the existing blockers mechanism is then used to line up the async work correctly. After processing a fragment a `run` command is created from the collected consts.
* fix
* tweak
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>