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
react-codemirror2 - add support for server-side rendering #22
Comments
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
@dorianpula Thank you for opening this up, as well as including a stellar amount of detail! I am honing in on closing #20 which involves shipping the module with type defs. While I've been at it, I've taken the opportunity to re-working a lot of things. I'm planning for a 3.0.0 release which will, in addition to having strong types, ship with a notion of a
I'm a day or so out from wrapping up and I'll let you know when it's available to try out. |
@dorianpula This should now be fixed in 3.0.0. I changed the core API a bit, please check out whats new in 3.0.0 to get up and running. Please let me know if this is resolved! |
@scniro it's definitely not solved, as |
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
@indeyets ah yes I do see that. What a pain. I am implementing the check as suggested, but for typings I need to |
@indeyets @dorianpula Sorry for the unexpected issue. This should now be fixed in 3.0.2. Basically TypeScript requires the import statement just for transpile time type checking, even if you don't want the library! I added a hacky gulp task to just remove the auto-generated Please let me know if resolved? (for real this time) |
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
Closing for now, please re-open should this remain problematic |
@scniro Thanks for the quick replies and the updates! (Sorry for not following up earlier.) I upgraded to the latest version, but I haven't attempted to add any server-side specific code to work around the |
@dorianpula no worries! You should be all set, but please comment back should you experience any troubles |
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
react-codemirror isn't maintained properly, look at JedWatson/react-codemirror#126 Keep react-codemirror as a dependency since it's a peer dependency of react-codemirror2. Don't render CodeMirror at the server-side since SSR isn't supported at all. Look at scniro/react-codemirror2#22 for details.
This appears to still be a problem. I'm using the latest I was able to sloppily work around this like so: import React from 'react';
import PropTypes from 'prop-types';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/xq-light.css';
// Workaround
const { Controlled: CodeMirror } =
(typeof window !== 'undefined' && require('react-codemirror2')) || {};
// Workaround
if (typeof window !== 'undefined') {
require('codemirror/mode/javascript/javascript');
}
const options = {
mode: {
name: 'javascript',
json: true
},
theme: 'xq-light',
lineNumbers: true
};
const CodeEditor = ({ markup, onChange }) => {
const handleChange = (editor, data, value) => {
onChange(value);
};
return (
<CodeMirror value={markup} options={options} onChange={handleChange} />
);
};
CodeEditor.propTypes = {
markup: PropTypes.string.isRequired,
onChange: PropTypes.func
};
CodeEditor.defaultProps = {
onChange: () => {}
};
export default CodeEditor; |
Description
As of
version 2.0.2
, react-codemirror2 breaks server-side rendering, due to the import ofcodemirror
requiring browser-level. A server-side render app needs extensive workaround (such as dynamic imports) or separate server/client components to use react-codemirror2 in an isomorphic app. See an example of an error below.Desired Outcome
Enable react-codemirror2 to handle import of codemirror from a node context as is the case with server-side rendering.
Potential Fixes
window
/navigator
global found.Example Error:
The text was updated successfully, but these errors were encountered: