Repository navigation
fix(strapi): dedupe CodeMirror packages to prevent JSON field crash - #27007
AdityaOP007 wants to merge 11 commits into
Conversation
|
This PR has been added to our community triage board as CPR-452. |
|
Thanks! We've already merged fixes for the issue (fixed in design-system, and bumped in the current |
Thanks for reviewing this PR ,So this would be able to merge or require some new changes |
|
Looks good to me as a defense-in-depth improvement (even with the design-system fix already merged/bumped on develop) — keeping CodeMirror packages deduped at the Strapi bundler layer should help avoid multi-instance issues via plugin chunks/hoisting. One small request before merge: could you please double-check Quick fix if that’s the case: remove the unused import, or wire it into Also FYI: the Vercel check is failing due to authorization requirements, not because of the code changes. AI-assisted comment. |
Sure will do |
…erge EOF Co-authored-by: Cursor <[email protected]>
Thanks for the review! I double-checked the branch and found that the I also ran the requested checks:
Both pass successfully. The only remaining failing check is the Vercel authorization one, which is unrelated to this change. Thanks again for the careful review! |
|
Hi guys, can you release a version with the fix as soon as possible? I need the feature urgently. |
The fix is ready from my side and the review feedback has been addressed. The release schedule is up to the maintainers, but hopefully it can be included in the next release. |
|
Yes, the fix will go out in the next release. In the meantime, you should be able to use the workaround in #26951 |
…ests Derive resolvable CodeMirror packages from admin-closure aliases so optimizeDeps and dedupe stay consistent under pnpm. Pin discovered singletons against optimizeDeps auto-exclude and add vite wiring tests.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
WalkthroughChangesCodeMirror singleton integration
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Hi! Thanks for taking the time to review this. I've addressed the feedback and rerun the requested checks ( |
Align monorepo installs with design-system 2.2.3 pins (6.7.1 / 6.43.0) so admin Vite aliases resolve the same copies as JSONInput at dev time.
I'm reviewing it again now, I've pushed some changes and additional tests. Since the core fix has already been merged, I think we may release without this particular PR so that we have more time to review and make sure it won't cause any additional problems, but we will most likely merge this in the coming days as an added layer of defense against regressions on this issue. |
|
Size Change: -110 kB (-3.26%) Total Size: 3.26 MB 📦 View Changed
ℹ️ View Unchanged
|
Thanks for the update and for taking another look! That makes sense. I completely understand wanting to be extra cautious since the core fix is already in place. I'm happy to wait while you finish the review, and if you spot anything that should be adjusted or improved, just let me know—I'd be happy to make the changes. Thanks again for the detailed review! |
|
got same issue lol |
Hi @innerdvations, hope you're doing well! Just checking in on this PR. I know you mentioned it would likely be merged after some additional review since the core fix had already landed. I've kept the branch up to date with the latest Thanks again for all the time you've put into reviewing this and for the helpful feedback! |
|
@jhoward1994 Has a PR handling some similar things, I'm going to pass this one off to him to make the final decision |
Thanks for the update, I really appreciate it! Sounds good. I'll leave it in @jhoward1994's hands for the final review. If there's anything you'd like me to change or clarify during the review, I'm happy to make the updates. Thanks again for taking the time to review this PR! |
|
Thanks for this! I'm going to close it as we've merged #27064 |
fix(strapi): dedupe CodeMirror packages in admin bundler to fix JSON field crash
Summary
This PR fixes the JSON field editor crash reported in #27003.
After a fresh installation, opening any entry containing a JSON field could throw the following runtime error:
The issue is caused by multiple runtime instances of CodeMirror packages being created during the admin bundling process. While the package manager installs only a single version of
@codemirror/state, Vite can still produce multiple module instances during dependency optimization, causing CodeMirror's internalinstanceofchecks to fail.This PR applies the same singleton resolution strategy already used for React and
@strapi/design-systemto the CodeMirror packages used by the JSON editor.What changed
Added a shared
codemirror-packages.tshelper containing the list of CodeMirror packages that should resolve as singletons.Updated the admin Vite configuration to:
optimizeDepsso they are pre-bundled into a single optimized graphAdded the same aliases to the webpack configuration for compatibility with the legacy bundler.
Added unit tests covering the new helper utilities.
The following packages are now resolved as singletons:
@codemirror/state@codemirror/view@codemirror/language@codemirror/lang-json@codemirror/commands@codemirror/lint@uiw/react-codemirrorWhy this approach?
The JSON editor inside
@strapi/design-systemrelies on CodeMirror 6. Since CodeMirror packages are externalized during the design-system build, Vite may optimize them into separate dependency graphs.When extensions are created from one runtime instance of
@codemirror/stateand validated against another, CodeMirror rejects them because theinstanceofchecks no longer match.By forcing all CodeMirror imports to resolve to a single runtime instance, the editor receives compatible extension objects and the JSON field loads correctly without requiring users to pin dependency versions or add manual Vite configuration.
How to test
Log in to the Strapi Admin.
Open Content Manager.
Open or create an entry containing a JSON field.
Verify that:
Regression checks
Test results
Unit tests
Package resolution
Build output
Admin build
Runtime verification
Related
Fixes CPR-452