fixes#14466
The logic introduced in #14395 was flawed - not every text or expression outside the template is the child of an attribute. This turns it around: We know that every child of a fragment is inside the template, so we ignore all text/expression tags that are not child of a fragment
Fixes#14399
Add a mechanism to connect render tags to snippets to know where to walk when coming across render tags
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
fixes#14439
This bug was introduced in #13642 because setting the input to null means the equality check ("is the input different") fails if you set the value to null
Also fixes#14441 - this bug was present for a long time, and the reason is the same as for the other bug: The equality check always returns "yes this is the same" if the value is undefined initially. The fix is similar; we need to initialize the input to something that can never be equal to whatever value is passed
This reverts #13255 / #13158, and helps with the validation error part of #14120
If you would have a component like this...
```svelte
<td>hi there</td>
```
...and then render it on the server via our `render` function like this:
```js
const result = render(Main);
```
...then right now you get an error saying that `td` is not valid at this position. But that doesn't seem right, because we should give people the benefit of the doubt: It may very well be that someone renders such a component and then correctly puts it into a `tr` tag themselves on the server (another example is rendering a full html document like in #14120).
All the other validation where there's a known parent (X not valid inside Y) is untouched by this.
Doing this as cleanup prior to tackling #13331
* fix: always use set for private identifiers
* we can simplify this further - no need to check the value was transformed, since the outcome of not returning immediately is the same but with extra steps
* add explanatory note
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
through #14363 I noticed our `export default` validation wasn't quite right:
- missed checking for derived/state exports
- the "cannot have a default export" error was only thrown if you did `export default` from the instance script, but it shouldn't matter from which component part you export it; it's never ok
* fix: ensure internal cloning can work circular values
* better fixc
* 'original' feels slightly clearer than 'json_instance'
* use an optional parameter, so we can omit it in most cases
* Update packages/svelte/src/internal/shared/clone.js
Co-authored-by: Rich Harris <rich.harris@vercel.com>
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
The detection whether or not props are writable is buggy; it doesn't take into account the case when instantiating components via `mount` or legacy-`new`
Fixes#14161
This posed an interesting question: What to do about (non-)`bind:`able properties? The answer I arrived on was: Treat it as if everything that _can_ be bound _is_ treated as bound, and everything else as readonly. In other words, if you're reassigning a prop, it will diverge from the passed in props if it's not bindable or not set in the parent, otherwise it will mutate the passed in props. I think that makes the most sense, given that you can't control this behavior from the outside.
* fix: avoid marking subtree as dynamic for inlined attributes
* fix: i'm a silly goose 🪿
* chore: refactor `is_inlinable_expression` to accept the attribute
* feat: inline dom expression too
* fix: special case literals with `"` in it and fix standalone case
* chore: simpler check first
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
* typo
* add more stuff to snapshot test
* simplify/speedup by doing the work once, during analysis
* simplify
* simplify - no reason these cases should prevent inlining
* return template
* name is incorrect
* name is incorrect
* fix escaping
* no longer necessary
* remove obsolete description
* better concatenation
* fix test
* do the work at runtime
* fix another thing
* tidy
* tidy up
* simplify
* simplify
* fix
* note to self
* another
* simplify
* more accurate name
* simplify
* simplify
* explain what is happening
* tidy up
* simplify
* better inlining
* update test
* colocate some code
* better inlining
* use attribute metadata
* Update packages/svelte/src/compiler/phases/2-analyze/visitors/Identifier.js
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
* Apply suggestions from code review
---------
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
We previously marked all `:root` selectors as global-like, which excempted them from further analysis. This causes problems:
- things like `:not(...)` are never visited and therefore never marked as used -> we gotta do that directly when coming across this
- `:has(...)` was never visited, too. Just marking it as used is not enough though, because we might need to scope its contents
Therefore the logic is enhanced to account for these special cases. Fixes#14118
While fixing this I cleaned up some inconsistencies in what we mark as global. This simplified code and fixed some adjacent bugs, which conindicentally also fixes#14189
* fix: consider static attributes that are inlined in the template
* fix: use `is_inlinable_expression`
* fix: move check for inlinable expression as last
* fix: simplify and correct
* chore: accept single node in `is_inlinable_expression`
* chore: update comment
* chore: add snapshots for non static nodes
Previously, we were applying an explicit nesting selector to the start of a relative selector chain only when starting the traversal. Prepending the selector is important because it ensures we traverse upwards to the parent rule when the current selectors all matched and there's still more to do. But we forgot to do the prepend for parent rules, which meant that if we were nested two levels deep, we would stop too early. This fix ensures we prepend in that case, too.
Fixes#14178
fixes#14168
This reverts the whole "selectors inside `:not` are scoped" logic. Scoping is done so that styles don't bleed. But within `:not`,everything is reversed, which means scoping the selectors now means they are more likely to bleed. That is the opposite of what we want to achieve, therefore we should just leave those selectors alone.
The exception are `:not` selectors with descendant selectors, as that means "look up the tree" and we need to scope all ancestor elements in that case.
If the contents of a `:not` selector don't match, then it's actually a match for `:not` because it's inverted. Therefore, we need to scope such elements. We're also making sure that contents of `:not` that never match actually count as a used (because the result is negated), and as such the contents of `:not` that always match are actually marked as unused.
Fixes#13974
`<a>` tags are valid in both the SVG and HTML namespace. If there's no parent, we therefore have to look downwards to see if it's the parent of a SVG or HTML element.
fixes#7807fixes#13793
We didn't account for the `$props` rune being writtin in a way that makes some props unknown, and they would only be visible through the `customElement.props` definition. This changes the iteration to account for that and also adds a note to the documentation that you need to list out the properties explicitly.
fixes#13785
Fixes#13848.
When we set custom element attributes/props, we should be doing so without the current effect/reaction active. Otherwise, the custom element lifecycle might attach effects/dependencies to the wrong reaction and all manner of things can incorrectly occur
---------
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
We originally didn't extend from `Error` anymore because its fields are of no real value to us, and has problems with serialization in a worker context.
Turns out this was a mistake, because various build tools rely on errors being thrown as something that extends Error, else they try to wrap it in their own error.
We therefore revert that change while still trying to preserve most of the advantages of not extending `Error`, namely nuking the useless stack trace and making sure the message is enumerable.
When CSS is externalized we rightfully rely on the following tooling chain to properly minify CSS. When we inject the CSS however, that tooling won't be able to do that, so we gotta do it ourselves.
This PR brings back most of that logic that existed in Svelte 4. Fixes#13716
Only count down after timeout, else we would reach 0 before our own render effect reruns, but reach 1 again when the tick callback of the prior teardown runs. That would mean we re-subcribe unnecessarily and create a memory leak because the old subscription is never cleaned up.
* fix: add empty stack to `CompileDiagnostic` to show error on build
* chore: generate types
* chore: make stack optional to make TS happy
* chore: generate types -.-"
* chore: add comment
* fix: ensure value is correctly set to zero on the progress element
* fix: ensure value is correctly set to zero on the progress element
* fix: ensure value is correctly set to zero on the progress element
* chore: highlight swallowed errors from await blocks in DEV
* chore: highlight swallowed errors from await blocks in DEV
* chore: highlight swallowed errors from await blocks in DEV
* lint
* feedback
* feedback
* add test
* Update packages/svelte/tests/runtime-runes/samples/await-no-catch-error/main.svelte
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* fix: ensure SVG element attributes have case preserved
* fix: ensure SVG element attributes have case preserved
* fix: ensure SVG element attributes have case preserved
* fix: enable bound store props in runes mode components
* add some JSDoc, since it could be a headscratcher for future us
* make it clear that this is specifically about bindings
* skip intermediate value
* tweak other names too
---------
Co-authored-by: Rich Harris <rich.harris@vercel.com>
* fix: internally wrap store subscribe in untrack
* lint
* Update packages/svelte/src/store/utils.js
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* Version Packages
* Update packages/svelte/CHANGELOG.md
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Closes#13493.
This PR allows the usage of getContext() inside $derived runes. Previously, you could use it, but only on init and not updates – and this inconsistency was unnecessary. We can make it work just like we do in other places.
I resisted this previously because it felt a bit wasteful, but I now think that there's really no way around this: Instead of only going upwards the tree while matching, for `:has` we go _down_ the tree to see what matches. More specifically, we're collecting the children of the current element and then check if one of those does match the selectors inside `:has`.
This makes the way the code works easier to reason about and also removes some boolean tracking we had to add for the previous approach.
Fixes#13779