1733778862
2024-12-09 09:34:00
警告: テキストの内容が一致しませんでした。サーバー:「サーバー」 クライアント:「クライアント」
スパンで
アプリで
。
警告: テキストの内容が一致しませんでした。サーバー:「サーバー」 クライアント:「クライアント」
スパンで
アプリで
。
キャッチされないエラー: テキスト コンテンツがサーバーでレンダリングされた HTML と一致しません。
checkForUnmatchedText で
…
ここで、不一致の差分を含む 1 つのメッセージをログに記録します。
– サーバー/クライアント ブランチ if (typeof window !== 'undefined')。 – などの変数入力 Date.now() または Math.random() 呼び出されるたびに変化します。 – ユーザーのロケールでの日付の形式がサーバーと一致しません。 – HTML とともにスナップショットを送信しない外部変更データ。 – HTML タグのネストが無効です。
また、クライアントにブラウザ拡張機能がインストールされており、React がロードされる前に HTML が混乱する場合にも発生する可能性があります。
https://react.dev/link/水和-mismatch
+ クライアント
– サーバ
スロー時水分補給の不一致
…
プロバイダーとして
React 19 では、レンダリングできます。 の代わりにプロバイダーとして :
const ThemeContext = createContext('');
function App({children}) {
return (
ThemeContext value="dark">
{children}
ThemeContext>
);
}
新しいコンテキストプロバイダーが使用できる また、既存のプロバイダーを変換する codemod を公開する予定です。将来のバージョンでは非推奨になります 。
参照のクリーンアップ関数
からのクリーンアップ関数を返すことをサポートするようになりました。 ref コールバック:
input
ref={(ref) => {
return () => {
};
}}
/>
コンポーネントがアンマウントされると、React はコンポーネントから返されたクリーンアップ関数を呼び出します。 ref 折り返し電話。これは、DOM 参照、クラス コンポーネントへの参照、および useImperativeHandle。
ref クリーンアップ関数の導入により、 ref コールバックは TypeScript によって拒否されるようになります。修正は通常、暗黙的な戻り値の使用を停止することです。次に例を示します。
- div ref={current => (instance = current)} />
+ div ref={current => {instance = current}} />
元のコードは、 HTMLDivElement TypeScript はこれがそうなのかどうかを知りません。 想定 クリーンアップ関数にするか、クリーンアップ関数を返したくない場合。
このパターンをコードモッドすることができます no-implicit-ref-callback-return。
useDeferredValue 初期値
を追加しました initialValue というオプション useDeferredValue:
function Search({deferredValue}) {
const value = useDeferredValue(deferredValue, '');
return (
Results query={value} />
);
}
いつ 初期値 提供されており、 useDeferredValue として返します value コンポーネントの最初のレンダリングに使用し、バックグラウンドでの再レンダリングをスケジュールします。 遅延値 戻ってきました。
詳細については、を参照してください。 useDeferredValue。
ドキュメントメタデータのサポート
HTML では、次のようなドキュメントのメタデータ タグが使用されます。 、 、 そして に配置するために予約されています。 section of the document. In React, the component that decides what metadata is appropriate for the app may be very far from the place where you render the or React does not render the at all. In the past, these elements would need to be inserted manually in an effect, or by libraries like react-helmet、サーバーが React アプリケーションをレンダリングするときは慎重な取り扱いが必要でした。
React 19 では、コンポーネント内のドキュメント メタデータ タグをネイティブにレンダリングするためのサポートを追加しています。
function BlogPost({post}) {
return (
article>
h1>{post.title}h1>
title>{post.title}title>
meta name="author" content="Josh" />
link rel="author" href="https://twitter.com/joshcstory/" />
meta name="keywords" content={post.keywords} />
p>
Eee equals em-see-squared...
p>
article>
);
}
React がこのコンポーネントをレンダリングすると、 そして タグを取得し、それらを自動的にホイストします。 section of document. By supporting these metadata tags natively, we’re able to ensure they work with client-only apps, streaming SSR, and Server Components.
詳細については、ドキュメントを参照してください。 、 、 そして 。
スタイルシートのサポート
スタイルシート、両方とも外部リンク () およびインライン (), require careful positioning in the DOM due to style precedence rules. Building a stylesheet capability that allows for composability within components is hard, so users often end up either loading all of their styles far from the components that may depend on them, or they use a style library which encapsulates this complexity.
In React 19, we’re addressing this complexity and providing even deeper integration into Concurrent Rendering on the Client and Streaming Rendering on the Server with built in support for stylesheets. If you tell React the precedence スタイルシートの DOM 内でのスタイルシートの挿入順序を管理し、スタイル ルールに依存するコンテンツを表示する前にスタイルシート (外部の場合) が読み込まれるようにします。
function ComponentOne() {
return (
Suspense fallback="loading...">
link rel="stylesheet" href="foo" precedence="default" />
link rel="stylesheet" href="bar" precedence="high" />
article class="foo-class bar-class">
{...}
article>
Suspense>
)
}
function ComponentTwo() {
return (
div>
p>{...}p>
link rel="stylesheet" href="baz" precedence="default" /> -- will be inserted between foo & bar
div>
)
}
サーバー側のレンダリング中に、React はスタイルシートを , which ensures that the browser will not paint until it has loaded. If the stylesheet is discovered late after we’ve already started streaming, React will ensure that the stylesheet is inserted into the on the client before revealing the content of a Suspense boundary that depends on that stylesheet.
During Client Side Rendering React will wait for newly rendered stylesheets to load before committing the render. If you render this component from multiple places within your application React will only include the stylesheet once in the document:
function App() {
return >
ComponentOne />
...
ComponentOne /> // won't lead to a duplicate stylesheet link in the DOM
>
}
スタイルシートを手動でロードすることに慣れているユーザーにとって、これは、スタイルシートに依存するコンポーネントと並んでスタイルシートを見つける機会となり、より適切なローカル推論が可能になり、実際に依存するスタイルシートのみをロードすることが容易になります。
スタイル ライブラリおよびバンドラーとのスタイル統合でもこの新しい機能を採用できるため、独自のスタイルシートを直接レンダリングしなくても、この機能を使用するようにツールがアップグレードされるため、メリットを得ることができます。
詳細については、ドキュメントを参照してください。 そして 。
非同期スクリプトのサポート
HTML の通常のスクリプト (
#反応 #v19 #反応