Skip to content

Commit

Permalink
refix react 19 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilyStrelyaev committed Jan 7, 2025
1 parent 32abc23 commit 50210e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 38 deletions.
58 changes: 28 additions & 30 deletions packages/devextreme-react/src/core/component-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
useLayoutEffect,
useCallback,
useState,
useMemo,
ReactElement,
useMemo,
} from 'react';

import { requestAnimationFrame } from 'devextreme/animation/frame';
Expand Down Expand Up @@ -98,6 +98,31 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(

let widgetConfig: IConfigNode;

const templateContainer = useMemo(() => document.createElement('div'), []);

const elementDescriptor: IOptionElement = {
type: ElementType.Option,
descriptor: {
name: '',
isCollection: false,
templates: templateProps,
initialValuesProps: defaults,
predefinedValuesProps: {},
expectedChildren,
},
props,
};

const options = useOptionScanning(
elementDescriptor,
props.children,
templateContainer,
Symbol('initial update token'),
);

[widgetConfig] = options;
const [, context] = options;

const restoreTree = useCallback(() => {
if (childElementsDetached.current && childNodes.current?.length && element.current) {
element.current.append(...childNodes.current);
Expand Down Expand Up @@ -249,6 +274,7 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(
instance.current,
subscribableOptions,
independentEvents,
widgetConfig,
]);

const onTemplatesRendered = useCallback(() => {
Expand Down Expand Up @@ -279,6 +305,7 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(
scheduleTemplatesUpdate,
updateCssClasses,
props,
widgetConfig,
]);

const onComponentMounted = useCallback(() => {
Expand Down Expand Up @@ -339,35 +366,6 @@ const ComponentBase = forwardRef<ComponentBaseRef, any>(
shouldRestoreFocus.current,
]);

const templateContainer = useMemo(() => document.createElement('div'), []);

const elementDescriptor: IOptionElement = useMemo(() => ({
type: ElementType.Option,
descriptor: {
name: '',
isCollection: false,
templates: templateProps,
initialValuesProps: defaults,
predefinedValuesProps: {},
expectedChildren,
},
props,
}), [
templateProps,
defaults,
props,
]);

const options = useOptionScanning(
elementDescriptor,
props.children,
templateContainer,
Symbol('initial update token'),
);

[widgetConfig] = options;
const [, context] = options;

useLayoutEffect(() => {
onComponentMounted();

Expand Down
9 changes: 1 addition & 8 deletions packages/devextreme-react/src/core/use-option-scanning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
useContext,
useRef,
useLayoutEffect,
useMemo,
} from 'react';

import { ElementType, getElementType, IOptionElement } from './configuration/react/element';
Expand All @@ -32,13 +31,7 @@ export function useOptionScanning(

const updateToken = Symbol('update token');

const configBuilder = useMemo(
() => createConfigBuilder(optionElement, parentFullName),
[
optionElement,
parentFullName,
],
);
const configBuilder = createConfigBuilder(optionElement, parentFullName);

Children.forEach(
children,
Expand Down

0 comments on commit 50210e5

Please sign in to comment.