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
No support for server-side rendering #27
Comments
Would be happy to have a PR for this. |
Since your dependencies are not built for serverside rendering, it will be pretty challenging. For now, I would recommend users should just use a client-rendered React components if they want to use your lib which is what I did. But, I have made some minor modifications in my fork which should improve performance. Also, this fork is not optimized for a PR. If you want, I can prepare it. |
I just ran into this same issue. One possible solution is to pull in brace in another way separate from you main bundle. The client required javascript anyway, so at least you can render the rest of the page. |
from what I've seen, Ace uses the DOM api directly to create the editor. Wouldn't it be possible to use something like jsdom to simulate a browser environment on the server? |
NextJS offers great support for React.JS server-side rendered applications. They have the dynamic function where it allows you to import client side only. The implementation that I use.
` How to import
|
is there any side effect of using "next/dynamic" ? or it's fine to use that.. |
I have not seen any issues, duly noted that I am following the Next,JS framework guidelines on how to develop. |
Very sad((( |
Very interested in this. We are using Ace and love it but haven't found a way to use it with Gatsby yet. |
@saulflores95 has the right idea in my case the mode and theme had to be dynamically imported as well. But when I did that I don't think those were being imported before the default react ace component was so I didn't see my theme. I had to await the main import before I imported the ace builds theme and mode. This is version 8.0.0.
|
Just as an FYI, my PR does not enable full SSR. It just prevents I've been working on more complete support for SSR, meaning actually generating markup on the server similar to what you would find on the client after Ace loads. This is non-trivial, since Ace does some fairly nasty and convoluted layout calculations on load that will need to be mocked out in jsdom. So getting something that looks like what you'd see client side will probably require passing some of those layout constants. Anyway—this is definitely a step in the right direction. Now that |
Thank you @JohnGrisham, your solution worked for me. I did have to replace the imports with requires however
|
Working partially, mode and theme missing (also tried using
Starting with Google Chrome 87 console outputs this error:
Also noticed 404 status code for this requests: If instead I use this other approach: // code-editor.js
import AceEditor from 'react-ace'
import 'ace-builds/src-noconflict/mode-javascript'
import 'ace-builds/src-noconflict/theme-monokai'
const handleOnChange = () => {
console.log('Changed!')
}
export default function CodeEditor() {
return (
<AceEditor
mode="javascript"
theme="monakai"
onChange={handleOnChange}
name="editor01"
/>
)
}
// hello-world.js
import dynamic from 'next/dynamic'
const CodeEditor = dynamic(
() => import('../../components/code-editor'),
{ ssr: false },
)
export default function HelloWorld() {
return <CodeEditor />
} I get the same error but slightly different 404 errors: |
Was able to prevent that by setting the useWorker option to false <CodeEditor
...
setOptions={{
useWorker: false,
}}
/> |
hi~,i'm use next and react-ace create playground |
Hi guys! I deployed my app on vercel, and my dynamic component, (dynamic Ace Code Editor) not showing up, although on my localhost it is working great, but on the deployed site it is rendered empty. Anyone experienced this strange behaviour, and found a solution for it? (I have followed @saulflores95 idea, with next/dynamic) |
same as @radikris, production build is not rendering it. |
@radikris did you add the ssr:false key? |
same as @radikris , any updates on the production build not rendering? |
It worked and then stopped. Doesn't build because [react-ace (used by elastic UI) can't doesn't support server-side rendering][1] [1]: securingsincity/react-ace#27 (comment)
Worked for me 👍 but had to add
async () => {
const ace = await import('react-ace');
await import('ace-builds/src-noconflict/mode-javascript');
await import('ace-builds/src-noconflict/theme-textmate');
return ace;
}, Also important step, as mentioned above, is to set <Editor
...
setOptions={{
useWorker: false,
}}
/> |
No description provided.
The text was updated successfully, but these errors were encountered: