fix: use lazy initializer for useState with function calls#3867
Open
karyanayandi wants to merge 1 commit intoDokploy:canaryfrom
Open
fix: use lazy initializer for useState with function calls#3867karyanayandi wants to merge 1 commit intoDokploy:canaryfrom
karyanayandi wants to merge 1 commit intoDokploy:canaryfrom
Conversation
Calling getTerminalKey() and getDefaultDateRange() directly in useState re-runs them on every render. Wrap in an arrow function so they execute only once during component initialization.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates a couple of React useState initializations to use lazy initializer functions, avoiding re-executing initializer function calls on every render and ensuring they only run during the initial mount.
Changes:
- Wrap
getTerminalKey()in a lazyuseStateinitializer in the terminal modal. - Wrap
getDefaultDateRange()in a lazyuseStateinitializer in the requests dashboard.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/dokploy/components/dashboard/settings/web-server/terminal-modal.tsx | Makes terminalKey state initialization lazy so getTerminalKey() only runs on initial mount. |
| apps/dokploy/components/dashboard/requests/show-requests.tsx | Makes dateRange state initialization lazy so getDefaultDateRange() only runs on initial mount. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR about?
Calling getTerminalKey() and getDefaultDateRange() directly in useState
re-runs them on every render. Wrap in an arrow function so they execute
only once during component initialization.
Checklist
Before submitting this PR, please make sure that:
canarybranch.Greptile Summary
This PR applies the React
useStatelazy initializer pattern to two components, wrapping direct function calls (getTerminalKey()andgetDefaultDateRange()) in arrow functions so they are only executed once during component initialization rather than on every render.terminal-modal.tsx,getTerminalKey()(which callsDate.now()) was being evaluated on every render; it is now wrapped as() => getTerminalKey().show-requests.tsx,getDefaultDateRange()(which createsnew Date()objects) was similarly evaluated on every render; it is now wrapped as() => getDefaultDateRange().Both changes are correct and follow React best practices. The fix prevents unnecessary function evaluations and avoids creating throwaway object allocations on each re-render. No logic changes are introduced — only the initialization timing is corrected.
Confidence Score: 5/5
useStateare idiomatic React; both wrapped functions are side-effect-free (aside fromDate.now(), which is intentional and was already the existing behavior). No new logic is introduced and there is no risk of regression.Last reviewed commit: 43f9f54
(5/5) You can turn off certain types of comments like style here!