Skip to content

Commit

Permalink
fix: update context usage for ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Jan 13, 2025
1 parent cd54b8b commit 1bddaa9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/clear-pugs-make.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@patternfly/pfe-core": patch
"@patternfly/elements": patch
---
Enable context protocol in SSR scenarios.
5 changes: 5 additions & 0 deletions core/pfe-core/functions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ function makeContextRoot() {
const root = new ContextRoot();
if (!isServer) {
root.attach(document.body);
} else {
root.attach(
// @ts-expect-error: enable context root in ssr
globalThis.litServerRoot,
);
}
return root;
}
Expand Down
3 changes: 2 additions & 1 deletion core/pfe-core/ssr-shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ globalThis.window ??= globalThis;
globalThis.document ??= new MiniDocument();
// @ts-expect-error: this runs in node
globalThis.navigator ??= { userAgent: '' };
// @ts-expect-error: opt in to event support in ssr
globalThis.litSsrCallConnectedCallback = true;
// @ts-expect-error: this runs in node
globalThis.ErrorEvent ??= Event;
// @ts-expect-error: this runs in node
Expand All @@ -55,4 +57,3 @@ globalThis.getComputedStyle ??= function() {
}

;

0 comments on commit 1bddaa9

Please sign in to comment.