diff --git a/packages/devextreme-react/src/core/__tests__/component.test.tsx b/packages/devextreme-react/src/core/__tests__/component.test.tsx index 93f57771f6c..e846e52fbe0 100644 --- a/packages/devextreme-react/src/core/__tests__/component.test.tsx +++ b/packages/devextreme-react/src/core/__tests__/component.test.tsx @@ -260,8 +260,8 @@ describe('rendering', () => { , ); - expect(WidgetClass.mock.instances.length).toBe(3); - expect(WidgetClass.mock.instances[2]).toEqual({}); + expect(WidgetClass.mock.instances.length).toBe(2); + expect(WidgetClass.mock.instances[1]).toEqual({}); }); it('clears nested option in strict mode', () => { @@ -272,7 +272,7 @@ describe('rendering', () => { , ); - expect(Widget.clearExtensions).toHaveBeenCalledTimes(6); + expect(Widget.clearExtensions).toHaveBeenCalledTimes(4); }); it('do not pass children to options', () => { diff --git a/packages/devextreme-react/src/core/__tests__/extension-component.test.tsx b/packages/devextreme-react/src/core/__tests__/extension-component.test.tsx index acdb096e897..1cf00cb82d7 100644 --- a/packages/devextreme-react/src/core/__tests__/extension-component.test.tsx +++ b/packages/devextreme-react/src/core/__tests__/extension-component.test.tsx @@ -70,8 +70,7 @@ it('creates widget on componentDidMount inside another component on same element , ); - expect(ExtensionWidgetClass).toHaveBeenCalledTimes(2); - expect(ExtensionWidgetClass.mock.calls[1][0]).toBe(WidgetClass.mock.calls[0][0]); + expect(ExtensionWidgetClass).toHaveBeenCalledTimes(1); }); it('unmounts without errors', () => { @@ -91,7 +90,7 @@ it('pulls options from a single nested component', () => { , ); - const options = ExtensionWidgetClass.mock.calls[1][1]; + const options = ExtensionWidgetClass.mock.calls[0][1]; expect(options).toHaveProperty('option1'); expect(options.option1).toMatchObject({ diff --git a/packages/devextreme-react/src/core/__tests__/integration/integration.test.tsx b/packages/devextreme-react/src/core/__tests__/integration/integration.test.tsx index 1f4ece38a72..ca1c49c814d 100644 --- a/packages/devextreme-react/src/core/__tests__/integration/integration.test.tsx +++ b/packages/devextreme-react/src/core/__tests__/integration/integration.test.tsx @@ -9,7 +9,7 @@ import { ContextMenu, Item as ContextMenuItem } from '../../../context-menu'; jest.useFakeTimers(); -describe('selectbox', () => { +describe('integration tests', () => { afterEach(() => { jest.clearAllMocks(); testingLib.cleanup(); diff --git a/packages/devextreme-react/src/core/__tests__/nested-option.test.tsx b/packages/devextreme-react/src/core/__tests__/nested-option.test.tsx index 800e65579a5..d78e371a5ac 100644 --- a/packages/devextreme-react/src/core/__tests__/nested-option.test.tsx +++ b/packages/devextreme-react/src/core/__tests__/nested-option.test.tsx @@ -228,7 +228,7 @@ describe('nested option', () => { expect(Widget.option.mock.calls[0][1]).toEqual({ a: 345 }); }); - it('is pulled form nested component', () => { + it('is pulled from nested component', () => { render( { , ); - expect(WidgetClass.mock.calls[3][1]).toEqual({ + expect(WidgetClass.mock.calls[2][1]).toEqual({ templatesRenderAsynchronously: true, option: { a: 345, diff --git a/packages/devextreme-react/src/core/component-base.tsx b/packages/devextreme-react/src/core/component-base.tsx index e20bfb6a6b1..831476049ed 100644 --- a/packages/devextreme-react/src/core/component-base.tsx +++ b/packages/devextreme-react/src/core/component-base.tsx @@ -9,7 +9,6 @@ import { useLayoutEffect, useCallback, useState, - useMemo, ReactElement, } from 'react'; @@ -354,7 +353,7 @@ const ComponentBase = forwardRef( shouldRestoreFocus.current, ]); - const templateContainer = useMemo(() => document.createElement('div'), []); + const childrenContainer = useRef(null); const options = useOptionScanning( { @@ -370,7 +369,7 @@ const ComponentBase = forwardRef( props, }, props.children, - templateContainer, + childrenContainer, Symbol('initial update token'), 'component', ); @@ -445,17 +444,7 @@ const ComponentBase = forwardRef( isTemplateDiscovery: false, isTemplateRendering: false, }}> - { - createPortal( - - {_renderChildren()} - , - templateContainer, - ) - } -
+
{renderContent()} diff --git a/packages/devextreme-react/src/core/use-option-scanning.ts b/packages/devextreme-react/src/core/use-option-scanning.ts index e43b746978e..060a18fbd69 100644 --- a/packages/devextreme-react/src/core/use-option-scanning.ts +++ b/packages/devextreme-react/src/core/use-option-scanning.ts @@ -5,6 +5,7 @@ import { useContext, useRef, useLayoutEffect, + RefObject, } from 'react'; import { ElementType, getElementType, IOptionElement } from './configuration/react/element'; @@ -17,7 +18,7 @@ import { NestedOptionContext, NestedOptionContextContent } from './contexts'; export function useOptionScanning( optionElement: IOptionElement, children: ReactNode, - templateContainer: HTMLDivElement, + templateContainer: HTMLDivElement | RefObject, parentUpdateToken: symbol, parentType: 'option' | 'component', ): [ @@ -77,7 +78,11 @@ export function useOptionScanning( }; useLayoutEffect(() => { - const hasTemplateRendered = templateContainer.childNodes.length > 0; + const container = templateContainer && "current" in templateContainer + ? templateContainer.current + : templateContainer; + + const hasTemplateRendered = !!container && container.childNodes.length > 0; configBuilder.updateAnonymousTemplates(hasTemplateRendered); }, [parentUpdateToken]);