lukasbach / react-complex-tree

Unopinionated Accessible Tree Component with Multi-Select and Drag-And-Drop
https://rct.lukasbach.com
MIT License
944 stars 74 forks source link

Error in useKey when using in NextJS 13 #259

Closed kkga closed 1 year ago

kkga commented 1 year ago

Describe the bug

Getting an error in NextJS 13 (app directory), which looks very similar to this: https://github.com/vercel/next.js/issues/44014.

Like in the linked issue, the document seems to be available to the component as the keyboard shortcuts are working, however I see this output in the terminal console:

error - node_modules/react-complex-tree/lib/cjs/hotkeys/useKey.js (6:0) @ useKey
error - ReferenceError: document is not defined

To Reproduce

I'm finding it hard to reproduce the issue on cloud platforms like codesandbox.

Desktop (please complete the following information):

lukasbach commented 1 year ago

Hey @kkga, thanks for your report! I've just updated the location in code that you mentioned. I can't easily tell if that already fixes the issue, there might be other occurances of a document reference that are in global scope, I'm not too sure, I'm also not sure if what I did completely fixes the issue, so I might have to look into this deeper if this didn't work.

Can you try it again with the latest version (2.1.3) and let me know if there are still issues?

kkga commented 1 year ago

Can you try it again with the latest version (2.1.3) and let me know if there are still issues?

Sure, I can try it out. Seems like 2.1.2 is still the latest version though.

lukasbach commented 1 year ago

Didn't expect you to answer this fast, the pipeline is still running, release should be out in a few minutes 😅

kkga commented 1 year ago

Still hitting the same error, but in a different file now:

error - node_modules/.pnpm/react-complex-tree@2.1.3_react@18.2.0/node_modules/react-complex-tree/lib/cjs/hotkeys/useHotkey.js (19:0) @ useHotkey
error - ReferenceError: document is not defined

Looks like there's 2 references to document in useHotkey.ts:

https://github.com/lukasbach/react-complex-tree/blob/8ec11191245476d20326ebffc1c541af2d069e4d/packages/core/src/hotkeys/useHotkey.ts#L27

https://github.com/lukasbach/react-complex-tree/blob/8ec11191245476d20326ebffc1c541af2d069e4d/packages/core/src/hotkeys/useHotkey.ts#L66

lukasbach commented 1 year ago

Hm okay, I updated a bunch of references of document this time, hopefully this time it doesn't come up again 😅 Can you try again with v2.1.4-alpha.0?

kkga commented 1 year ago

Not seeing the error anymore! Thanks a lot for tackling this 👍🏼

lukasbach commented 1 year ago

Cool, happy to hear and thanks for your patience!