-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Strict TS typing for useResizeObserver #3859
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bundle Stats — desktop-clientHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller
Unchanged
|
Bundle Stats — loot-coreHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset No files were changed View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller No assets were smaller Unchanged
|
WalkthroughThe pull request introduces modifications to the Possibly related PRs
Suggested labels
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
packages/desktop-client/src/components/budget/BudgetSummaries.tsxOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-eslint-plugin". (The package "eslint-plugin-eslint-plugin" was not found when loaded as a Node module from the directory "/packages/eslint-plugin-actual".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-eslint-plugin" was referenced from the config file in "packages/eslint-plugin-actual/.eslintrc.js". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/hooks/useResizeObserver.ts (1)
6-6
: Consider adding cleanup logic using useEffect.While the typing is correct, consider adding a cleanup effect to properly dispose of the ResizeObserver when the component unmounts.
Here's a suggested implementation:
import { useRef, useCallback } from 'react'; +import { useRef, useCallback, useEffect } from 'react'; export function useResizeObserver<T extends Element>( func: (contentRect: DOMRectReadOnly) => void, ): (el: T) => void { const observer = useRef<ResizeObserver | undefined>(undefined); + + useEffect(() => { + return () => { + observer.current?.disconnect(); + }; + }, []); if (!observer.current) { observer.current = new ResizeObserver(entries => {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
upcoming-release-notes/3859.md
is excluded by!**/*.md
📒 Files selected for processing (1)
packages/desktop-client/src/hooks/useResizeObserver.ts
(1 hunks)
🔇 Additional comments (3)
packages/desktop-client/src/hooks/useResizeObserver.ts (3)
3-5
: LGTM! Excellent type safety improvement.
The addition of the generic type parameter <T extends Element>
and the corresponding return type (el: T) => void
provides better type safety and enables proper type inference when using this hook with specific element types.
13-17
: LGTM! Well-implemented callback with proper type safety.
The callback implementation is robust with:
- Proper type safety using the generic parameter T
- Defensive programming using optional chaining
- Correct ResizeObserver options
3-5
: Verify existing usage compatibility.
The stricter typing might affect existing usage of this hook. Let's verify all current implementations remain compatible.
✅ Verification successful
All existing usages are compatible with the stricter typing
The verification shows that all current usages of useResizeObserver
in the codebase are compatible with the stricter typing:
MonthPicker.tsx
: Uses it with a callback that receivesrect: DOMRectReadOnly
BudgetSummaries.tsx
: Uses it with a callback that receivesrect: DOMRectReadOnly
Sidebar.tsx
: Uses it with a callback that receivesrect: DOMRectReadOnly
All implementations follow the same pattern and already comply with the stricter type definition.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for all useResizeObserver usage
rg "useResizeObserver" --type ts --type tsx -B 2 -A 2
Length of output: 81
Script:
#!/bin/bash
# Search for all useResizeObserver usage with ripgrep, without file type restrictions
rg "useResizeObserver" -B 2 -A 2
Length of output: 3540
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/BudgetSummaries.tsx (1)
Line range hint
34-38
: LGTM! Consider adding explicit return type for the callback.The addition of
HTMLDivElement
generic type parameter improves type safety by ensuring the resize observer is correctly typed for the div element it observes.Consider adding an explicit return type to the callback for better type documentation:
const containerRef = useResizeObserver<HTMLDivElement>( - useCallback(rect => { + useCallback((rect: DOMRectReadOnly): void => { setWidthState(rect.width); }, []), );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
packages/desktop-client/src/components/budget/BudgetSummaries.tsx
(1 hunks)packages/desktop-client/src/components/sidebar/Sidebar.tsx
(1 hunks)
🔇 Additional comments (1)
packages/desktop-client/src/components/sidebar/Sidebar.tsx (1)
64-66
: LGTM! Type parameter matches the element usage.
The addition of HTMLDivElement
type parameter correctly specifies the type of element being observed, which aligns with its usage for width measurements.
Let's verify that the View component renders as HTMLDivElement:
✅ Verification successful
Type parameter HTMLDivElement
is correctly used
The verification confirms that the View component is implemented as a div element and uses forwardRef<HTMLDivElement, ViewProps>
, making the HTMLDivElement
type parameter in useResizeObserver
perfectly aligned with its usage.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify View component implementation
# Expected: View component should render as a div element
# Search for View component implementation
ast-grep --pattern 'const View = $_'
Length of output: 1502
No description provided.