Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/use-isomorphic-layout-effect-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-simplikit': patch
---

The JSDoc of `useIsomorphicLayoutEffect` now states that the effect never runs on the server and that the hook only avoids the `useLayoutEffect` warning, and no longer claims it supports both client and server environments.
2 changes: 1 addition & 1 deletion packages/plugin/skills/react-simplikit/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Backticks in this table mark catalog entries only.
| [`useIntersectionObserver`](references/useIntersectionObserver.md) | `useIntersectionObserver` is a React hook that detects whether a specific DOM element is visible on the screen. |
| [`useInterval`](references/useInterval.md) | `useInterval` is a React hook that executes a function at a specified interval. |
| [`useIsClient`](references/useIsClient.md) | `useIsClient` is a React hook that returns `true` only in the client-side environment. |
| [`useIsomorphicLayoutEffect`](references/useIsomorphicLayoutEffect.md) | `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering. |
| [`useIsomorphicLayoutEffect`](references/useIsomorphicLayoutEffect.md) | `useIsomorphicLayoutEffect` is a React hook that runs `useLayoutEffect` in the browser without triggering its warning during server-side rendering. |
| [`useKeyboardHeight`](references/useKeyboardHeight.md) | `useKeyboardHeight` is a React hook that tracks the on-screen keyboard height. |
| [`useList`](references/useList.md) | A React hook that manages an array as state. |
| [`useLoading`](references/useLoading.md) | `useLoading` is a React hook that simplifies managing the loading state of a `Promise`. |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# useIsomorphicLayoutEffect

`useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
`useIsomorphicLayoutEffect` is a React hook that runs `useLayoutEffect` in the browser without triggering its warning during server-side rendering.
During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.

This hook runs synchronously after DOM updates but before paint, making it ideal for:
React does not run effects on the server, so the effect only runs in the browser. On the server, this hook is `useEffect`, which React skips.
It exists only to avoid the warning: it does not run anything on the server, and it does not make the server output match the client.

In the browser, it runs synchronously after DOM updates but before paint, making it ideal for:

- Measuring DOM elements after render
- Applying DOM changes before paint
- Preventing UI flashes or layout shifts
- Supporting both client and server environments safely

## Interface

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# useIsomorphicLayoutEffect

`useIsomorphicLayoutEffect` es un Hook de React que proporciona el comportamiento de `useLayoutEffect` sin generar advertencias durante el renderizado en el servidor.
`useIsomorphicLayoutEffect` es un Hook de React que ejecuta `useLayoutEffect` en el navegador sin generar su advertencia durante el renderizado en el servidor.
Durante el SSR, no hay un DOM que puedas medir o modificar de forma síncrona, por lo que React advierte sobre el uso de `useLayoutEffect`.

Este Hook se ejecuta de forma síncrona después de las actualizaciones del DOM, pero antes de que el navegador pinte la pantalla, lo que lo hace ideal para:
React no ejecuta efectos en el servidor, así que el efecto solo se ejecuta en el navegador. En el servidor, este Hook es `useEffect`, que React omite.
Solo existe para evitar la advertencia: no ejecuta nada en el servidor ni hace que la salida del servidor coincida con la del cliente.

En el navegador, se ejecuta de forma síncrona después de las actualizaciones del DOM, pero antes de que el navegador pinte la pantalla, lo que lo hace ideal para:

- Medir elementos del DOM después del renderizado
- Aplicar cambios al DOM antes de que el navegador pinte la pantalla
- Evitar parpadeos en la interfaz o cambios en la disposición de los elementos
- Funcionar de forma segura tanto en el entorno del cliente como en el del servidor

## Interfaz

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# useIsomorphicLayoutEffect

`useIsomorphicLayoutEffect` は、サーバーサイドレンダリング中に警告を発生させずに `useLayoutEffect` と同じ動作を提供する React フックです。
SSR 中には同期的に計測や変更を行う DOM が存在しないため、React は `useLayoutEffect` の使用に対して警告を表示します。
`useIsomorphicLayoutEffect` は、サーバーサイドレンダリング中に警告を発生させずに、ブラウザーで `useLayoutEffect` を実行する React フックです。
SSR 中には同期的に計測や変更ができる DOM が存在しないため、React は `useLayoutEffect` の使用に対して警告を表示します。

