[Bug] Warning: useLayoutEffect does nothing on the server

オープン
#381 コメント 10 件 リアクション 7 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
nextjs, react, typescript
領域
frontend, web-dev

調査の方向性

dist/index.modern.mjs:805 の SSR スタックトレースで特定された Map エントリーポイントから開始し、サーバーサイドレンダリングされる NextJS アプリで警告を再現します。そのエントリーポイントをパッケージのソースまでたどります; サーバーサイドレンダリングで useLayoutEffect 警告が出力されなくなり、クライアント側の動作が維持されれば完了です。

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

説明

bug
Description

After installing the react-google-maps package we started getting the following error:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.
2024-05-24T18:49:02.004220106Z     at Map (file:///app/node_modules/@vis.gl/react-google-maps/dist/index.modern.mjs:805:5)

In our own project we used something like this to prevent this warning issue.
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect

This means that it will use useLayoutEffect normally, but during Server Side Rendering it will use useEffect

Steps to Reproduce

Use react-google-maps inside of a NextJS project.

Environment
  • Library version: 0.11.0
  • Google maps version: weekly
  • Browser and Version: Chrome
  • OS: Alpine Linux
Logs
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.
2024-05-24T18:49:02.004220106Z     at Map (file:///app/node_modules/@vis.gl/react-google-maps/dist/index.modern.mjs:805:5)
主要言語
TypeScript
スター
2k
フォーク
195
平均マージ
6時間 26分
マージ済み PR(30日)
3

環境構築

はじめの一歩

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

visgl/react-google-maps のほかの issue

visgl/react-google-maps の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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