Repository navigation
feat(ui): migrate the code editors from CodeMirror 5 to CodeMirror 6 - #32069
Conversation
Groundwork for replacing CodeMirror 5 / react-codemirror2. Nothing consumes this yet, so behaviour is unchanged. - Add the @codemirror/* v6 packages and @uiw/react-codemirror. CodeMirror 5 stays installed until SchemaEditor and CodeEditor are switched over. - Pin @codemirror/state and @codemirror/view in resolutions: a second copy of either makes every extension value from the other copy unrecognized at runtime. - getCodeMirrorLanguage maps the existing `mode` prop to a v6 language. CSMode.CLIKE is only ever Java (Language.Java), so it uses the legacy stream parser. CSMode.YAML gets highlighting for the first time — the v5 yaml mode was never imported. - getCodeMirrorExtensions translates the v5 option bag the ~55 call sites already pass, so none of them need to change. `gutters` and `theme` have no v6 equivalent and are ignored. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Replaces CodeMirror 5 / react-codemirror2 with @uiw/react-codemirror in SchemaEditor and CodeEditor. SchemaEditorProps is unchanged, so the ~55 call sites are untouched; the v5 option bag they pass is translated to v6 extensions by getCodeMirrorExtensions. - Extract the shared buffer/extension/value-sync logic into useCodeMirrorEditor so both editors stay thin. - Add an `extensions` prop so a call site can supply completion sources and update listeners instead of reaching into the DOM for the editor instance. - Rename `.CodeMirror*` to the v6 `.cm-*` classes across 12 stylesheets, and restore the 300px default height v5 shipped in its own stylesheet (v6 grows with its content, so every editor without an explicit height would otherwise be unbounded). v6's dotted focus outline is recoloured, not removed — the editor is what keyboard users land on. - Add playwright/utils/codeEditor.ts and route the 12 suites that used `.CodeMirror` selectors through it. Note that v6 only renders visible lines, so line counting is only safe on short documents. - Drop the codemirror, react-codemirror2 and @types/codemirror dependencies. Two behaviour changes, both deliberate: - The buffer is no longer reformatted while typing, which is what moved the caret after an auto-closed bracket. onChange still reports the formatted value, so parents see what they always did, and the `uncontrolled` prop that existed to work around this is now redundant (kept, ignored). - The `readOnly` prop was accepted but never applied under v5. It is honoured now: CodeWidget, markdown code blocks and a disabled ManifestJsonWidget all pass it meaning it. `refreshEditor` is likewise kept and ignored — v6 measures itself when its container becomes visible or resizes. Verified: 1225 jest suites / 14523 tests pass; tsc and eslint clean on every file touched. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
Several read-only viewers pass `readOnly: 'nocursor'`, v5's spelling for read-only *and* not focusable. Typing the option as a boolean made those call sites a type error, and treating the string as a plain truthy readOnly left the caret in an editor that never had one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
An external value that arrived while the editor was focused was stashed and applied on blur, but a subsequent keystroke did not clear it: the parent echoing that keystroke back hit the early return, so blur restored the older value and silently dropped everything typed after it. A fresh edit now discards the pending value. Read-only editors also no longer wait for blur. They stay focusable under CodeMirror 6 (EditorState.readOnly rather than editable: false), and having no edit to protect they would otherwise show stale content until focus left. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
jsx-a11y/control-has-associated-label on the mock's bare input. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A focused editor with no local edit that saw A, then B, then A again kept B queued: the second A matched the synced value and returned early without clearing it, so blur applied the obsolete B and left the editor showing something the parent no longer held. Returning to the synced value now discards the pending update. The added case fails without this change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Conflicts were the three spec files where main's new fixtures import landed beside this branch's codeEditor helper import — both sides kept. main also added two CodeMirror 5 consumers while this branch was open, migrated here to keep the removal of the v5 packages honest: - The SPARQL consoles (Ontology Studio and the standalone console) imported the v5 addons, stylesheet and sparql mode directly. CSMode.SPARQL now maps to the legacy stream parser, like CSMode.CLIKE does for Java, and the side-effect imports are gone. - OntologyStudioQueryConsole.css targeted the v5 DOM; renamed to the v6 classes. The purple PREFIX tint moves from `.CodeMirror-code > div` to `.cm-content > .cm-line`. - OntologyQueryRdf.spec.ts reached through the DOM for the editor instance (`element.CodeMirror.setValue`), which v6 does not expose. It now goes through the shared fillCodeEditor helper. Verified: 1412 jest suites / 16159 tests pass; tsc and eslint clean on the app and playwright projects for every file touched. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two om-playwright/no-positional-locator errors, both introduced by this branch: - The shared helper resolved `.cm-content` with `.first()`. CodeMirror 6 renders one contenteditable per editor, so a scope holding a single editor resolves without picking by position; call sites showing more than one editor pass a narrower scope. - Permission.spec added a `.first()` that the CodeMirror 5 line selector it replaced never had. Also prunes the suppression baseline. Replacing the v5 selectors fixed four entries' worth of positional locators (MetricCustomUnitFlow, CustomProperties, customProperty, metric), and leaving them listed fails the guardrail as stale. Verified: yarn lint:playwright reports 0 errors and no stale suppressions, the generated rule table is current, and the eslint rule unit tests pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@uiw/react-codemirror renders a wrapper div around the editor, so the editor is a direct child of the element carrying `editorClass` but a grandchild of the one carrying `className`. The container height rules were left as `> .cm-editor`, which only covers the first case — CodeMirror 5 needed two selectors for this and I dropped the second (`> .react-codemirror2 > .CodeMirror`) as dead. Consequence: any call site passing the class through `className` lost its height. MetricExpression passes `full-screen-editor-height` that way, so the metric expression editor fell back to the 300px default. Descendant selectors cover both paths with one rule. Verified in a browser: the className and editorClass paths now both resolve to calc(100vh - 250px), and editors without a height rule keep the 300px default. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Ant Design injects a global `::selection { color: #fff }`. CodeMirror 5 never
felt it: its visible text is display-only, with the real selection living in an
offscreen textarea. CodeMirror 6 selects the content element itself, so that
white text landed on v6's pale drawn selection band and the selected line became
unreadable.
Scoped to `.cm-editor`, so the app's selection colour is untouched everywhere
else. `inherit` does not work here — browsers chain ::selection inheritance
through the ancestors' ::selection colour, which is the white being overridden —
so the text colour is pinned to the editor's own token.
Also drops `codemirror` from optimizeDeps.include: it is no longer a direct
dependency, so vite was force-pre-bundling the v6 meta-package alongside the
antlr4 entries, which is how a dev server ends up throwing
`require_Utils is not a function` from an unrelated module.
Verified in a browser against the SPARQL console: selection is dark text on the
pale band, and `body` selection is still white on brand blue.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The corpus test pins the suppression totals exactly, and replacing the CodeMirror 5 selectors took six no-positional-locator suppressions with them (MetricCustomUnitFlow, CustomProperties, customProperty, metric). The baseline was pruned in an earlier commit but this recorded count was not lowered to match, so the test failed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Conflicts, and the two that were not mechanical: - corpus.test.mjs — main's recorded suppression totals, with no-positional-locator lowered 1202 -> 1196 for the six this PR removes. - code-mirror.less / CodeMirror.utils.ts — main added a CodeMirror 5 dark theme while this PR was open. Its chrome rules port to the v6 class names, but v6 generates its own class names for highlighted tokens, so restyling `.cm-keyword` & co. from a `.dark-mode` block cannot work. The hues move into CSS variables consumed by a HighlightStyle, which keeps main's dark-mode colours and serves both themes from one style. Also: main's new OntologyExplorerPage integration test mocked react-codemirror2, which this PR removes — repointed at the v6 wrapper. And the @codemirror/state / view resolutions move from exact pins to `^6`: main's tree now wants 6.7.5, and pinning 6.7.1 split the install into two copies, which is the duplicate-instance failure the pin exists to prevent. Verified: 1574 jest suites / 18171 tests pass, the guardrail rule tests and rule table are current, and eslint reports no errors under playwright/. Co-Authored-By: Claude Opus 5 <[email protected]>
🔄 Playwright impact map auto-refreshedThis PR touched specs or UI source that changed the source→spec routing map. I regenerated What is this file? It is the auto-generated half of Playwright's PR planner. It routes "if source X changes, run specs Y" by walking spec imports and cross-referencing What if I want to regenerate locally instead? Run this before pushing your next change to skip the bot commit: python3 .github/scripts/generate_playwright_impact_map.py
git add .github/playwright/impact-map.generated.json
git commit --amend --no-edit # or a separate commit |
|
| Count | Rule |
|---|---|
| 9 | react-hooks/exhaustive-deps |
All findings
| Location | Rule | Message | |
|---|---|---|---|
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:135:6 |
react-hooks/exhaustive-deps |
React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array. |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:152:6 |
react-hooks/exhaustive-deps |
React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array. |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:399:5 |
react-hooks/exhaustive-deps |
React Hook useCallback has missing dependencies: 'onVisibilityChange', 't', and 'tableId'. Either include them or remove the dependency array. If 'onVisibilityC |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:406:6 |
react-hooks/exhaustive-deps |
React Hook useCallback has missing dependencies: 'onVisibilityChange' and 'updateInitialConfig'. Either include them or remove the dependency array. If 'onVisib |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:413:5 |
react-hooks/exhaustive-deps |
React Hook useCallback has a missing dependency: 'handleStateChange'. Either include it or remove the dependency array. |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:421:5 |
react-hooks/exhaustive-deps |
React Hook useCallback has a missing dependency: 'handleStateChange'. Either include it or remove the dependency array. |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:428:6 |
react-hooks/exhaustive-deps |
React Hook useCallback has a missing dependency: 'handleStateChange'. Either include it or remove the dependency array. |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:453:5 |
react-hooks/exhaustive-deps |
React Hook useCallback has missing dependencies: 'form' and 'handleStateChange'. Either include them or remove the dependency array. |
| 🟡 | src/components/Database/Profiler/TableProfiler/ProfilerSettingsModal/ProfilerSettingsModal.tsx:473:6 |
react-hooks/exhaustive-deps |
React Hook useEffect has a missing dependency: 'fetchProfileConfig'. Either include it or remove the dependency array. |
Fix locally (fast - only checks files changed in this branch):
make ui-checkstyle-changed`@lezer/highlight` belongs after the `@codemirror/*` group, and the named members of the language import sort differently once HighlightStyle joins them. eslint and prettier were both happy; this is the organise-imports step. Co-Authored-By: Claude Opus 5 <[email protected]>
Two faults, both found by measuring the running app rather than the harness: - The syntax hues referenced `--color-purple-300` and friends, which are not defined on the document in the app that mounts these editors. An undefined var makes the whole custom property invalid, so every token lost its colour and dark mode rendered flat grey text. The hues are literals now, with the token as a fallback where one resolves. - The selection band stayed CodeMirror's light lavender. Its own rule is `.<generated>.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground`, which tied on specificity with the shorter selector and won on order, since that stylesheet is injected at runtime. Matching its depth takes the tie. White selected text on the light band was unreadable; the band is dark now. Verified in the browser on both themes: keyword resolves #708 light / #bdb4fe dark, and the selection band is rgb(215,212,240) light / rgb(62,68,86) dark with matching text colours. Co-Authored-By: Claude Opus 5 <[email protected]>
# Conflicts: # openmetadata-ui/src/main/resources/ui/playwright/eslint-rules/tests/corpus.test.mjs
Code Review ✅ Approved 4 closed / 4 findings🟡 Medium risk · Shared editor runtime and dependency migration changes behavior across many UI call sites. Migrates code editors from CodeMirror 5 to CodeMirror 6 while preserving the existing ✅ 4 closed✅ Bug: Blur discards user edits typed after a mid-edit external value
✅ Edge Case: Focused read-only editor won't reflect external value until blur
✅ Quality: Duplicate import from './codeEditor'
✅ Quality: Entire styles tree accidentally duplicated into nested wrong path
OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|



Fixes #27953
What
Replaces CodeMirror 5 /
react-codemirror2with CodeMirror 6 (@uiw/react-codemirror) in the two components that actually construct an editor —SchemaEditorandCodeEditor.SchemaEditorPropsis deliberately unchanged, so none of the ~55 call sites are touched. The CodeMirror 5 option bag they already pass is translated into v6 extensions by a new adapter. That is the whole regression-control story here: a revert is a dependency revert, not a 55-file revert.Commits
feat(ui): add CodeMirror 6 deps and a v5-option adapter— deps,resolutionspin,getCodeMirrorLanguage/getCodeMirrorExtensions, unit tests. Nothing consumes it, so behaviour is unchanged.feat(ui): move the editors to CodeMirror 6— the switch, CSS, Playwright, and removal of the v5 deps.Notable pieces
resolutionspin on@codemirror/stateand@codemirror/view. A second copy of either makes every extension value from the other copy unrecognized at runtime.useCodeMirrorEditorholds the buffer, the extension set, and the rules for when an incomingvaluemay replace what the user is looking at; both editors are now thin.extensionsprop so a call site can pass completion sources and update listeners instead of reaching into the DOM for the editor instance.CSMode.YAMLgets highlighting for the first time — the v5yamlmode was never imported, so YAML has been rendering as plain text.CSMode.CLIKEis only ever Java (Language.Java), so it uses the legacy stream parser.height: 300pxin its own stylesheet; v6 grows with its content, so without this every editor lacking an explicit height would be unbounded. The existing per-call-site overrides still win as they always did.playwright/utils/codeEditor.tscentralises the class names; 12 suites now go through it. Worth knowing for future tests: v6 renders only the visible lines, so counting lines is safe only on short documents.Behaviour changes (both deliberate)
onChangestill reports the formatted value, so parents see exactly what they saw before. Theuncontrolledprop that existed to work around this is now redundant — kept and ignored.readOnlyprop is now honoured. It was accepted but silently dropped under v5. The call sites that pass it —CodeWidget, markdown code blocks, and a disabledManifestJsonWidget— all mean it.refreshEditoris likewise kept and ignored: v6 measures itself when its container becomes visible or changes size.Verification
jest: 1225 suites / 14523 tests pass (2 suites skipped, pre-existing).tscandeslintclean on every file touched.Follow-up
The Collate side (SQL Studio autocomplete rebuilt on
@codemirror/autocompletevia the newextensionsprop, its stylesheets, and its Playwright selectors) lands separately and depends on this merging first.🤖 Generated with Claude Code
The PR appears safe to merge; no outstanding correctness, security, or repository-rule violations were identified.
Findings
Summary
Migrates the shared schema and code editors from CodeMirror 5 to CodeMirror 6 while preserving the existing component API.
useCodeMirrorEditor.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR P[SchemaEditor / CodeEditor props] --> H[useCodeMirrorEditor] H --> A[Legacy option adapter] A --> E[CodeMirror 6 extensions] H --> B[Internal editor buffer] B --> C[CodeMirror 6 editor] C -->|user edit| F[Optional formatting] F --> O[Parent onChange] P -->|external value| S{Focused and editable?} S -->|No| B S -->|Yes| D[Defer until blur] D --> BReviews (15) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."