このフックは DOM の更新後、ブラウザーが画面を描画する前に同期的に実行されるため、次の用途に適しています。
React はサーバーでエフェクトを実行しないため、エフェクトはブラウザーでのみ実行されます。サーバーでは、このフックは React が実行しない `useEffect` になります。
このフックは警告を避けるためだけに存在します。サーバーで何かを実行することはなく、サーバーの出力をクライアントと一致させることもありません。

ブラウザーでは DOM の更新後、ブラウザーが画面を描画する前に同期的に実行されるため、次の用途に適しています。

- レンダリング後の DOM 要素の計測
- 画面の描画前に DOM の変更を適用
- UI のちらつきやレイアウトのずれの防止
- クライアント環境とサーバー環境の両方への安全な対応

## インターフェース

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# useIsomorphicLayoutEffect

SSR 환경에서는 DOM에 대한 접근이 불가하기 때문에 useLayoutEffect 훅 사용 시 경고가 발생해요. 이 훅은 브라우저에서 SSR 경고를 트리거하지 않고 useLayoutEffect의 동작을 제공해요. DOM 업데이트 후 페인트 전에 동기적으로 실행되며, 다음과 같은 상황에서 효과적으로 사용할 수 있어요.
`useIsomorphicLayoutEffect`는 서버 사이드 렌더링 중에 경고를 일으키지 않고 브라우저에서 `useLayoutEffect`를 실행하는 리액트 훅이에요. SSR 환경에서는 동기적으로 측정하거나 변경할 DOM이 없기 때문에, `useLayoutEffect`를 사용하면 리액트가 경고를 보내요.

리액트는 서버에서 effect를 실행하지 않으므로 effect는 브라우저에서만 실행돼요. 서버에서 이 훅은 `useEffect`이고, 리액트는 이를 실행하지 않아요. 이 훅은 경고를 피하기 위해서만 존재해요. 서버에서 아무것도 실행하지 않으며, 서버 출력을 클라이언트와 맞춰 주지도 않아요.
Comment on lines +3 to +5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`useIsomorphicLayoutEffect`는 서버 사이드 렌더링 중에 경고를 일으키지 않고 브라우저에서 `useLayoutEffect`를 실행하는 리액트 훅이에요. SSR 환경에서는 동기적으로 측정하거나 변경할 DOM이 없기 때문에, `useLayoutEffect`를 사용하면 리액트가 경고를 보내요.
리액트는 서버에서 effect를 실행하지 않으므로 effect는 브라우저에서만 실행돼요. 서버에서 이 훅은 `useEffect`이고, 리액트는 이를 실행하지 않아요. 이 훅은 경고를 피하기 위해서만 존재해요. 서버에서 아무것도 실행하지 않으며, 서버 출력을 클라이언트와 맞춰 주지도 않아요.
`useIsomorphicLayoutEffect`는 서버 사이드 렌더링 중에 경고를 일으키지 않고 브라우저에서 `useLayoutEffect`를 실행하는 리액트 훅이에요. SSR 환경에서는 동기적으로 측정하거나 변경할 DOM이 없기 때문에, `useLayoutEffect`를 사용하면 리액트가 경고를 보내요. (보내요...?! 더 적절한 단어가 있을지 고민이네요 ..) 이 훅은 경고를 피하기 위해서만 존재해요. 서버에서 아무것도 실행하지 않으며, 서버 출력을 클라이언트와 맞춰 주지도 않아요.

이렇게 한 문단으로 적어볼 수도 있을거 같아요 ! 🤔

'서버에서 이 훅은 useEffect이고, 리액트는 이를 실행하지 않아요.' < 요것은 구현에 대한 세부사항을 드러내는 것 아닐까 싶기도 하구요 🤔 🤔 🤔 (물론 간단하고 + 개발자가 알고 사용하면 좋긴 할거라 공감도 돼요 🤔 )

이 부분에 대해서는 어떻게 생각하시나요 ??!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"useLayoutEffect를 사용하면 리액트가 경고를 보내요." -> "useLayoutEffect를 사용하면 경고가 발생해요."

