reactjs / reactjs/react.dev

Problem with recommending startTransition in design system event handlers?

オープン
#2,604 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
11

説明

we generally recommend to bake useTransition into the design system components of your app
https://reactjs.org/docs/concurrent-mode-patterns.html#baking-transitions-into-the-design-system

 // Button component in design system event handler:

  function handleClick() {
    startTransition(() => {
      onClick();
    });
  }

Couldn't this lead to the problem mentioned later?

Try typing into the input now. Something’s wrong! The input is updating very slowly
https://reactjs.org/docs/concurrent-mode-patterns.html#splitting-high-and-low-priority-state

The answer to this problem is to split the state in two parts: a “high priority” part that updates immediately, and a “low priority” part that may wait for a transition.

Solution:

function handleChange(e) {
  const value = e.target.value;
  
  // Outside the transition (urgent)
  setQuery(value);

  startTransition(() => {
    // Inside the transition (may be delayed)
    setResource(fetchTranslation(value));
  });
}

If your design system components wrap all their event handlers in startTransition then how would you make a setState call in your handler run outside of a transition?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

Concurrent Mode Patterns のリンクされたセクションを確認し、トランジションをデザインシステムのコンポーネントに組み込む方法と、高優先度と低優先度の state を分離する方法を調べてください。issue のイベントハンドラーの例を出発点として使用します。完了条件は、デザインシステムのハンドラーがコールバックを startTransition でラップすべきかどうか、および緊急の更新をトランジションの外部に残す方法をドキュメントで明確に説明していることです。

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

評価

技術スタック
javascript, react
領域
documentation
issue の種類
ドキュメント
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

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

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