editor.view.scrollDOM and editor.view.dom don't match actual rendered DOM in react-codemirror-merge
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu với component CodeMirrorMerge và cách xử lý ref của nó, sau đó so sánh với entry point onCreateEditor của component CodeMirror trong @uiw/react-codemirror. Tái hiện các quan sát đã báo cáo về ref và DOM bằng setup Original và Modified được hiển thị; công việc được xem là hoàn tất khi xác lập được một cách đáng tin cậy để truy cập DOM có thể cuộn của từng editor đã render nhằm đồng bộ cuộn hoặc xử lý sự kiện.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 2.3k
- Fork
- 162
- Merge trung bình
- 2 giờ 41 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của uiwjs/react-codemirror
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
uiwjs/react-codemirror#766 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
uiwjs/react-codemirror#765 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
uiwjs/react-codemirror#772 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
uiwjs/react-codemirror#770 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
uiwjs/react-codemirror#767 · 2 bình luận ·
Tất cả issue của uiwjs/react-codemirror
Issue tương tự
-
area: repo priority: P2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
appandflow/stim#4107 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 60/100
lingdojo/kana-dojo#32859 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
code-quality refactoring
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
github/gh-aw-firewall#10364 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Merge the duplicate kaffir_corn record into sorghumCó thể đã có người làm @Crypto-Shroom đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Crypto-Shroom/Bird-Feed-Calculator#322 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
drizzle-team/drizzle-orm#6552 ·
Maintainer thường phản hồi trong vòng 2 ngày