Selection toolbar paints stale condition results for one frame

Đang mở Phù hợp với người mới
#1,293 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Bắt đầu từ TextSelectionTooltip, nơi conditionKey được lưu trong state và được làm mới bởi một useEffect không có danh sách dependency; toolbarData được memoize theo [config, conditionKey]. Tính key trong lúc render từ calcConditionKey(config, editor, editorView) rồi xóa state và effect, sau đó kiểm tra thanh công cụ khi chọn văn bản trong WYSIWYG playground với hai đoạn văn. Hoàn thành khi kéo dài vùng chọn qua nhiều đoạn văn mà select loại khối không còn hiển thị trong một frame và không kích hoạt thêm render nào.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

TextSelectionTooltip keeps conditionKey in state and refreshes it in a useEffect without a dependency list, so the key is recomputed after the render that consumed it. toolbarData is memoized on [config, conditionKey], so a render caused by a selection change reuses the cached value and paints the previous set of buttons. The effect then updates the key and a second render paints the correct one.

This shows up on any item with a condition. In the built-in presets those are the block type select and the folding heading button, visible only while the selection stays inside a single paragraph or heading.

Steps:

  1. Open the playground in WYSIWYG mode with two paragraphs.
  2. Select a word inside the first paragraph — the selection toolbar shows the block type select.
  3. Extend the selection into the second paragraph.

The block type select stays visible for one frame after its condition turns false, and every condition flip costs an extra render.

Computing the key during render instead of storing it removes both. Present since #1044.

const [conditionKey, setConditionKey] = useState(() => calcConditionKey(config, editor, editorView));

useEffect(() => {
    const newKey = calcConditionKey(config, editor, editorView);
    if (conditionKey !== newKey) setConditionKey(newKey);
});
Ngôn ngữ chính
TypeScript
Star
428
Fork
48
Merge trung bình
5 ngày 15 giờ
Pull request đã merge (30 ngày)
47

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của gravity-ui/markdown-editor

Tất cả issue của gravity-ui/markdown-editor

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.