-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
After updating to the latest verion of react-draft-wysiwyg 1.14.4 [ReferenceError: window is not defined] #920
Comments
I'm also seeing this issue. The project uses SSR, if that makes any difference. |
This is the workaround I am using, the only problem is that external links aren't working
|
Found a simpler, ES6 workaround with basic React Hooks while working in Gatsby. First create this Editor: Then add a useState and useEffect hook so that on page load you have a state change. Then conditionally render wherever you use the Editor component. Here's an example: Hope this helps! |
I am also experiencing this issue with a SSR app. My workaround is to just keep it at 1.13.2 until it's resolved. |
thx for the comments , I will probably bump down to 1.13.2 |
This seemed to work import React, { Component } from 'react';
import { EditorState, convertToRaw } from 'draft-js';
import draftToHtml from 'draftjs-to-html';
let Editor = () => null;
class EditorConvertToHTML extends Component {
state = {
ready: false,
editorState: EditorState.createEmpty(),
}
componentDidMount() {
import('react-draft-wysiwyg').then(({ Editor: WSYSIGEditor }) => {
Editor = WSYSIGEditor;
this.setState({ ready: true });
});
}
onEditorStateChange = (editorState) => {
this.setState({
editorState,
});
};
render() {
const { editorState } = this.state;
return (
<div>
<Editor
editorState={editorState}
wrapperClassName="demo-wrapper"
editorClassName="demo-editor"
onEditorStateChange={this.onEditorStateChange}
/>
<textarea
disabled
value={draftToHtml(convertToRaw(editorState.getCurrentContent()))}
/>
</div>
);
}
}
export default EditorConvertToHTML; |
I created a forked version of the npm package, for anyone interested in the Webpack fix from the linked PR above. Think it's working for my use case now https://www.npmjs.com/package/@dvargas92495/react-draft-wysiwyg |
Same here. EDIT: If you are working with Next.js, a viable workaround until this is resolved is to load the component dynamically using const Editor = dynamic(() => import('react-draft-wysiwyg').then(({ Editor }) => Editor), {
ssr: false
});
const draftToMarkdown = dynamic(() => import('draftjs-to-markdown'), { ssr: false }); |
Hi
…On Sun, 25 Jul 2021, 11:13 pm ridhosatriawan, ***@***.***> wrote:
this work for me
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#920 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASPDIJLXQKRJU7PORQ6D35LTZTHEHANCNFSM4KHOHC2Q>
.
|
ReferenceError: window is not defined
at Object. (D:\project\node_modules\react-draft-wysiwyg\dist\react-draft-wysiwyg.js:1:393)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Module.require (internal/modules/cjs/loader.js:848:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.react-draft-wysiwyg (D:\project.next\server\static\development\pages\plans.js:23614:18)
at webpack_require (D:\project.next\server\static\development\pages\plans.js:23:31)
at Module../client/components/containers/ModernScriptEditor/MseRichTextEditor.jsx (D:\project.next\server\static\development\pages\plans.js:4346:78)
at webpack_require (D:\project.next\server\static\development\pages\plans.js:23:31)
at Module../client/components/containers/ModernScriptEditor/ModernScriptEditor.jsx (D:\project.next\server\static\development\pages\plans.js:1103:77)
at webpack_require (D:\project.next\server\static\development\pages\plans.js:23:31)
at Module../client/components/containers/TestCases/TestCasesPage.jsx (D:\project.next\server\static\development\pages\plans.js:8173:96)
at webpack_require (D:\project.next\server\static\development\pages\plans.js:23:31)
at Module../client/components/containers/Plan/PlanDetail.jsx (D:\project.next\server\static\development\pages\plans.js:5322:83)
at webpack_require (D:\project.next\server\static\development\pages\plans.js:23:31)
at Module../client/components/containers/Plan/Plan.jsx (D:\project.next\server\static\development\pages\plans.js:4953:70)
at webpack_require (D:\project.next\server\static\development\pages\plans.js:23:31)
at Module../pages/plans.js (D:\project.next\server\static\development\pages\plans.js:22720:97)
at webpack_require (D:\project.next\server\static\development\pages\plans.js:23:31)
at Object.3 (D:\project.next\server\static\development\pages\plans.js:22810:18)
The text was updated successfully, but these errors were encountered: