-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Server Rendering #51
Comments
Interesting, but hydrating such a rendering into a working editor would be a whole different problem. Being able to do this would be cool, but, I think, too much extra complexity to be justified by that coolness. So yeah, this is probably out of scope. |
The hydration problem can be avoided by clearing out and re-building the DOM once the JS loads, like this (which is how the demo does it): const editorDiv = document.querySelector('#editor');
editorDiv.innerHTML = '';
editorDiv.appendChild(view.dom); It's not as fancy as React hydration by a long shot, but it works. For my use case I think this is perfectly acceptable as a hydration solution. I just had another idea. As an alternative to populating const dom = new JSDOM(html);
const document = dom.window.document;
new EditorView(state, document); If Food for thought! |
It would be interesting to support the use case of server-side rendering of the CodeMirror DOM.
I expect this issue to be closed as out of scope, but check this out - I actually got server rendering working in an experiment.
Here's what I had to do in order to get it to work, using JSDOM (full server file):
It may be interesting and relatively easy to add a
node
orjsdom
entry to the environments detected in browser.ts, then use that to avoid executing code that's not necessary for just constructing the DOM.The text was updated successfully, but these errors were encountered: