Skip to content
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

Svelte 5: deprecate <svelte:component> #12668

Closed
Rich-Harris opened this issue Jul 30, 2024 · 10 comments · Fixed by #12694
Closed

Svelte 5: deprecate <svelte:component> #12668

Rich-Harris opened this issue Jul 30, 2024 · 10 comments · Fixed by #12694
Milestone

Comments

@Rich-Harris
Copy link
Member

Describe the problem

See #12646 — we're now in a position to deprecate <svelte:component> if we want.

There are some places where in theory it still makes sense to keep it:

<script>
  import A from './A.svelte';
  import B from './B.svelte';

  let { condition } = $props();
</script>

<svelte:component this={condition ? A : B} />
{#each things as thing}
  <svelte:component this={thing.component} />
{/each}

We could solve these with $derived or @const but maybe that's not as nice. The second one could be solved by treating <thing.component> as a component rather than as an (impossible) element, which is a change we could make separately or at the same time. (It would conflict with Svelte Native's property elements, however.)

Both should be considered for 5.0

Describe the proposed solution

see above

Importance

nice to have

@Rich-Harris Rich-Harris added this to the 5.0 milestone Jul 30, 2024
@Conduitry
Copy link
Member

My unscientific impression is that nearly all uses in the wild of <svelte:component> could be simply represented as a dynamic <Component/> without fiddling around with $derived or @const. And that not having two ways to do this outweighs the slightly more verbose code that would be required without it.

The this={} is also just really nasty and I don't like it. I'm also thinking, though, about #12662 (which is about <svelte:element>) where there is a desire to let this be spread to like any other attribute. I don't know whether that's something we want to let people to do (it still seems gross to me) (and I'm doubting that works today with <svelte:component> either) - but whether we get rid of <svelte:component> seems also somewhat tied to the question of whether we want people to be spreading to this. If we don't, it's better to get rid of the syntax entirely that tempts people to try to write code that way.

@paoloricciuti
Copy link
Member

paoloricciuti commented Jul 31, 2024

The second one could be solved by treating <thing.component> as a component rather than as an (impossible) element, which is a change we could make separately or at the same time. (It would conflict with Svelte Native's property elements, however.)

This could be solved by documentation because it already works if you use Thing instead of thing

REPL

And to be fair it seems like a better solution considering also the other components needs to be Uppercase

Tbf it would be cool to have a solution for the first tho even if the derived solution is still not bad.

@rChaoz
Copy link
Contributor

rChaoz commented Jul 31, 2024

On a side note: I think the docs stating <svelte: component> is no longer needed for dynamic components should be moved to deprecations from breaking changes

@Rich-Harris
Copy link
Member Author

It is a breaking change — <Thing> didn't update when Thing changed, and now it does. So it's in the right place

@Conduitry
Copy link
Member

We could still reword it, though - the main thing for the breaking change is that the behavior of <Thing> is different, not that <svelte:component> is no longer necessary, which does indeed sound more like something for the deprecation section.

@paoloricciuti
Copy link
Member

Actually now that I think about it it would be good to throw a warning if you are trying to use thing.something as the name of a component suggesting to uppercase thing...I'll try to work on this this evening (both the deprecation and the warning)

@Rich-Harris
Copy link
Member Author

We'd need to make sure that thing is in scope, otherwise we'd be throwing Svelte Native users under the bus

@paoloricciuti
Copy link
Member

We'd need to make sure that thing is in scope, otherwise we'd be throwing Svelte Native users under the bus

Yeah only if it has a binding

@craigcosmo
Copy link

hey guys, I got a bunch of these warnings, how do I know which part of my code is causing this warning ? and what should be the easier solution to fix?

CleanShot 2024-08-18 at 13 57 37

@paoloricciuti
Copy link
Member

hey guys, I got a bunch of these warnings, how do I know which part of my code is causing this warning ? and what should be the easier solution to fix?

CleanShot 2024-08-18 at 13 57 37

This is from the sveltekit generated root. There's already a PR open to fix this sveltejs/kit#12584 so when that pr is merged they will go away when you update svelte kit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants