diff --git a/.changeset/clear-pugs-make.md b/.changeset/clear-pugs-make.md new file mode 100644 index 0000000000..c4b55e1a98 --- /dev/null +++ b/.changeset/clear-pugs-make.md @@ -0,0 +1,5 @@ +--- +"@patternfly/pfe-core": patch +"@patternfly/elements": patch +--- +Enable context protocol in SSR scenarios. diff --git a/core/pfe-core/functions/context.ts b/core/pfe-core/functions/context.ts index 2e109b6b2c..d3ebc1f0e4 100644 --- a/core/pfe-core/functions/context.ts +++ b/core/pfe-core/functions/context.ts @@ -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; } diff --git a/core/pfe-core/ssr-shims.ts b/core/pfe-core/ssr-shims.ts index 2fe31e6d6a..dd6248e381 100644 --- a/core/pfe-core/ssr-shims.ts +++ b/core/pfe-core/ssr-shims.ts @@ -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 @@ -55,4 +57,3 @@ globalThis.getComputedStyle ??= function() { } ; -