Skip to content

Commit

Permalink
fix: guard client API against SSR until CustConfComp optimizations ar…
Browse files Browse the repository at this point in the history
…e merged (#28730)
  • Loading branch information
VasilyStrelyaev committed Jan 17, 2025
1 parent ddbbf78 commit b0004a2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/devextreme-react/src/core/component-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(

const prevPropsRef = useRef<P & ComponentBaseProps>();

const templateContainer = useMemo(() => document.createElement('div'), []);
const templateContainer = useMemo(
() => (typeof document !== 'undefined'
? document.createElement('div')
: undefined),
[],
);

const [widgetConfig, context] = useOptionScanning(
{
Expand Down Expand Up @@ -422,8 +427,8 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(
return (
<RestoreTreeContext.Provider value={restoreTree}>
<TemplateDiscoveryContext.Provider value={{ discoveryRendering: false }}>
{
createPortal(
{ templateContainer
&& createPortal(
<TemplateDiscoveryContext.Provider value={{ discoveryRendering: true }}>
{_renderChildren()}
</TemplateDiscoveryContext.Provider>,
Expand Down
2 changes: 1 addition & 1 deletion packages/devextreme-react/src/core/nested-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const NestedOption = function NestedOption<P>(
const { children } = props;
const { elementDescriptor, ...restProps } = props;

if (!elementDescriptor) {
if (!elementDescriptor || typeof document === 'undefined') {
return null;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/devextreme-react/src/core/use-option-scanning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { NestedOptionContext, NestedOptionContextContent } from './contexts';
export function useOptionScanning(
optionElement: IOptionElement,
children: ReactNode,
templateContainer: HTMLDivElement,
templateContainer: HTMLDivElement | undefined,
parentUpdateToken: symbol,
): [
IConfigNode,
Expand Down Expand Up @@ -75,7 +75,12 @@ export function useOptionScanning(
};

useLayoutEffect(() => {
if (!templateContainer) {
return;
}

const hasTemplateRendered = templateContainer.childNodes.length > 0;

configBuilder.updateAnonymousTemplates(hasTemplateRendered);
}, [parentUpdateToken]);

Expand Down

0 comments on commit b0004a2

Please sign in to comment.