You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using dynamicCompileOptions here because generate is not typically configurable within the svelte Vite plugin, and the only other way I'm aware of to trigger the compilation of SSR code is to use ssrLoadModule, which doesn't fit my use case.
Repo A exports an index.js file with render() and mount() functions.
Repo B is a SvelteKit site, which dynamically imports the module from Repo A over http using an import hook.
So far so good. However, when I call render() within the SvelteKit site, I get lifecycle_outside_component errors any time I try to set/get context or call onMount during component initialization. Digging further, it seems set_component_context is not called before rendering, resulting in component_context being null within internal/client/context.js.
Notwithstanding how nonstandard this architecture is, I'd expect onMount and set/getContext to work properly.
This is a bit of a weird setup...the problem you are facing is that you are generating a server svelte component...this is meant to be used in server runtimes where onMount is actually a noop. However with your setup you are generating the server code but you are accessing with an http request so the import { onMount } from 'svelte'; is resolved by vite to the browser version which can't work with the server version of the component.
Makes sense. I'm working on a micro-frontend architecture in which one repo exports components to be loaded dynamically for SSR by a separate SvelteKit server. I eventually realized this was not the direction to go, and am now blocked by #13186 instead. This can be closed.
Describe the bug
I have a Svelte component in Repo A, with a Vite server configured to emit code for the server:
I'm using
dynamicCompileOptions
here becausegenerate
is not typically configurable within thesvelte
Vite plugin, and the only other way I'm aware of to trigger the compilation of SSR code is to usessrLoadModule
, which doesn't fit my use case.Repo A exports an
index.js
file withrender()
andmount()
functions.Repo B is a SvelteKit site, which dynamically imports the module from Repo A over
http
using an import hook.So far so good. However, when I call
render()
within the SvelteKit site, I getlifecycle_outside_component
errors any time I try to set/get context or callonMount
during component initialization. Digging further, it seemsset_component_context
is not called before rendering, resulting incomponent_context
being null withininternal/client/context.js
.Notwithstanding how nonstandard this architecture is, I'd expect
onMount
andset/getContext
to work properly.Reproduction
REPO
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: