Skip to content

feat(web-components): add SSR support via Declarative Shadow DOM modules#36247

Merged
radium-v merged 44 commits into
microsoft:masterfrom
radium-v:users/radium-v/wc-add-ssr-support
May 27, 2026
Merged

feat(web-components): add SSR support via Declarative Shadow DOM modules#36247
radium-v merged 44 commits into
microsoft:masterfrom
radium-v:users/radium-v/wc-add-ssr-support

Conversation

@radium-v
Copy link
Copy Markdown
Contributor

Previous Behavior

@fluentui/web-components had no server-side rendering path. Components were defined and rendered only on the client, so SSR frameworks could not pre-render Fluent web components into HTML and hydrate them on load.

The e2e tests ran against a custom harness that only covered client-side rendering.

New Behavior

@fluentui/web-components now supports SSR via Declarative Shadow DOM, built on @microsoft/fast-element and @microsoft/fast-html. Every component in the package ships a paired define-async.ts / *.definition-async.ts module so its template can render on the server and hydrate on the client.

The build also emits two new asset types alongside the JS modules, one pair per component (42 of each), exposed through new package subpath exports:

  • @fluentui/web-components/<component>/template.html: declarative HTML template wrapped in <f-template>, consumed by @microsoft/fast-html to render Declarative Shadow DOM on the server.
  • @fluentui/web-components/<component>/styles.css: plain CSS extracted from the component's styles, importable as a raw stylesheet without pulling in the component's JS.

Currently, the SSR templates and styles are generated at build time and placed in the dist output, but we may want to provide them as src assets in the future for easier consumption and customization.

New test harness modules (test/src/entry-client.ts, test/src/entry-server.ts) and a test/ssr.html entry point template exercise the DSD output end-to-end. The e2e pipeline runs SSR tests after CSR tests.

Several components needed template or base adjustments to render correctly under SSR: tooltip (anchor positioning polyfill handling), text-input, textarea, tree, and tree-item. The theme/set-theme tests are skipped under SSR.

Next Steps

This PR lays the groundwork for SSR support in @fluentui/web-components, but there are still some follow-up tasks to complete:

  • Update to the latest @microsoft/fast-element and remove the @microsoft/fast-html dependency, as DSD rendering will be directly supported in FAST in the next major release.
  • Provide more detailed documentation and examples for using the SSR templates and styles.
  • Add more comprehensive SSR tests covering edge cases and hydration scenarios.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

📊 Bundle size report

✅ No changes found

@github-actions
Copy link
Copy Markdown

Pull request demo site: URL

Comment thread packages/web-components/src/accordion/accordion.definition-async.ts
Comment thread packages/web-components/src/accordion-item/define-async.ts Outdated
Comment thread packages/web-components/src/dropdown/dropdown.base.ts Outdated
Comment thread packages/web-components/src/menu/define-async.ts Outdated
Comment thread packages/web-components/src/textarea/textarea.spec.ts Outdated
Comment thread packages/web-components/src/tooltip/tooltip.ts
Comment thread packages/web-components/src/tree-item/tree-item.base.ts Outdated
@radium-v radium-v force-pushed the users/radium-v/wc-add-ssr-support branch from b80881f to 3ebabb7 Compare May 26, 2026 15:41
@radium-v radium-v force-pushed the users/radium-v/wc-add-ssr-support branch from ac9d18f to 7531a73 Compare May 26, 2026 19:45
@github-actions github-actions Bot added the CI label May 26, 2026
@radium-v radium-v force-pushed the users/radium-v/wc-add-ssr-support branch from 7531a73 to 4601fe9 Compare May 26, 2026 20:17
Comment thread packages/web-components/project.json
Comment thread packages/web-components/src/menu/menu.template.ts
Comment thread packages/web-components/src/text-input/text-input.template.ts
@radium-v radium-v force-pushed the users/radium-v/wc-add-ssr-support branch from b5d30b7 to d525a47 Compare May 27, 2026 18:53
@radium-v radium-v force-pushed the users/radium-v/wc-add-ssr-support branch from d525a47 to c80688c Compare May 27, 2026 20:44
@radium-v radium-v enabled auto-merge (squash) May 27, 2026 20:57
@radium-v radium-v disabled auto-merge May 27, 2026 20:58
@radium-v radium-v enabled auto-merge (squash) May 27, 2026 21:03
@radium-v radium-v merged commit 8ee8c7e into microsoft:master May 27, 2026
14 checks passed
@radium-v radium-v deleted the users/radium-v/wc-add-ssr-support branch May 27, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants