Skip to content

Fix(#7442): dynamic loading of codemirror language modes#7443

Merged
martinjagodic merged 5 commits into
decaporg:mainfrom
fgnass:fix/codemirror-esm
Apr 20, 2026
Merged

Fix(#7442): dynamic loading of codemirror language modes#7443
martinjagodic merged 5 commits into
decaporg:mainfrom
fgnass:fix/codemirror-esm

Conversation

@fgnass

@fgnass fgnass commented Mar 28, 2025

Copy link
Copy Markdown
Contributor

Currently, the code widget does not work properly in ESM builds as it calls require() with a dynamic argument, hence the dynamic loading of language modes is broken (see #7442).

This PR fixes this by using a map of loader functions that use dynamic imports with static paths. The map is generated by the same script that creates the languages.json file.

NOTE:
Ideally, we would use https://github.com/codemirror/language-data instead, which internally uses the same approach, but this requires codemirror 6.x which in turn is not supported by react-codemirror2, the wrapper library that is currently used. In the long term switching to https://www.npmjs.com/package/@uiw/react-codemirror would probably make sense, but this would require a huge refactoring.

@fgnass fgnass requested a review from a team as a code owner March 28, 2025 15:05

@yanthomasdev yanthomasdev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks. I agree the suggested approach is better, but given current limitations this will do.

@martinjagodic martinjagodic merged commit 708f6fa into decaporg:main Apr 20, 2026
6 checks passed
sempostma pushed a commit to laikacms/decap-cms that referenced this pull request May 23, 2026
…aporg#7443)

* fix: dynamic codemirror mode imports

* style: format code

* fix: await function and add error handling

---------

Co-authored-by: Martin Jagodic <jagodicmartin1@gmail.com>
Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

3 participants