Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sfc-gh-bnisco
Copy link
Collaborator

Describe your changes

  • Refactors all usages of useResizeObserver for their widths into a single shared useCalculatedWidth hook
  • Matches the previous behavior of setting width to -1 instead of 0 uniformly across all components that read their own width.
  • Writes unit tests

GitHub Issue Link (if applicable)

Testing Plan

  • Manually tested
  • Added unit tests

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@sfc-gh-bnisco sfc-gh-bnisco added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Mar 10, 2025
values: [width],
elementRef,
} = useResizeObserver(useMemo(() => ["width"], []))
const [width, elementRef] = useCalculatedWidth()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This change is the main fix for widget width flickering. The other useCalculatedWidth updates are primarily for code simplification, ensuring a consistent pattern for width handling across all widgets.

@sfc-gh-bnisco sfc-gh-bnisco marked this pull request as ready for review March 10, 2025 20:53
@sfc-gh-lmasuch sfc-gh-lmasuch requested a review from Copilot March 10, 2025 21:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request fixes width flickering issues in several components by consolidating the width calculations into a single hook, useCalculatedWidth, and standardizing the width value to -1 when a width of 0 is observed. Key changes include:

  • Refactoring usages of useResizeObserver to useCalculatedWidth across components.
  • Ensuring consistent behavior by returning -1 instead of 0 when no width is detected.
  • Adding unit tests for the new useCalculatedWidth hook.

Reviewed Changes

File Description
frontend/lib/src/hooks/useCalculatedWidth.test.ts Added unit tests to verify the behavior of useCalculatedWidth.
frontend/lib/src/hooks/useCalculatedWidth.ts Introduced the new hook that returns the observed width or -1 when width is 0.
frontend/lib/src/components/core/Layout/withCalculatedWidth.tsx Updated to use useCalculatedWidth and removed redundant useMemo usage.
frontend/lib/src/components/elements/Popover/Popover.tsx Replaced useResizeObserver with useCalculatedWidth.
frontend/lib/src/components/widgets/TextArea/TextArea.tsx Updated to use the new hook; removed unnecessary useMemo dependency.
frontend/lib/src/components/widgets/TextInput/TextInput.tsx Updated to use useCalculatedWidth instead of useResizeObserver.
frontend/lib/src/components/widgets/ChatInput/ChatInput.tsx Updated to use the new hook while removing useMemo usage from the hook call.
frontend/lib/src/components/widgets/NumberInput/NumberInput.tsx Updated to use useCalculatedWidth by replacing useResizeObserver and useMemo.
frontend/lib/src/components/shared/ElementFullscreen/ElementFullscreenWrapper.tsx Updated to use useCalculatedWidth instead of useResizeObserver.

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

frontend/lib/src/hooks/useCalculatedWidth.ts:56

  • [nitpick] Consider using an explicit check (e.g. 'return [width === 0 ? -1 : width, elementRef]') instead of relying on the falsy check to ensure that a width value of 0 is correctly mapped to -1. This offers clearer intent and prevents any unexpected behavior with other falsy values.
return [width || -1, elementRef]

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sfc-gh-bnisco sfc-gh-bnisco merged commit 452f8fa into develop Mar 10, 2025
45 checks passed
@sfc-gh-bnisco sfc-gh-bnisco deleted the bnisco/fix-flickering branch March 10, 2025 22:57
kajarenc pushed a commit that referenced this pull request Mar 11, 2025
- Refactors all usages of `useResizeObserver` for their widths into a
single shared `useCalculatedWidth` hook
- Matches the previous behavior of setting width to `-1` instead of `0`
uniformly across all components that read their own width.
- Writes unit tests

- Manually tested
- Added unit tests

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants