Migrating Remotely Bundled Component setup from Svelte 4 to 5 #14298
-
Describe the bugI have a server on port 8000 that bundles and hosts svelte components, which are imported into a sveltekit app running on port 5173. This setup used to work fine on svelte 4, but the migration isnt as straight forward as i'd hoped. The server had a esbuild bundler, which had its outputFiles hosted on a http get request.
This was consumed by the client in two steps.
The referenced Component:
The component thats gettings built by the server is currently an empty demo.
this setup worked like a CHARM! given, its a bit much, but once i had figured it out, it never had any hickups. but as you can see, it relied on instantiating the components as now ive updated the build svelte dependency to 5.1.9 which is the same my main sveltekit app uses. replace but nothing works.
any help would be welcome. i am very stuck and have no clue what levers to try next. Reproduction
LogsNo response System InfoSystem:
OS: macOS 14.5
CPU: (8) arm64 Apple M1 Pro
Memory: 161.06 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
Yarn: 4.5.0 - ~/.nvm/versions/node/v20.17.0/bin/yarn
npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
pnpm: 9.11.0 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 130.0.6723.117 Severityblocking an upgrade |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 9 replies
-
Please provide a reproduction repository |
Beta Was this translation helpful? Give feedback.
-
of the system that worked or the one that doesnt? |
Beta Was this translation helpful? Give feedback.
-
@dummdidumm |
Beta Was this translation helpful? Give feedback.
-
This the version that doesnt work. I am pretty sure the problem is somewhere on the client with how the component is instantiated and mounted. only once the component tries to attach to the dom, some problem arrises. also the bundling is successfull, and from what i can tell, looks exactly like before. |
Beta Was this translation helpful? Give feedback.
-
The problem is that your setup does not deduplicate the Svelte runtime, it exists multiple times: once for your main app, once for your each of your bundles. If you can externalize them somehow that would be the ideal outcome, since it means you also save on bundle size. If that's not possible for some reason, you have to make sure to call the I quickly tried that like this <script module>
import Test from './Test.svelte'
import { mount as _mount } from "svelte";
export function mount(target, props) {
return _mount(Test, { target, props})
}
</script>
<script>
let { ...data } = $props();
console.log("Hello World from Test.svelte");
console.log("Check these amazing props", data);
</script>
<h1 class="text-palette-white">My Test Heading</h1> (and adjusting the place where the component is instantiated to use the exported mount method) ...but it still produces two versions of the Svelte runtime inside the Converting this to a discussion because this is not a bug in Svelte. |
Beta Was this translation helpful? Give feedback.
-
for reference: https://stackoverflow.com/questions/65484019/how-can-i-manually-compile-a-svelte-component-down-to-the-final-javascript-and-c the author adresses the issue of duplicate runtimes headon towards the end:
Is there any way to maintain this approach with svelte5? |
Beta Was this translation helpful? Give feedback.
-
@dummdidumm I am chewing my teeth out on this. I can easily remove the second svelte runtime from the component bundle and get the component down to:
by adding the
the author of the stackoverflow above cites this issue in his explanation for why the second svelte instance is needed. the problems seems to be that we changed from classes to functions. ie, i can no longer instantiate a svelte component with |
Beta Was this translation helpful? Give feedback.
-
@dummdidumm something popped up.
and If i add any idea how to handle this? |
Beta Was this translation helpful? Give feedback.
done. solution is in the repo.