Closed LazerJesus closed 2 days ago
Please provide a reproduction repository
of the system that worked or the one that doesnt? gonna take me till tmrw
@dummdidumm https://github.com/vivalence/Svelte-Widget-Demo
This the version that doesnt work. with svelte 4 and just a few adjustments this setup worked like a charm.
I am pretty sure the problem is somewhere on the client with how the component is instantiated and mounted. I think that because thats the thing that changed most and the :server/bundle/Test.svelte component's console.log() statement actually executes and prints to the client console.
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.
you can view the bundle by visiting http://localhost:3000/bundle/Test.svelte
once the server is running.
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 mount
method of your bundled component, not the one of your main app. In other words, you likely need a wrapper that does the mounting inside the bundle.
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 Test.svelte
bundle. I don't know why that is, but if you fix that then that would work (but as I said above ideally you would externalize the whole Svelte runtime).
Converting this to a discussion because this is not a bug in Svelte.
Describe the bug
I 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. Let me show first how the old setup used to work server and client side, and then what ive tried so far.
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 Widget functioned as the Sveltekits Universal interface/ loader.
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
new component
classes.now ive updated the build svelte dependency to 5.1.9 which is the same my main sveltekit app uses. on the client ive tried a few different approaches like:
replace
new component
withcmp = createClassComponent({component:Component, target });
andcmp = mount(Component, { target, props: payload,});
but nothing works. I get various error messages like:
any help would be welcome. i am very stuck and have no clue what levers to try next.
Reproduction
above
Logs
No response
System Info
Severity
blocking an upgrade