[Refactor/Tests] verify components in SSR #10237
Labels
0 - new
New issues that need assignment.
p - medium
Issue is non core or affecting less that 60% of people using the library
testing
Issues related to automated or manual testing.
Milestone
Priority impact
p - medium
Test type
SSR
Which Component(s)
all
Unstable Tests
[not actionable before the migration]
When Stencil component is rendered in the Hydrate build, Stencil was providing mocks for a lot of dom APIs. (source code)
When Lit elements are rendered in SSR, Lit also provides a mock dom API, but it's much more lightweight (source code 1, source code 2)
That means that if before Stencil would mock the
element.closest()
calls in SSR, these are no longer mocked in Lit. This may cause some Calcite components to start failing in SSR after migration (with errors likeelement.closest is not a function
)Options:
When you identify a place where a DOM API that is not available in SSR is accessed, you have a few options:
Use optional chaining for property/methods:
Use
globalThis
with optional chaining for global APIs:Conditionally execute code in browser environment only:
isBrowser
check that Stencil provided. The Stencil check was based on presence/absence of DOM globals likewindow.navigator
and etc. Lit's check instead is determined at build-time. That works thanks to a feature called export conditions (this let's Lit set that variable to true in the node.js build, and false in the browser build)Tell consumers of Calcite components in SSR that they need to have happy-dom or jsdom environment setup to correctly render Calcite components.
Lit docs:
Test error, if applicable
No response
PR skipped, if applicable
No response
Additional Info
No response
The text was updated successfully, but these errors were encountered: