* Revert "fix: take outroing elements out of the flow when animating siblings (#11208)"
This reverts commit c44234dc2f.
* fix: measure elements before taking siblings out of the flow
* lint
* add changeset back
* changeset
* fix: fall back to component namespace when not statically determinable
In #10006 we added more elaborate mechanisms to determine which namespace a given element is in. For `<svelte:element>` we added a "can't know at compile time" case and introduced a limited heuristic into the runtime.
This doesn't work for a few reasons:
- we're checking the parent's namespace to determine the current namespace, but the element itself could be the one that _changes_ the namespace
- as mentioned in the previous comment already, on the first render we can't do any parent analysis
- it does not take into account the static component namespace
The last point is the crucial one: In Svelte 4, we're falling back to the component namespace if we can't know statically - e.g. if someone added `<svelte:options namespace="svg">` then `<svelte:element>` should fall back to that namespace instead.
We were not doing that up until now, which introduced a regression. Fixing this also means getting rid of the (flawed) "can't know statically" heuristic.
Fixes#10858, though for a complete solution we likely need some way to tell `<svelte:element>` the namespace at runtime through a special attribute. Maybe we can use `xmlns` for that like we do in the static case
* support dynamic svelte:element namespace through xmlns attribute
* fix
* feat: allow $inspect reactivity map, set, date
* feat: inspect map without adding new data source
* feat: add inspect
* feat: define inspect on dev mode only
* fix: lint error
Ownership was not widened when assigning a sub state to a different top level state. The set of owners for the state was zero because the owner was on the original parent, but that one was reset to null because it's now the top level of a different state. That meant that there was no owner but also no parent to check for the owner, which is an invalid combination resulting in a nullpointer (and also potentially false positive warnings in other situations).
fixes#11204
* breaking: warn/error on old syntax in runes mode
- warn on slots and event handlers in runes mode
- error on `<slot>` + `{@render ...}` tag usage in same component
closes#9416
* render tag + slot could occur in legacy mode as well, error there, too
* rename metadata.o to metadata.owners, tweak check_ownership implementation
* track parent relationships
* update
* changeset
* adjust test to reflect new semantics
* prevent component using bind: with object it does not own
* failing test
* fix#11060
* add explanatory comment
* don't accidentally narrow global ownership, fix has_owner method
* widen ownership if assigning different state proxies to one another
* don't set owners to null when parent exists
* fix
* only recurse into POJOs
* handle cycles on context
---------
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
Co-authored-by: Dominic Gannaway <dg@domgan.com>
- don't call fallback values eagerly, only when it's actually needed. Avoids potential unwanted side effects
- use derived_safe_equals to memoize results of destructured snippet/each context values with default values to ensure they're only recalculated when their dependencies change. Avoids unstable default values getting called multiple times yielding different results. Use derived_safe_equals to ensure new values are always set, even when mutated. fixes#11143
* added raw elements set
* added test
* added changeset
* moved raw text elements to constands and made array
* moved to correct constants
* fix test
* fix constants formatting
* feat: hot module reloading support for Svelte 5
* fix lockfile
* tweaks
* types
* lint
* lint
* tweaks
* add hmr flag
* tweak
* tweaks
* move HMR logic into its own module
* simplify
* tidy up types
* fix test
* lint
* need some indirection here or references break
* prevent transitions during HMR update
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: loosen proxy signal creation heuristics
* tighten up test
* update comment
* no need to create a source outside an effect here, because it can't result in a reference
* preserve reference to props.$$events
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
- take into account that template could consist of a single script tag, for which querySelectorAll('script') would yield false negatives
- add test to ensure that we don't execute script tags inside `@html` tags next to static script tags
fixes#11082
The character adjustments in the existing warnings are because we remove some tabs from empty lines when initializing the Svelte 5 repo; the warnings were just not checked at that time yet.
Previously, ownership widening/removal was only done if the immediate object that was encountered was state. This isn't always the case. It also didn't take into account classes with state on it (which turn into getters). This change takes both these cases into account and now always traverses the given object deeply.
fixes#11060
- don't throw a dev time error when binding to an export (fixes#11008)
- remove bindings that are for component exports
- throw an error when using a component export with the same name as a property
* chore: apply each block controlled teardown optimization
remove deopt
remove deopt
* remove deopt
* give a more descriptive name if we're running it across modules
* shorter comment
* rename each_element -> parent_node
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: hydrate HTML with surrounding whitespace
* add test
* fix a few more short comments
* tidy up
* avoid magic strings
* avoid magic strings
* fix
* oops
* this condition is always true
* rename child_frag to first_child
* no need to use is_array, it is always an array when hydrating
* simplify close_template
* spread is faster than Array.from
* avoid reassigning argument
* remove some indirection
* tidy up
* tidy
* tidy up
* simplify
* fix
* don't attempt to hydrate children of void dynamic element
* simplify
* tighten up
* fix
* add note, simplify
* tidy up
* changeset
* revert this change, save for a separate PR
* use server-rendered HTML as hydration test starting point
* update tests
* remove _before.html files
* remove _before_head.html files
* override output with _expected.html
* expected output for binding-input case
* remove unused files
* fix
* changeset
* attach DOM to effects
* null out effect.dom
* remove some block.d references
* another
* drive-by fix
* better comment
* unused arg
* another
* another
* another
* more
* finish renaming stuff
* more
* remove item.d
* remove block.d
* remove effect.block
* remove current_block
* delete delete delete
* rename
* remove some stuff we dont need
* simplify
* feat: take form resets into account for two way bindings
When resetting a form, the value of the inputs within it get out of sync with the bound value of those inputs. This PR introduces a reset listener on the parent form to reset the value in that case
closes#2659
* slightly different approach
* tweaks, test
* this is a breaking change, strictly speaking
* bind:files
* use capture phase
* tweak wording
* use promise, explain
* breaking: apply fallback value every time in runes mode
closes#9948
* apply fallback value in setter
* encapsulate fallback logic
* we should keep this logic out of b.set, since it's very specific to accessors
* oops
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* replace transition code
* get rid of some stuff
* simplify
* remove some junk
* not sure how we solved this before, but i guess this makes sense
* oh hey i don't think we need this
* make elseif transparent for transition purposes
* oops
* edge case
* fix
* do not want
* rename
* transition out ecah blocks when emptying
* baby steps
* hydration fix
* tidy up
* tidy up
* tidy up
* fallbacks
* man i love deleting code
* tidy up
* note to self
* why was this an effect
* tidy up
* tidy up
* key blocks
* temporary
* fix
* WIP
* fix
* simplify
* emit events
* delete delete delete
* destroy child effects
* simplify helper
* simplify helper
* fix
* remove commented out code
* fix wonky test
* fix test
* fix test
* fix test
* dynamic components
* fix test
* await
* tidy up
* fix
* fix
* fix test
* tidy up
* we dont need to reconcile during hydration
* simplify
* tidy up
* fix
* reduce indentation
* simplify
* remove some junk
* remove some junk
* simplify
* tidy up
* prefer while over do-while (this appears to have the same behaviour)
* group fast paths
* rename
* unused import
* unused exports
* try this
* simplify
* simplify
* simplify
* simplify
* tidy up
* simplify
* simplify
* tidy up
* simplify
* simplify
* more compact names
* simplify
* better comments
* simplify
* tidy up
* we don't actually gain anything from this
* fix binding group order bug (revealed by previous commit, but exists separately from it)
* tidy up
* simplify
* tidy up
* remove some junk
* simplify
* note to self
* tidy up
* revert this bit
* tidy up
* simplify
* simplify
* simplify
* symmetry
* tidy up
* var
* rename some stuff
* tidy up
* simplify
* keyed each transitions
* make elements inert
* deferred transitions
* fix
* fix test
* fix some tests
* simplify
* fix
* fix test
* fix
* eh that'll do for now
* fix
* revert all these random changes
* fix
* fix
* simplify
* tidy up
* simplify
* simplify
* tidy up
* tidy up
* tidy up
* WIP
* WIP
* working
* tidy up
* fix
* tidy up
* tidy up
* lerp
* tidy up
* rename
* rename
* almost everything working
* tidy up
* ALL TESTS PASSING
* fix treeshaking
* Apply suggestions from code review
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* comment
* explain elseif locality
* explain flushSync
* comments
* this is accounted for
* add some comments
* remove outdated comment
* add comment
* add comments
* rename
* a few naming tweaks
* explain each_item_block stuff
* remove unused arg
* optimise
* add some comments
* fix test post-optimisation
* explicit comparisons
* some docs
* fix intro events
* move effect.ran into the bitmask
* docs
* rename run_transitions to should_intro, add explanatory jsdoc
* add some more docs
* remove animation before measuring
* only animate blocks that persist
* note to self
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
pre effects, which also contain `$:` statements, are more controlled in legacy mode and should only run once per tick, in their defined order. Flushing them out of order can result in bugs. Related to #10795 and #10787
* fix: improve element class attribute behaviour
* Update packages/svelte/src/internal/client/dom/elements/class.js
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
The await block scope analysis was flawed because it did not set the scope for the value/error field before visiting those nodes, resulting in the wrong scopes getting references
As a byproduct, this fixes#8141
* follow up to 10846
* lint
* simplify
* don't update value
* rework logic, rely more on mutation observer, fix bug related to select multiple
* fix lazy select options bug
---------
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: brunnerh <brunnerh@users.noreply.github.com>
* feat: add support for webkitdirectory DOM boolean attribute
* add to types
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* feat: adds reactive Map class to svelte/reactivity
* add docs
* add docs
* add test case
* types
* make reactive set better
* address feedback
* fix typo
* more efficient initialisation
* this is incorrect, it would fail if given a map for example
* increase consistency (with e.g. proxy.js)
* tidy up
* Revert "more efficient initialisation"
This reverts commit 29d4a8078b.
* efficient initialization, without bugs this time
* convention
* delete make_iterable
* update changeset
* efficient initialization
* avoid generator functions
* Update sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
- the `component` parameter expects a component constructor type, not an instance type
- use `import('svelte')` instead of relative paths to not inline all types that are already present in the sibiling module declaration
* null out teardown function
* add managed effects to effect tree
* let the code breathe a bit
* bit more
* man, that's better
* create correct parent-child relationship between if block and its branches
* remove unnecessary arg
* each blocks already have the correct parent-child relationship so i guess we can get rid of this
* simplify
* unused import
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: invalidate store when mutated inside each block
fixes#10771
* Update packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js
We can simplify pre effects by not doing the flush logic at all now. Instead we can move the flushing logic to the only place its needed – for beforeUpdate
* feat: add reactive Set class to svelte/reactivity
* add some type safety
* simplify, read entries lazily
* failing unit test
* fix deletions
* minor tweaks
* work around effect ordering bug
* simplify, make entries lazy
* small tweak
* use var, minor tweaks
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* move bindings to separate file
* tidy up
* errrr this code is confusing as hell but it works and the tests pass. fix it another day
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* split destroy_signal into destroy_effect and destroy_derived
* remove unused code
* remove derived.y
* remove unused code
* lint
* use alias
* simplify
* remove unused code
* remove unused code
* rename value.c to value.reactions, remove from effect type
* rename consumer to reaction, for greater consistency
* remove push_destroy_fn, we don't need it
* more clarity
* this is just incorrect
* align with 10594
* rename signal.i to signal.fn
* rename signal.d to signal.deps
* remove some unnecessary ceremony
* remove unnecessary code
* believe it or not this is faster. it also looks cooler
* tidy up
* remove derived.x
* tighten up mark_subtree_insert
* remove derived.b
* tidy up
* tidy up
* effect.x -> effect.ctx
* signal.b -> signal.block
* tighten up
* tidy up
* separate reaction.r into reaction.effects and reaction.deriveds
* make Derived and Effect inherit from Reaction, rather than Reaction being a union of Derived and Effect
* remove unused stuff
* tidy up
* rename effect.v to effect.teardown
* rename effect.y to effect.ondestroy
* tidy up
* inline doc
* rename
* simplify
* tidy up
* tweak
* remove unnecessary if check
* fix effect teardown bug
* test
* stfu eslint
* remove unused is_runes call
* remove unused argument
* this code doesnt do anything
* typos
* unused import
* source needs no flags
* tidy up
* tidy up
* move some code
* tidy up
* set current signal status, not dependency status
* simplify
* remove unused code
* tidy up
* rename — is_signal_dirty sounds like a pure function but it isnt
* rename value.w to value.version
* rename
* simplify
* MaybeSignal -> MaybeSource
* unused argument
* use default parameters
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* Docs: Change all initizlisation to initialisation
* Reverted to "initialization" when asserting errors with specific message
* Reverted to "initialization" where related to specific error message
- run reactive statements only once per tick, even when they have indirect cyclic dependencies. Made possible by adding an array to the component context, which is filled with identifiers of the reactive statements, and which is cleared after all have run. Reactive statements rerunning before that will bail early if they detect they're still in the list
- part of the solution is to run all reactive statements, and then all render effects, which also fixes#10597
* fix: improve bind:this support around proxyied state
* fix: improve bind:this support around proxyied state
* fix: improve bind:this support around proxyied state
Get more validation tests passing:
- const tag cyclic validation (now runtime, based because of new reactivity system)
- illegal-variable-declaration
- illegal-attribute-character
- remove invalid-reactive-var validation as legacy reactive statements are transformed to functions under the hood, which never escape scope - arguably not completely correct, but will be what the user expects anyway
- invalid-rest-eachblock-binding
- remove edge-case redundant-event-modifier warning because event modifiers are deprecated anyway
- invalid-style-directive-modifier
- invalid-tag-property (now a different error)
- module-script-reactive-declaration
- take comment above script into account when silencing warnings
- invalid-css-declaration
- unused-export-let
- invalid-html-attribute
- illegal-store-subscription
- empty-block
- use interface instead of type (interface is less forgiving)
- rename SourceSignal to Source, etc
- make Derived extend Source, rather than deriveds sharing a type with effects, since they have much more in common with each other
- have a Value type which is a union of Source and Derived, and a Reaction type which is a union of Derived and Effect
- avoid using the Signal type (which is a union of all three) unless necessary
* move some code
* split computations.js into deriveds.js and effects.js
* move reactivity types into separate .d.ts file
* move some signal code
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>