* fix: correctly validate head snippets on the server
* put the logic in copy_payload so it gets treeshaken in most cases
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* init
* fix
* make `Payload` a class
* doh
* lint
* tweak changeset
* fix
* only export things that should be available on $
* tweak message
* fix
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: don't transform reassigned state in labeled statement in `$derived`
* fix type so optional chaining is unnecessary
* drive-by tidy up
* drive-by tidy up
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: prevent ownership warnings if the fallback of a bindable is used
* fix: filter out symbol from own keys
* fix: don't create sources for `BINDABLE_FALLBACK_SYMBOL`
* fix: use strategy suggested by actually competent person aka @dummdidumm
* chore: rename function
* fix: set deriveds as `CLEAN` if they are assigned to
* chore: remove only
* chore: remove unnecessary typecast
* fix: set unowned as `MAYBE_DIRTY` instead of `CLEAN`
* fix: visit the derived function when to update the dependencies even when it's reassigned
* fix: use `execute_derived` instead of `update_reaction`
* fix: execute deriveds eagerly when they are set if DIRTY
* remove old validation
* fix: rework binding ownership validation
Previously we were doing stack-based retrieval of the owner, which while catching more cases was costly (performance-wise) and prone to errors (as shown by many issues over the months).
This drastically simplifies the ownership validation - we now only do simple static analysis to check which props are mutated and wrap them with runtime checks to see if a binding was established.
Besides making the implementation simpler and more performant, this also follows an insight we had over the months: Most people don't really know what to do with this warning when it's shown beyond very simple cases. Either it's not actionable because they don't really know how to fix it or they question if they should at all (in some cases rightfully so). Now that the warning is only shown in simple and easy-to-reason-about cases, it has a much better signal-to-noise-ratio and will hopefully guide people in the right direction early on (learn from the obvious cases to not write spaghetti code in more complex cases).
closes#15532closes#15210closes#14893closes#13607closes#13139closes#11861
* remove some now obsolete tests
* fix
* better warnings now that we have more info
* fix
* hoist
* we only care about mutation, not reassignment
* tidy
* handle prop aliases
* mutation validation is only tangentially linked to context requirement
* no need for two vars, one will do
* update warning, include mutation location
* tweak
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix-untracked-writes-leak
* fix
* fix
* Update packages/svelte/src/internal/client/runtime.js
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* fix: ignore generic type arguments while creating AST
bumps esrap and fixes a resulting error: because esrap now uses a more compliant TSESTree AST, it has `typeArguments` instead of `typeParameters` in some places - those were not deleted while stripping types, which caused an error.
* fix $$render_inner declaration
fixes#15543
No test because this is a one-liner in a stable part of the code-base, also it can only happen within legacy mode when using bindings which is not getting any new updates at this point
* fix: prevent state runes from being called with spread
* prevent spread arguments for all runes except $inspect
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: allow get_proxied_value to return original value when error
closes#15546
* Update packages/svelte/src/internal/client/proxy.js
---------
Co-authored-by: Rich Harris <hello@rich-harris.dev>
* feat: make deriveds writable
* add optimistic UI example
* add note to when-not-to-use-effect
* add section on deep reactivity
* root-relative URL
* use hash URL
* mention const
* make handler async, move into script block
* Add failing JSDoc property svelte-migrate conversion tests
* Add further test case and remove default value in JSDoc output
* Look for inlined JSDoc comments after a hyphen
* Add changeset
* move parent property onto Signal
* don't self-invalidate when updating a source create inside current reaction
* lazily create deep state with parent reaction
* no need to push_derived_source with mutable_state, as it never coexists with $.derived
* reduce indirection
* remove state_unsafe_local_read error
* changeset
* tests
* fix test
* inelegant fix
* remove arg
* tweak
* some progress
* more
* tidy up
* parent -> p
* tmp
* alternative approach
* tidy up
* reduce diff size
* more
* update comment
Fixes#14072
`:has()` was matching only against descendants or siblings, but not sibling's descendants. This makes the logic be able to go forward or backwards, simplifying a lot of cases along the way.
For instance, specifying a tree-structural pseudo-class to
`::view-transition-new` should still constitute a valid global-like
selector.
Fixes#15312
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* ix: ensure transient writes to tracked parent effects works as expected
* lint
* format test
* tweak changeset
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
Fixes#14579
Although this isn't 100% correct because there's no `group` attribute, there's no better way to make people have components' props just be `HTMLInputAttributes` and allow them to reference `group`
* fix: on teardown, use the last known value for the signal before the se
* fix: on teardown, use the last known value for the signal before the se
* fix: on teardown, use the last known value for the signal before the se
* fix: on teardown, use the last known value for the signal before the se
* fix: on teardown, use the last known value for the signal before the se
* Update packages/svelte/src/internal/client/reactivity/props.js
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* Update packages/svelte/src/internal/client/reactivity/props.js
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* Update packages/svelte/src/internal/client/reactivity/props.js
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* lint
* lint
* lint
* Update .changeset/sharp-elephants-invite.md
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix null and warning for local handlers
* test
* changeset
* treat `let handler = () => {...}` the same as `function handler() {...}`
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* add style attribute when needed
* set_style()
* to_style()
* remove `style=""`
* use cssTest for perfs
* base test
* test
* changeset
* revert dom.style.cssText
* format name
* use style.cssText + adapt test
* Apply suggestions from code review
suggestions from dummdidumm
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* fix priority
* lint
* yawn
* update test
* we can simplify some stuff now
* simplify
* more
* simplify some more
* more
* more
* more
* more
* more
* remove continue
* tweak
* tweak
* tweak
* skip hash argument where possible
* tweak
* tweak
* tweak
* tweak
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* style must be set via set_attribute
* test
* changeset
* add empty string and null in test
* explanatory comment
* this is now redundant, set_attribute takes care of it
* drive-by
* tweak changeset
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* set_attributes for <svelte:element>
* changeset
* Update .changeset/wise-hats-wonder.md
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* add changeset
* remove `chore` changeset — no need for non-user-facing changes to appear in changelog
* Update packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/element.js
* determine element traits inside set_attributes
* unused
* stash lookup
---------
Co-authored-by: adiguba <frederic.martini@gmail.com>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* fix: correctly set `is_updating` before flushing root effects
* rename for consistency with update_effect
* use var
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
This ensures someone like Astro can render multiple islands and the unique ids produced in them are able to be deduplicated
---------
Co-authored-by: Hugos68 <hugokorteapple@gmail.com>
Co-authored-by: paoloricciuti <ricciutipaolo@gmail.com>
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
* fix: catch error on @const tag in svelte:boundary
* changeset
* edit changeset
* test
* fix
* rollback
* simpler way to do that
* rollback
* roolback again
---------
Co-authored-by: paoloricciuti <ricciutipaolo@gmail.com>
* this appears to be unnecessary
* DRY out
* this doesnt appear to do anything useful
* simplify
* remove unused if block
* simplify, make non-recursive
* unused
* DRY
* simplify
* tidy up
* simplify
* changeset
* unused
* Revert "changeset"
This reverts commit 946e00dcf7.
* make flush_sync non-recursive
* fix flushSync types
* fix
* unused
* simplify
* tidy up
* tidy up
* present unnecessary microtasks, avoid flushing if no function provided
* simplify
* no `?? ''` on some expressions
* changeset
* delete operator returns boolean
* inverted conditions are a lil confusing
* no need for else after return
* simplify condition
* may as well add special handling for undefined while we're here
* use normal string literal when there are no values
* omit assignment when there is no text content
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: `muted` reactive without `bind` and select/autofocus attributes working with function calls
Co-authored-by: Joel Howse <joel@helicalco.com>
* chore: add comments
---------
Co-authored-by: Joel Howse <joel@helicalco.com>
They DOM could've been updated already by the time the event bubbling logic is reached, so the target element itself could not be notified of the event because it is marked as disabled. But the target could not have been disabled because it emits the event in the first place, so we emit regardless.
No test because not reproducible in jsdom environment.
Fixes#15256
This was the result of a `@ts-expect-error` silencing other type errors, which lead to this creeping in. This changes it so that the object is fully set, so we'll get type errors when new properties need to be added
fixes#15284
- `$derived` can contain `$state` declarations so we cannot ignore them, so this reverts #14533
- instead, we add equality checks to not do this expensive work unnecessarily
- this also adds a render effect similar to the class ownership addition when it detects a getter on a POJO during ownership addition
fixes#15164
* fix: when an unowned derived is tracked again, remove unowned flag
* fix: when an unowned derived is tracked again, remove unowned flag
* test case
* test case
* cleanup unused logic
* simplify
* simplify
* simplify
* simplify
* add test
* fix other issue
* back to original plan
* Apply suggestions from code review
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* fix: ensure custom element updates don't run in hydration mode
When a custom element is created before Svelte hydration kicks in, it will scaffold itself, using the properties given via attributes.
Now when a custom element property is set during Svelte's hydration, the Svelte custom element component could run logic like updating an each block. Without turning off hydration mode during that time, the update would try to pick up existing element nodes (because it thinks they must be there because of hydration mode), and crash.
No test because it would require a setup where we can ensure the element is scaffolded before hydration runs.
Fixes#15213
* changeset
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
Avoid going through the `element.value = element.__value = newValue` condition because `__value` is actually how Lit stores the current value on the element, and messing with that would break things: Lit would think the value hasn't changed (because `__value` is already set to the new value by us) and doesn't fire an update.
fixes#15194
* fix: ensure tracking returns true, even if in unowned
* fix: ensure tracking returns true, even if in unowned
* Update packages/svelte/tests/runtime-runes/samples/effect-tracking-unowned/main.svelte
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
`slot` is treated as a regular prop if it is not used directly inside another component, but we were running validations on such regular props that should only be run on real slots.
Fixes#15125
Instead of doing ownership addition at each `getContext` call site, we do it once as the `setContext` call site and make the state basically global.
- avoids potential false positives in edge cases
- makes the whole thing more performant, especially around things like calling `getContext` inside a list item component
- false negatives are unlikely from this
fixes#15072
Fixes#14910
The issue occurs only when :has() targets at a component's root element and because include_self is false.
I came to the conclusion that this is the same case as :root:has(.scoped).
Fixes#15027 and fixes#14995
When the target element is inside a block or component, get_following_sibling_elements was looking only for sibling elements after the block/component. This PR fixes it by starting the search from the begging of the block/component and skipping nodes that go before the target element.
* fix: ensure signal write invalidation within effects is persistent
* fix: ensure signal write invalidation within effects is persistent
* fix: ensure signal write invalidation within effects is persistent
* address feedback