Selection toolbar paints stale condition results for one frame

オープン 初心者向け
#1,293 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
react, typescript
領域
frontend

調査の方向性

TextSelectionTooltip から始めてください。ここでは conditionKey が state に保存され、依存配列のない useEffect で更新されています。toolbarData は [config, conditionKey] でメモ化されています。calcConditionKey(config, editor, editorView) を使ってレンダー中にキーを計算し、state と effect を削除してください。その後、2つの段落がある WYSIWYG playground で選択ツールバーを確認してください。段落をまたいで選択を広げたときにブロックタイプの select が1フレーム表示されたままにならず、余分な再レンダーも発生しなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

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);
});
主要言語
TypeScript
スター
428
フォーク
48
平均マージ
5日 15時間
マージ済み PR(30日)
47

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

gravity-ui/markdown-editor のほかの issue

gravity-ui/markdown-editor の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。