Skip to content

refactor(react, react-dom, eslint): rename 'useModernLayoutEffect' to 'useClientLayoutEffect' for clearer semantics #3338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Jun 2, 2025

No description provided.

… 'useClientLayoutEffect' for clearer semantics
Copy link

netlify bot commented Jun 2, 2025

Deploy Preview for vibrant-gates-22c214 ready!

Name Link
🔨 Latest commit 5efb496
🔍 Latest deploy log https://app.netlify.com/projects/vibrant-gates-22c214/deploys/683dc4c11860f60008c1155d
😎 Deploy Preview https://deploy-preview-3338--vibrant-gates-22c214.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@FezVrasta
Copy link
Member

Why?

Copy link

pkg-pr-new bot commented Jun 2, 2025

Open in StackBlitz

@floating-ui/core

npm i https://pkg.pr.new/@floating-ui/core@3338

@floating-ui/dom

npm i https://pkg.pr.new/@floating-ui/dom@3338

@floating-ui/react

npm i https://pkg.pr.new/@floating-ui/react@3338

@floating-ui/react-dom

npm i https://pkg.pr.new/@floating-ui/react-dom@3338

@floating-ui/react-native

npm i https://pkg.pr.new/@floating-ui/react-native@3338

@floating-ui/utils

npm i https://pkg.pr.new/@floating-ui/utils@3338

@floating-ui/vue

npm i https://pkg.pr.new/@floating-ui/vue@3338

commit: 5efb496

@sukvvon
Copy link
Contributor Author

sukvvon commented Jun 2, 2025

@FezVrasta

The previous name, useModernLayoutEffect, felt a bit abstract and may not have clearly conveyed the hook’s behavior.
Since the hook only runs on the client and no-ops during SSR, i felt that useClientLayoutEffect would better reflect its intent.

I believe this change improves readability and maintainability, and aligns more closely with naming conventions in SSR-aware libraries — but of course, open to feedback if there’s a better alternative.

@FezVrasta
Copy link
Member

Ok thanks, makes sense to me. I'll let @atomiks have the last word though.

@atomiks
Copy link
Collaborator

atomiks commented Jun 2, 2025

The ‘Client’ is redundant since useLayoutEffect is already client-only

The only reason this util exists is because in React 17 and 18, it warns when useLayoutEffect is used in a server pre-rendered component, but this was removed in 19 (this is why it has ‘Modern’).

The token exists to disambiguate from React’s native useLayoutEffect, but it's the exact same thing while preventing the warning in older versions.

A correct name is useLayoutEffectWithoutWarningInOlderReacts but it's way too long of course

@sukvvon
Copy link
Contributor Author

sukvvon commented Jun 3, 2025

@atomiks

I appreciate the detailed explanation and historical context, especially that this hook exists to avoid warnings in React 17 and 18, and that the name useModernLayoutEffect was introduced to reflect React 19 and above (“modern” React).

I also understand that since useLayoutEffect is inherently client-only, the term “Client” might seem redundant, and that useModernLayoutEffect could be reasonable given this hook’s purpose to suppress warnings in earlier React versions.

However, I believe that useClientLayoutEffect might offer a clearer and more maintainable name for the following reasons:

  • While useLayoutEffect is client-only by nature, this fact may not always be immediately obvious to all developers, especially those new to or unfamiliar with SSR. Including “Client” explicitly could help indicate the hook’s execution environment, which may reduce confusion and lower the learning curve.
  • The term “Modern” is somewhat relative and might become ambiguous over time — what is “modern” today could be considered outdated tomorrow. In contrast, “Client” tends to convey the intended meaning more consistently regardless of React version.
  • Although the hook’s original purpose (to prevent warnings in older React versions) remains the same, naming it based on its behavior could help future-proof the codebase.
  • Of course, useLayoutEffectWithoutWarningInOlderReacts would be the most precise name but is impractically long. useClientLayoutEffect seems to strike a reasonable balance by being concise yet sufficiently descriptive.

In conclusion, while “Client” may technically seem redundant, including it might provide greater clarity and maintainability, especially in an open-source environment with contributors of varied experience levels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy