Skip to content
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

Setting up repl - "Uncaught Error: No CodeMirror editor found" with Vite + React #559

Open
AdrianLThomas opened this issue Mar 7, 2025 · 6 comments

Comments

@AdrianLThomas
Copy link

AdrianLThomas commented Mar 7, 2025

Hello,
No doubt I'm doing something stupid. I was following the guide here to setup the repl component but I keep getting an error in the console:

Uncaught Error: No CodeMirror editor found

Looks like this is intentionally thrown when it can't be found, but I'm not sure why this would be.

Here's an example on a branch here (just run npm i && npm run dev to run).

PGlite is otherwise working for me.

Any ideas?

Thanks!

@AdrianLThomas AdrianLThomas changed the title "Uncaught Error: No CodeMirror editor found" with Vite + React Setting up repl - "Uncaught Error: No CodeMirror editor found" with Vite + React Mar 7, 2025
@ldirer
Copy link

ldirer commented Mar 7, 2025

I ran into the same issue.

This worked for me (I was on 4.23.10):

  "overrides": {
    "@uiw/react-codemirror": "4.23.5"
  },

Not ideal of course :)

Debugging notes:

I tried running the example from the pglite-repl repository and it worked, so I tried to see what was different in my setup and noticed the different lib version.
I think it's due to a change in @uiw/codemirror-react and ref management magic.

This PR seems to have introduced the changes: https://github.com/uiwjs/react-codemirror/pull/717/files

I haven't figured out how this executes exactly and why rcm.current is still null (CodeMirror editor not found) after the component rendered.

@AdrianLThomas
Copy link
Author

Thank you for the fix and insights, it works! Glad it wasn't just me 😄

@copiltembel
Copy link
Collaborator

@ldirer thank you for pointing this out!
@AdrianLThomas OK if we close this?

@AdrianLThomas
Copy link
Author

AdrianLThomas commented Mar 10, 2025

@copiltembel whilst the issue was introduced with react-codemirror are we convinced it will be resolved? Anyone trying to setup the REPL again will likely hit the same issue going forward...?

Either a permanent fix on the code mirror side (I don't know if they identify there's a problem), or at least documentation update on the PGlite side to clarify the workaround

What do you think?

@copiltembel
Copy link
Collaborator

Yes, at the very least we should document this.

@AdrianLThomas
Copy link
Author

I've looked a little more at Repl.tsx. I can reproduce the issue after cloning pglite locally and updating to the latest @uiw/react-codemirror package (the package lock file is still on 4.23.5).

I'm not sure where the issue is occurring yet... but I suspect there's some odd timing issue. Perhaps extractStyles is being called too soon?

The fix that the codemirror team put in place was to remove redundant re-rendering... I suspect the REPL component was taking advantage of that before?

I also see some setTimeout's being used in the repl component... are these a workaround?

copiltembel pushed a commit that referenced this issue Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants