react-imported-component
Version:
I will import your component, and help to handle it
28 lines (27 loc) • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyBoundary = void 0;
var tslib_1 = require("tslib");
var React = (0, tslib_1.__importStar)(require("react"));
var detectBackend_1 = require("../utils/detectBackend");
var useClientPhase_1 = require("../utils/useClientPhase");
var LazyServerBoundary = function (_a) {
var children = _a.children;
return React.createElement(React.Fragment, null, children);
};
var LazyClientBoundary = function (_a) {
var children = _a.children, fallback = _a.fallback;
return (React.createElement(React.Suspense
// we keep fallback null during hydration as it is expected behavior for "ssr-ed" Suspense blocks - they should not "fallback"
// see https://github.com/sebmarkbage/react/blob/185700696ebbe737c99bd6c4b678d5f2a923bd29/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js#L668-L682
, {
// we keep fallback null during hydration as it is expected behavior for "ssr-ed" Suspense blocks - they should not "fallback"
// see https://github.com/sebmarkbage/react/blob/185700696ebbe737c99bd6c4b678d5f2a923bd29/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js#L668-L682
fallback: (0, useClientPhase_1.useIsClientPhase)() ? fallback : undefined }, children));
};
/**
* React.Suspense "as-is" replacement. Automatically "removed" during SSR and "patched" to work accordingly on the clientside
*
* @see {@link HydrationController} has to wrap entire application in order to provide required information
*/
exports.LazyBoundary = detectBackend_1.isBackend ? LazyServerBoundary : LazyClientBoundary;