Skip to content

[Svelte] Add support for Svelte 5#3177

Open
Kocal wants to merge 1 commit intosymfony:3.xfrom
Kocal:svelte-5
Open

[Svelte] Add support for Svelte 5#3177
Kocal wants to merge 1 commit intosymfony:3.xfrom
Kocal:svelte-5

Conversation

@Kocal
Copy link
Copy Markdown
Member

@Kocal Kocal commented Nov 16, 2025

Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? no
Issues Fix #2540
License MIT

Related to #2288

This is in work-in-progress, I still have an error in the browser while trying to render the Hello component when using the AssetMapper:

stimulus.index-S4zNcea.js:7 Error connecting controller

TypeError: Cannot read properties of undefined (reading 'call')
    at _n (client-BATiWue.js:7:27775)
    at client-BATiWue.js:7:39919
    at Hello (Hello-s876KnU.js:8:12)
    at svelte.index-TK8_2BG.js:7:28981
    at svelte.index-TK8_2BG.js:7:11011
    at Ht (svelte.index-TK8_2BG.js:7:24452)
    at Kt (svelte.index-TK8_2BG.js:7:25511)
    at dt (svelte.index-TK8_2BG.js:7:21898)
    at pt (svelte.index-TK8_2BG.js:7:22380)
    at svelte.index-TK8_2BG.js:7:11003

I didn't check how it deals with Webpack Encore yet (opened symfony/webpack-encore#1384).

@Kocal Kocal added this to the 3.0 milestone Nov 16, 2025
@Kocal Kocal self-assigned this Nov 16, 2025
@carsonbot carsonbot added Deprecation Documentation Improvements or additions to documentation Feature New Feature Svelte Status: Needs Review Needs to be reviewed labels Nov 16, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 16, 2025

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
Svelte
render_controller.d.ts 629 B / 353 B 647 B+3% 📈 / 364 B+3% 📈
render_controller.js 1.05 kB / 493 B 1.12 kB+6% 📈 / 512 B+4% 📈

This was referenced Nov 16, 2025
@Kocal Kocal added Status: Needs Work Additional work is needed and removed Documentation Improvements or additions to documentation Status: Needs Review Needs to be reviewed Deprecation labels Nov 17, 2025
@maxperei
Copy link
Copy Markdown
Contributor

hi there, this is one of a kind.. i had a look recently about svelte 5/asset mapper and i ran into the same, so following what i thought i wrote a rollup.config.js (inspired from this repo) on top of this branch to put all the things together
after a while and some distorsions ^^ i managed to render something but it's a big mess at least
anyway i feel this is not the right way things should be done with assetmapper as i got to use a module bundler
there is already a step to compile .svelte files and it's quite unpleasant tho
i could give extra details if it sounds interesting

@Kocal
Copy link
Copy Markdown
Member Author

Kocal commented Nov 20, 2025

Hey @maxperei, sure, any help would be appreciated! :)

@maxperei
Copy link
Copy Markdown
Contributor

ok well, i generated a patch to give a try
of course you'll have to npm i && npm run build again (as well as php bin/console assetmap:install if necessary)
then if you go into ./assets/vendor/svelte you see a new file : index-client.js and a bunch of other files like svelte.index.js, internal/client.js which are overridden and the left ones remain unchanged
this particular index-client.js is very tricky because sometimes it throws a 404 and you will have to expose this file into public/ folder using php bin/console asset-map:compile or just copy it, and sometimes (maybe it's symfony cache or something i can't explain --') it works without exposing it

@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Mar 23, 2026
@Kocal
Copy link
Copy Markdown
Member Author

Kocal commented Mar 23, 2026

Hey @maxperei and sorry for the late reply, support for Svelte 5 is something I've put on the side for a while, but I'd really like to finish this task.

I tried your solution, which is indeed super hacky, but it's still one solution among... 0 other solutions 😅

I've just rebased and force-pushed this PR, and moved the ux.symfony.com things to symfony/ux.symfony.com#32, the files svelte/internal/client.js and svelte/svelte.index.js looks better, but it contains an unresolved dependency to custom-element.js (even if the file exists... maybe the AssetMapper import resolver is missing it?)

image

I will try to open an issue on Svelte to see if they can provide a JSDeliver/ESM-compatible build, that will be easier for everyone.

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

Labels

Feature New Feature Status: Needs Review Needs to be reviewed Svelte

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants