-
-
Notifications
You must be signed in to change notification settings - Fork 276
[internal] Performance: useEffect optimization & fast hooks
#3367
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-authored-by: romgrk <[email protected]>
Bundle size report
Check out the code infra dashboard for more information about this PR. |
Co-authored-by: romgrk <[email protected]>
useEffect optimization
commit: |
useEffect optimizationuseEffect optimization & fast hooks
|
@copilot Do the same change as in the original prompt, but for |
…Ref/useCallback usages Co-authored-by: romgrk <[email protected]>
Done in add770e. Created Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Now implement |
Co-authored-by: romgrk <[email protected]>
Implemented in d902e55. Added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Now continue this PR by doing the same changes, but for the |
Co-authored-by: romgrk <[email protected]>
Implemented in dbedbb9. Added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Extract all the |
Co-authored-by: romgrk <[email protected]>
Done in b5fbe0e. Moved Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Now do the same thing for |
Co-authored-by: romgrk <[email protected]>
Done in 6e51e48. Added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Description
Replace React
useEffect,useLayoutEffect,useInsertionEffect,useRef,useCallback, anduseStatewith custom wrappers that perform faster via thefastHooks.tsmodule.Changes
packages/utils/src/fastHooks.ts: AddedcreateUseRef,createUseCallback, andcreateUseStatefunctions using the same batching pattern ascreateUseEffect. Consolidated alldidInitializeflags into a single flag on the rootContexttype. Added support foruseInsertionEffect.packages/utils/src/useEffect.ts: UsescreateUseEffect()from fastHookspackages/utils/src/useInsertionEffect.ts: UsescreateUseEffect('useInsertionEffect')from fastHookspackages/utils/src/useRef.ts: UsescreateUseRef()from fastHookspackages/utils/src/useCallback.ts: UsescreateUseCallback()from fastHookspackages/utils/src/useState.ts: UsescreateUseState()from fastHookspackages/utils/src/useRefWithInit.ts: UsesReact.useRefdirectly to avoid circular dependencypackages/utils/src/: Files now use the wrappers instead of direct React hook callspackages/react/src/: All files migrated to useuseEffect,useRef,useCallback, anduseStatefrom utilsImplementation Details
The
useRef,useCallback,useState, anduseInsertionEffectimplementations follow the same batching pattern asuseEffect:createComponentcontext, refs, callbacks, state, and effects are stored in a context arrayuseCallback, dependencies are compared usingareDepsEqualto determine if the callback should be updateduseState, initial value is computed (supporting both value and function initializers) and stored with its setterdidInitializeflag on the root context for simplified state managementUsage
Follows the same pattern as
useIsoLayoutEffectand other existing hook wrappers.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.