Skip to content

Commit

Permalink
guard client API against SSR until CustConfComp optimizations are merged
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilyStrelyaev committed Jan 15, 2025
1 parent dbecbe0 commit 07eb7de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/devextreme-react/src/core/component-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ 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,7 +426,7 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(
return (
<RestoreTreeContext.Provider value={restoreTree}>
<TemplateDiscoveryContext.Provider value={{ discoveryRendering: false }}>
{
{ templateContainer &&
createPortal(
<TemplateDiscoveryContext.Provider value={{ discoveryRendering: true }}>
{_renderChildren()}
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
6 changes: 5 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,11 @@ export function useOptionScanning(
};

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

const hasTemplateRendered = templateContainer.childNodes.length > 0;

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

Expand Down

0 comments on commit 07eb7de

Please sign in to comment.