Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Grid depends on side effects #666

Merged

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Nov 30, 2020

This fix #644 (comment)

https://babeljs.io/docs/en/babel-plugin-transform-react-constant-elements is used to optimize the rendering, it moves constant React elements to the upper scope, outside of the React function. So that when the component rerenders, the reference to the React element is identifical, this allows React to skip the rendering of the element, it similar to using React.memo.

However, the data grid relies on a side effect, it depends on its parent to systematically render its children to read the latest value of the grid state and correctly update the DOM.

This is a temporary workaround until we refactor the way the state of the grid is handled. State changes should propagate regardless of React rendering pruning (component memorization or element reference equality).

@oliviertassinari oliviertassinari added docs Improvements or additions to the documentation component: data grid This is the name of the generic UI component, not the React module! labels Nov 30, 2020
@oliviertassinari oliviertassinari force-pushed the data-grid-prevent-optimization branch 4 times, most recently from af4fee6 to 14070ff Compare November 30, 2020 11:37
@oliviertassinari
Copy link
Member Author

@oliviertassinari oliviertassinari force-pushed the data-grid-prevent-optimization branch from 30ae55e to 09982f6 Compare November 30, 2020 17:14
@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Nov 30, 2020
applyValue,
type,
}) => {
export function FilterInputValue(props: TypeFilterInputValueProps) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for a better typescript support, it would better to keep the type definition otherwise it might just see it as a function instead of a react functional component 🤔

Copy link
Member

@dtassone dtassone Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    interface FunctionComponent<P = {}> {
        (props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
        propTypes?: WeakValidationMap<P>;
        contextTypes?: ValidationMap<any>;
        defaultProps?: Partial<P>;
        displayName?: string;
    }

Copy link
Member Author

@oliviertassinari oliviertassinari Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe none of the added types of FunctionComponent are relevant:

I would be in favor of following @eps1lon's point in mui/material-ui#23634 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants