Skip to content

Commit

Permalink
Use global flag for lit/react and labs/ssr-react prop coordination
Browse files Browse the repository at this point in the history
  • Loading branch information
augustjk committed Mar 9, 2024
1 parent 9702f91 commit d5dcabb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/chilled-plants-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@lit-labs/ssr-react': patch
'@lit/react': patch
---

Use a global flag to detect whether `@lit-labs/ssr-react/enable-lit-ssr.js` was used for coordinated props when server rendering components made with `@lit/react`.
8 changes: 8 additions & 0 deletions packages/labs/ssr-react/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

// eslint-disable-next-line no-var
declare var litSsrReactEnabled: undefined | boolean;
2 changes: 2 additions & 0 deletions packages/labs/ssr-react/src/node/enable-lit-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ if (process.env.NODE_ENV === 'production') {
jsxDEV: wrapJsxDev(ReactJSXDevRuntime.jsxDEV),
});
}

globalThis.litSsrReactEnabled = true;
3 changes: 2 additions & 1 deletion packages/react/src/create-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ export const createComponent = <
// element properties in a special bag to be set by the server-side
// element renderer.
if (
React.createElement.name === 'litPatchedCreateElement' &&
(React.createElement.name === 'litPatchedCreateElement' ||
globalThis.litSsrReactEnabled) &&
Object.keys(elementProps).length
) {
// This property needs to remain unminified.
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

// eslint-disable-next-line no-var
declare var litSsrReactEnabled: undefined | boolean;

0 comments on commit d5dcabb

Please sign in to comment.