spectrum-web-components
spectrum-web-components copied to clipboard
[Feat]: Investigate SSR Support
Code of conduct
- [X] I agree to follow this project's code of conduct.
Impacted component(s)
All
Description of the requested feature
Look into delivering components with SSR. See https://github.com/lit/lit/tree/main/packages/labs/ssr (used in Astro and possibly Next.js) or https://github.com/lit/lit/tree/main/packages/labs/eleventy-plugin-lit (our docs site).
See https://youtu.be/l6Gn5uV83sw?t=1855 for testing options.
Mockups or screenshots
No response
Implementation notes or ideas
No response
Additional data points for SvelteKit
SvelteKit is SSR for Svelte. Svelte is to SvelteKit as React is to NextJs.
At the time of this writing, here are steps to see the MutationObserver is not defined error that is produced when trying to use SvelteKit's SSR with SWC.
npm create svelte@latest my-app(choose skeleton project, typescript, eslint, prettier, playwright)cd my-appnpm installnpm run dev -- --open(You should see sveltekit working and a welcome to sveltekit message)- stop server
npm install @spectrum-web-components/bundle- create a
+layout.sveltefile heresrc/routes/+layout.svelte - Put this as the contents of the
+layout.svelte.
<script>
import '@spectrum-web-components/theme/scale-medium.js'
import '@spectrum-web-components/theme/sp-theme.js'
import '@spectrum-web-components/theme/theme-lightest.js'
</script>
<sp-theme theme="spectrum" color="lightest" scale="medium">
<slot></slot>
</sp-theme>
npm run devagain to start the server and get aMutationObserver is not definederror.
Temporary solution
You can turn SSR off in SvelteKit, essentially turning your whole app into an SPA by...
- adding a
src/routes/+layout.tsnext to yoursrc/routes/+layout.svelte. - add the following to your
+layout.ts
export const ssr = false
For more details check out https://kit.svelte.dev/docs/page-options#ssr
I think something happened either in Sveltekit or Spectrum WC since I wrote my comment. Because at a glance it seems to be working now for Sveltekit! 🎉
If you try my original steps to reproduce, the MutationObserver is not defined error no longer appears. Official SvelteKit 1.0 just came out so not sure if that has anything to do with it.
Not sure what the process is for closing issues is. So, I'll leave this open for y'all to decide if it should be closed. I can report back here in this issue or reopen it if I notice the MutationObserver error coming back for Sveltekit
@timganter is this still working? I tried the setup you suggested above with
- svelte-kit version 1.20.4
- @spectrum-web-components/bundle version 0.38.0
and see the MutationObserver is not defined error
The MutationObserver is not defined still occurs on Next.js
Still occurs on Astro (with lit SSR integration configured) in SSR mode.
As of both Svelte 4.2.11 and the recent Svelte 5 beta release (5.0.0-next.238) this error still persists server-side in SvelteKit applications.