react-dropzone: document is not defined
Do you want to request a feature or report a bug?
- [ x] I found a bug
- I want to propose a feature
What is the current behavior? Version 10.0.0 cause a document undefined error with server side rendering.
If the current behavior is a bug, please provide the steps to reproduce.
- Enable application with SSR
- Use react-dropzone
What is the expected behavior? no undefined error
Please mention other relevant information such as the browser version, Operating System and react-dropzone version.
Most likely caused from changing /src/utils/index.js
from
export const supportMultiple =
typeof document !== 'undefined' && document && document.createElement
? 'multiple' in document.createElement('input')
: true
to
export const supportMultiple = 'multiple' in document.createElement('input')
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 17
- Comments: 19
Commits related to this issue
- fix: check if document exists and fix #775 — committed to rolandjitsu/react-dropzone by deleted user 5 years ago
- fix: check if document exists and fix #775 — committed to rolandjitsu/react-dropzone by deleted user 5 years ago
- fix: check if document exists and fix #775 — committed to rolandjitsu/react-dropzone by deleted user 5 years ago
- fix: check if document exists and fix #775 — committed to rolandjitsu/react-dropzone by deleted user 5 years ago
@Chris533 , it helps me, thx. @Dakkers try this:
๐ This issue has been resolved in version 10.0.4 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐
Just change
export const supportMultiple = 'multiple' in document.createElement('input')to
export const supportMultiple = 'multiple' in React.createElement('input')and the problem should be solved. In case you donโt want to import React in
utils/index.jsjust movesupportMultipletosrc/index.jssince it is just used thereThanks, I user this finger out.
useEffectsare run after a component is mounted, which is safe for SSR however, the code above gets parsed by the browser on the page load and thatโs the cause of the error. Adding a guard clause that checks for DOM would solve the problem.This is the cause of the issue:
Happy to make a PR
https://github.com/chill5018/next-react-dropzone-demo Here you go @rolandjitsu