editor.view.scrollDOM and editor.view.dom don't match actual rendered DOM in react-codemirror-merge
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
Comienza por el componente CodeMirrorMerge y su gestión de ref, y compáralo después con el punto de entrada onCreateEditor del componente CodeMirror de @uiw/react-codemirror. Reproduce las observaciones indicadas sobre ref y DOM con la configuración Original y Modified mostrada; se considera terminado cuando se haya establecido una forma fiable de acceder al DOM desplazable de cada editor renderizado para sincronizar el desplazamiento o gestionar eventos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi, thank you for your work on this library!
I'm trying to sync scroll positions between the two panes (Original and Modified) in react-codemirror-merge, so I need access to the actual scrollable DOM elements (scrollDOM) of each editor.
❗ Problem
In the @uiw/react-codemirror package, the CodeMirror component provides an onCreateEditor prop where I can easily access the underlying DOM and editor instance. However, in react-codemirror-merge, the CodeMirrorMerge component does not provide this prop.
So instead, I use a ref to get the editor object. I do receive editor.view.a and editor.view.b, but:
- editor.view.dom, editor.view.a.dom, and editor.view.a.scrollDOM do not match the actual DOM rendered in the browser (as seen in the Elements tab).
- I tried logging them after delays (setTimeout, requestAnimationFrame), but they always point to a stripped-down or intermediate structure that does not include .cm-gutters, .cm-layer, or the actual scrollable container.
🔁 Code Example
<CodeMirrorMerge
ref={editorRef}
orientation="a-b"
>
<Original
value={originalContent?.code}
extensions={extensions}
/>
<Modified
value={newContent?.code}
extensions={[
...extensions,
EditorView.editable.of(false),
EditorState.readOnly.of(true),
]}
/>
</CodeMirrorMerge>
const editorRef = useCallback((editor: CodeMirrorMergeRef) => {
if (!editor?.view) return;
// Test 1
console.log(editor.view.dom, 'editor.view.dom');
console.log(editor.view.b.dom, 'editor.view.b.dom');
// Test 2
document.querySelectorAll(".cm-scroller").forEach((node, index) => {
console.log(`Scroller [${index}]:`, node);
});
// Test 3
setTimeout(() => {
console.log(editor.view.dom, 'editor.view.dom in setTimeout');
console.log(editor.view.b.dom, 'editor.view.b.dom in setTimeout');
}, 3000);
}, []);
🧪 Observations
(for all the tests, they return the same result)
From ref:
<div class="cm-mergeView">
<div class="cm-mergeViewEditors">
<div class="cm-mergeViewEditor"></div> // It is empty
<div class="cm-mergeViewEditor"></div> // It is empty
</div>
</div>
<div class="cm-editor cm-merge-b">
// div.cm-scroller only contains div.cm-content, when actually rendered DOM has div.cm-layer, div.cm-gutters etc.
<div tabindex="-1" class="cm-scroller">
<div class="cm-content">...</div>
</div>
</div>
From browser's Elements tab (actual rendered DOM):
<div class="cm-mergeView">
<div class="cm-mergeViewEditors">
<div class="cm-mergeViewEditor">
<div class="cm-editor cm-merge-a">
<div class="cm-gutters">...</div>
<div class="cm-scroller">...</div>
<div class="cm-layer cm-selectionLayer">...</div>
</div>
</div>
<div class="cm-mergeViewEditor">
<div class="cm-editor cm-merge-b">
...
</div>
</div>
</div>
</div>
✅ Additional Note
When I tested with ReactCodeMirror (not CodeMirrorMerge) using the onCreateEditor callback, I received the correct scrollDOM, and event listeners attached worked as expected.
🙋 Questions
-
Shouldn’t the dom and scrollDOM properties point to the actual scrollable container (with .cm-scroller, .cm-gutters, etc.)? Why is this happening?
-
Is there a better way to reliably access the rendered editor DOM for scroll syncing or event handling?
Thanks again for your great work — I’d love to hear your recommendations or whether this could be addressed in a future release.
- Lenguaje dominante
- TypeScript
- Estrellas
- 2.3k
- Forks
- 162
- Merge medio
- 2 h 41 min
- PR fusionados (30 d)
- 1
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de uiwjs/react-codemirror
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
uiwjs/react-codemirror#766 · 2 comentarios ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
uiwjs/react-codemirror#765 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
uiwjs/react-codemirror#772 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
uiwjs/react-codemirror#770 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
uiwjs/react-codemirror#767 · 2 comentarios ·
Todos los issues de uiwjs/react-codemirror
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
mobile-next/mobile-mcp#526 ·
Los mantenedores suelen responder en 1 día
-
e2e-failure ready-to-code
Dificultad 1/5 Menos de una hora Aptitud para principiantes 73/100
redhat-developer/rhdh-plugin-export-overlays#4470 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
anthropics/anthropic-sdk-typescript#1273 ·
Los mantenedores suelen responder en 10 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
CopilotKit/OpenBot#815 ·
Los mantenedores suelen responder en 1 día