여기서는 굳이 "리액트"가 붙지 않아도 괜찮을거 같아요.
"보내요" 자체가 React시점이기 때문에 조금 어색하게 느껴지는거 아닐까 생각이 듭니다.
문서를 읽는 독자 시점에서는 누가 경고를 보내는지보다 어떤 상황에서 경고가 발생하는지에 대한 여부만 아는 형태면 될거같아요.
조금 더 독자에게 필요한 정보에 초점을 맞추는 형태(?)로 전환하는건 어떨까요 ?


브라우저에서는 DOM 업데이트 후 페인트 전에 동기적으로 실행되므로, 다음과 같은 상황에 적합해요.

- 렌더링 후 DOM 요소 측정
- 페인트 전 DOM 변경 적용
- UI 깜박임 또는 레이아웃 이동 방지
- 클라이언트와 서버 환경 모두 안전하게 지원

## 인터페이스

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# useIsomorphicLayoutEffect

`useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
`useIsomorphicLayoutEffect` is a React hook that runs `useLayoutEffect` in the browser without triggering its warning during server-side rendering.
During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.

This hook runs synchronously after DOM updates but before paint, making it ideal for:
React does not run effects on the server, so the effect only runs in the browser. On the server, this hook is `useEffect`, which React skips.
It exists only to avoid the warning: it does not run anything on the server, and it does not make the server output match the client.

In the browser, it runs synchronously after DOM updates but before paint, making it ideal for:

- Measuring DOM elements after render
- Applying DOM changes before paint
- Preventing UI flashes or layout shifts
- Supporting both client and server environments safely

## Interface

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ const isServer = typeof window === 'undefined';

/**
* @description
* `useIsomorphicLayoutEffect` is a React hook that provides the behavior of `useLayoutEffect` without triggering warnings during server-side rendering.
* `useIsomorphicLayoutEffect` is a React hook that runs `useLayoutEffect` in the browser without triggering its warning during server-side rendering.
* During SSR, there is no DOM to synchronously measure or mutate, so React warns about using `useLayoutEffect`.
*
* This hook runs synchronously after DOM updates but before paint, making it ideal for:
* React does not run effects on the server, so the effect only runs in the browser. On the server, this hook is `useEffect`, which React skips.
* It exists only to avoid the warning: it does not run anything on the server, and it does not make the server output match the client.
*
* In the browser, it runs synchronously after DOM updates but before paint, making it ideal for:
*
* - Measuring DOM elements after render
* - Applying DOM changes before paint
* - Preventing UI flashes or layout shifts
* - Supporting both client and server environments safely
*
* @param {React.EffectCallback} effect - The effect function.
* @param {React.DependencyList} [deps] - An optional array of dependencies.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# useIsomorphicLayoutEffect

`useIsomorphicLayoutEffect` 是一个提供 `useLayoutEffect` 行为、同时避免在服务端渲染期间触发警告的 React Hook。在 SSR 期间,没有 DOM 可供同步测量或变更,因此 React 会对使用 `useLayoutEffect` 发出警告。
`useIsomorphicLayoutEffect` 是一个在浏览器中运行 `useLayoutEffect`、同时避免在服务端渲染期间触发其警告的 React Hook。在 SSR 期间,没有 DOM 可供同步测量或变更,因此 React 会对使用 `useLayoutEffect` 发出警告。

此 Hook 在 DOM 更新之后、绘制之前同步运行,因此非常适合:
React 不会在服务端运行 effect,因此 effect 只会在浏览器中运行。在服务端,此 Hook 就是 `useEffect`,而 React 会跳过它。它的存在只是为了避免警告:它不会在服务端运行任何内容,也不会让服务端输出与客户端保持一致。

在浏览器中,它会在 DOM 更新之后、绘制之前同步运行,因此非常适合:

- 在渲染后测量 DOM 元素
- 在绘制前应用 DOM 变更
- 防止 UI 闪烁或布局偏移
- 同时安全地支持客户端和服务端环境

## 接口

Expand Down Expand Up @@ -41,6 +42,6 @@ function useIsomorphicLayoutEffect(

```tsx
useIsomorphicLayoutEffect(() => {
// Code to be executed during the layout phase on the client side
// 在客户端布局阶段执行的代码
}, [dep1, dep2, ...]);
```
Loading