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] Fix webpack v5 #449

Merged
merged 6 commits into from
Oct 29, 2020

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Oct 17, 2020

webpack v5 does no longer polyfill Node.js modules https://webpack.js.org/blog/2020-10-10-webpack-5-release/. This fixes the component under this environment. It replaces https://github.com/browserify/events with a custom version. Help with #447.

It should also remove some bundle size, using a simplified version of the polyfill used by webpack v4.

@oliviertassinari oliviertassinari added component: data grid This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work labels Oct 17, 2020
@oliviertassinari
Copy link
Member Author

@dtassone I have added a warning to edge against leaks.

@@ -12,5 +11,5 @@ export function useApiRef(): ApiRef {
const logger = useLogger('useApiRef');
logger.debug('Initializing grid api with EventEmitter.');

return React.useRef<GridApi>(new EventEmitter());
return React.useRef(new EventEmitter() as GridApi);
Copy link
Member

Choose a reason for hiding this comment

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

why not use the Generic?

Copy link
Member

Choose a reason for hiding this comment

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

Does it implement the EventEmitter type used in CoreApi?

Copy link
Member

Choose a reason for hiding this comment

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

And btw it works if we use an import there

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure exactly what to do here. Without the change, TypeScript complains that the GridApi has properties that the EventEmitter instance doesn't support. Guidance from your end welcome.

Copy link
Member

Choose a reason for hiding this comment

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

Ok we can pair up when you are free. Ping me on slack when it's a good time ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, let's do that tomorrow, for the sake of clarity, this is the current state of affair.

on master the type of the EventEmitter is any, c.f. #479:

Capture d’écran 2020-10-20 à 20 20 45

and once I rewrite the EventEmitter, it fails on:

Capture d’écran 2020-10-20 à 20 12 13

which looks expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any idea? It seems that the previous type was wrong. I can't think of a better alternative.

packages/grid/_modules_/grid/utils/EventEmitter.ts Outdated Show resolved Hide resolved
@@ -12,5 +11,5 @@ export function useApiRef(): ApiRef {
const logger = useLogger('useApiRef');
logger.debug('Initializing grid api with EventEmitter.');

return React.useRef<GridApi>(new EventEmitter());
return React.useRef(new EventEmitter() as GridApi);
Copy link
Member

@dtassone dtassone Oct 27, 2020

Choose a reason for hiding this comment

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

How about that?

Suggested change
return React.useRef(new EventEmitter() as GridApi);
return React.useRef<GridApi>(new EventEmitter() as GridApi);

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds great

@oliviertassinari oliviertassinari merged commit f28bb9c into mui:master Oct 29, 2020
@oliviertassinari oliviertassinari deleted the replace-event-emitter branch October 29, 2020 20:52
dtassone pushed a commit to dtassone/material-ui-x that referenced this pull request Nov 9, 2020
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants