inovua / reactdatagrid

Empower Your Data with the best React Data Grid there is
https://reactdatagrid.io
Other
3.45k stars 57 forks source link

TypeError: Cannot read properties of null (reading 'appendChild') #357

Open jchristianhall opened 1 year ago

jchristianhall commented 1 year ago

Relevant code or config

https://github.com/inovua/reactdatagrid/blob/master/community-edition/packages/getScrollbarWidth/index.ts#L55

What you did:

I'm importing reactdatagrid into a JS single bundle.

What happened:

When it executes this line before the page is done loading, I get this error.

image

Reproduction repository:

You can see an example of us using our script here. If you change the script to load async, the error does not occur, but I could see there being a race condition around this particular issue.

Problem description:

Because we can't currently code split our app, when we import reactdatagrid and load our script, the app immediately crashes because it's failing on this specific line of code.

Suggested solution:

I think we could probably avoid this issue by either changing the conditional in that file to be if (document && document.body) or using document.addEventListener('DOMContentLoaded') to wait to execute that script until the DOM content has loaded.