-
Notifications
You must be signed in to change notification settings - Fork 52
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
feat(hook/utils): add useIsomorphicLayoutEffect #239
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
93977cb
to
555f571
Compare
Codecov Report
@@ Coverage Diff @@
## main #239 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 22 +1
Lines 846 850 +4
Branches 149 150 +1
=========================================
+ Hits 846 850 +4
|
Deployment failed with the following error:
|
packages/react/src/utils/isServer.ts
Outdated
@@ -0,0 +1,3 @@ | |||
export const isServer = () => { | |||
return typeof window === 'undefined' && typeof global !== 'undefined' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why we should check global. could you explain it please?
No global checking libraries references
- usehoos-ts(check only window): https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect
- react-use(check only window): https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts
- use-isomorphic-layout-effect(check only document): https://github.com/Andarist/use-isomorphic-layout-effect/blob/main/src/index.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, if in node env or server env, this
is global
so this check is semantically equal to typeof window === 'undefined'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can accept semantical cause. but I think if we don't check global in this case, we can get better performance. because we are making most fundamental library so this isClient function will be recalled many time. so I don't want to give up our better performance if we can
I asked this to slash library too. toss/slash#352
Every libraries I checked don't check global to know it is server or client. so I'm very curious your and slash's intention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. this function is called every time in bundler position.
So this expression called inline, rather than export.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chore: delete isClient, isServer function
I delete it !! many thanks 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for accepting my opinion, Let's improve this if we need to improve it after
Deployment failed with the following error:
|
Co-authored-by: Jonghyeon Ko <[email protected]>
I think you need to use corepack with pnpm to meet your pnpm version as packageManager field of package.json. check this doc https://pnpm.io/installation#using-corepack This is also good for install script |
I resolved this issue in 80cec91 please use corepack please. I think we need to add this in CONTRIBUTING.md |
# Overview <!-- A clear and concise description of what this pr is about. --> To distinguish whether it is a client or server environment from a hook or component using `useEffect` I will change the `useEffect` used in places where the client environment and the server environment should be distinguished to the `useIsomorphicLayoutEffect`. ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/slash/blob/main/.github/CONTRIBUTING.md) 2. I added documents and tests. --------- Co-authored-by: Jonghyeon Ko <[email protected]>
# Overview <!-- A clear and concise description of what this pr is about. --> To distinguish whether it is a client or server environment from a hook or component using `useEffect` I will change the `useEffect` used in places where the client environment and the server environment should be distinguished to the `useIsomorphicLayoutEffect`. ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/slash/blob/main/.github/CONTRIBUTING.md) 2. I added documents and tests. ---------
# Overview <!-- A clear and concise description of what this pr is about. --> To distinguish whether it is a client or server environment from a hook or component using `useEffect` I will change the `useEffect` used in places where the client environment and the server environment should be distinguished to the `useIsomorphicLayoutEffect`. ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/slash/blob/main/.github/CONTRIBUTING.md) 2. I added documents and tests. --------- Co-authored-by: Jonghyeon Ko <[email protected]>
Overview
To distinguish whether it is a client or server environment from a hook or component using
useEffect
I will change the
useEffect
used in places where the client environment and the server environment should be distinguished to theuseIsomorphicLayoutEffect
.PR Checklist