@lit-labs/ssr-react
Version:
Lit SSR integration for React
35 lines • 1.33 kB
JavaScript
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @fileoverview Side-effect import meant to be loaded on the **server** before
* any user code is loaded. Patches `React.createElement` to support deep SSR of
* Lit components.
*/
import React from 'react';
/* eslint-disable import/extensions */
import ReactJSXRuntime from 'react/jsx-runtime';
import ReactJSXDevRuntime from 'react/jsx-dev-runtime';
import { wrapCreateElement } from '../lib/node/wrap-create-element.js';
import { wrapJsx, wrapJsxDev, wrapJsxs } from '../lib/node/wrap-jsx.js';
/* eslint-disable @typescript-eslint/no-explicit-any */
// The `.default ??` is used to get around inconsistent behavior with how
// tools like webpack seem to do es module interop.
Object.assign(React.default ?? React, {
createElement: wrapCreateElement(React.createElement),
});
if (process.env.NODE_ENV === 'production') {
Object.assign(ReactJSXRuntime.default ?? ReactJSXRuntime, {
jsx: wrapJsx(ReactJSXRuntime.jsx, ReactJSXRuntime.jsxs),
jsxs: wrapJsxs(ReactJSXRuntime.jsxs),
});
}
else {
Object.assign(ReactJSXDevRuntime.default ?? ReactJSXDevRuntime, {
jsxDEV: wrapJsxDev(ReactJSXDevRuntime.jsxDEV),
});
}
globalThis.litSsrReactEnabled = true;
//# sourceMappingURL=enable-lit-ssr.js.map