Skip to content

Not working on Svelte-5 #20

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

Closed
chmich opened this issue Jan 17, 2025 · 12 comments
Closed

Not working on Svelte-5 #20

chmich opened this issue Jan 17, 2025 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@chmich
Copy link

chmich commented Jan 17, 2025

For many years, i loved this package, but since Svelte-5

on this setup

import Component from 'svelte-tag';
import App from '../javascript/components/modal.svelte'
new Component({ component: App, tagname: 'modal-tag' })

i receive the error

Image

Is Svelte-Tag not working anymore on Svelte-5?

How to render Svelte without Shadow-DOM? see my Stackoverflow-Post

Thanks,Chris

@crisward
Copy link
Owner

Good to hear you've found it useful.

svelte 5 changed the way a component is mounted, so this would need updating. I'd quite like to keep the compatible with svelte < 5, so I'll need to do a quick check. Not sure if they've changed the way you pass props.

Change detailed here

https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes

line in svelte-tag that needs changing here

https://github.com/crisward/svelte-tag/blob/master/index.js#L76

Not sure if any other changes are needed. We use $$slots too, which looks like they're on the deprecated list. As web components don't have 'snippets' we'll just have to hope they keep slots around for interpolation.

https://svelte.dev/docs/svelte/legacy-$$slots

I'll update this when I get chance, isn't a big change.

@crisward
Copy link
Owner

Looks like I'll have to find a workaround for using svelte/internal too. 😬

@patricknelson
Copy link
Contributor

Keeping an eye on this. If you happen to get to it before me, I'll also backport it into my fork as well. Of course, if the inverse is true, I'll ping this thread.

@crisward
Copy link
Owner

See the svelte5 branch.

The tests are passing but I've no idea if this is working as expected. I've had to jump on some private api's again, but if it works.

@patricknelson if you find another solution let me know.

@chmich
Copy link
Author

chmich commented Jan 20, 2025

Many thanks @crisward, i tested it and it looks that it is working like expected with svelte5.

@crisward
Copy link
Owner

I'll update the readme and push a version 5 to npm at some point (possibly today).

Because of the level of the changes the 5 version won't work with <=4 so I'll need to document that somewhere.

@crisward
Copy link
Owner

crisward commented Jan 20, 2025

This new version has now been published.

https://www.npmjs.com/package/svelte-tag

npm install svelte-tag@5

@crisward crisward added the enhancement New feature or request label Jan 20, 2025
@crisward crisward self-assigned this Jan 20, 2025
@patricknelson
Copy link
Contributor

Not merged into master, yet but here are the apparent changes for reference (assuming fully pushed): master...svelte5

@patricknelson
Copy link
Contributor

Thanks for the effort, @crisward! I’m hoping all my downstream changes are just as simple (particularly nesting and context support), since they did have to reach into the internals a little bit. 🤞

p.s. Looks like slot support got slightly less complicated (and less magical) on our end thanks to the new “snippet” syntax. Looks like you can probably remove this line as well which copied that special createSlotFn:

https://github.com/sveltejs/svelte/issues/2588

@crisward I see you were still referencing .$$slots; have you tried rendering a component running in runes mode and not legacy mode? If so, does it still work?

@chmich
Copy link
Author

chmich commented Jan 20, 2025

Many thanks, @patricknelson and @crisward!

Slots and Custom Elements on Svelte, without shadow-dom: I added a comment to the discussion with rich harris

@crisward
Copy link
Owner

@crisward I see you were still referencing .$$slots; have you tried rendering a component running in runes mode and not legacy mode? If so, does it still work?

No I haven't checked, but I got the code from how svelte creates slots in the playground and those look very similar with and without runes enabled, so I suspect they'll work fine.

Image

Image

@chmich
Copy link
Author

chmich commented Jan 27, 2025

Now i played around slots, based on this «comprehensive» logrocket tutorial:

On the first step, on Rails, i built a vite-app, on the svelte default way. Svelte there is built with:

import { mount } from 'svelte'
import App from '../javascript/slots/App.svelte'
const app = mount(App, {
    target: document.getElementById('app'),
})

As you know, Svelte is not building a shadow dome along the way! And I found: Slots are working on all features described on above mentioned «Comprehensive Tutorial».

As a second step, I built the same components with svelte-tag@5 (on the same app, but with a different name!).

import SvelteTag from "svelte-tag";
new SvelteTag({ component: App, tagname: "svelte-tag-app"})

And added it to the view by <svelte-tag-app/>

I found all features from slots working on the same way like on «first-step»:

{#if $$slots.footer} .... => worked
<svelte:fragment slot="footer"> => worked
named slots => worked

And i tested that all on the browsers Safari, Chrome, Brave, Opera, FireFox, MS Edge.

Like said, i am not experienced in slots, i just became courious because of all theese discussions and want a reliable way for integrating svelte on Rails. And I am completely satisfied with Svelte-Tag!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants