Skip to content

Conversation

@gitdallas
Copy link
Contributor

What: Closes #10974

@gitdallas gitdallas requested review from a team, dlabaj and rebeccaalpert and removed request for a team October 14, 2025 15:51
@patternfly-build
Copy link
Collaborator

patternfly-build commented Oct 14, 2025

@gitdallas gitdallas force-pushed the fix/10974-truncate-remove-resizeObserver branch from 0104b5a to ec5e337 Compare October 14, 2025 15:57
@rebeccaalpert
Copy link
Member

rebeccaalpert commented Oct 14, 2025

I'd want to make sure that #11811 still works - noting this down so I don't forget when I come back to review this.

@gitdallas gitdallas force-pushed the fix/10974-truncate-remove-resizeObserver branch from ec5e337 to c047af3 Compare October 14, 2025 16:47
@gitdallas gitdallas changed the title Fix/10974 truncate remove resize observer fix(Truncate): remove resize observer Oct 14, 2025
Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

One issue with this update is that the truncate always has a tabindex of 0 now, when it should really only have that when truncation is actually in effect. Otherwise potentially a lot of static text that isn't truncated will just add an equal amount of unneccessary tab stops to the page.

@gitdallas
Copy link
Contributor Author

@thatblindgeye - looks like i can set isTruncated to false originally and then it seems to work initially, however it won't update if something is resized.. maybe that doesn't matter as much as the performance? because i'm not sure if there is a better way to do this without adding the resizeObserver back

@thatblindgeye
Copy link
Contributor

looks like i can set isTruncated to false originally and then it seems to work initially, however it won't update if something is resized.. maybe that doesn't matter as much as the performance? because i'm not sure if there is a better way to do this without adding the resizeObserver back

I think both are important, though I don't know which (if either) is more important. That's probably a lengthier discussion.

@christianvogt for your use case, are you taking advantage of the resizability of the Truncate component, i.e. whether the content is actually truncated or not can change depending on the viewport width or the content can be of varying length? Or is it pretty reliable that wherever Truncate is being used things will always be Truncated or always not be Truncated (like in a Table column that is always fairly narrow)?

Mainly asking because if it's the latter - and assuming using the maxCharsDisplayed prop isn't viable - I wonder if adding a prop to dictate whether the resize observer is even used would be useful (or debouncing the resize observer).

@christianvogt
Copy link
Contributor

I believe when I created the original issue it was because the component was unmounting and remounting needlessly. Secondary after looking into the code I made the comment about performance and the potential to omit the resize handler. However I didn't consider the tab index case.

For our use case I would still like the text react to container size.

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

After having a quick discussion on Slack, we should update this to keep the resizeObserver, and instead within Truncate import our debounce helper and debounce the handleResize being passed to the getResizeObserver.

Copy link
Contributor

@kmcfaul kmcfaul left a comment

Choose a reason for hiding this comment

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

lgtm with the resizeObserver + debounce

patternfly-build and others added 6 commits October 27, 2025 15:22
 - @patternfly/react-code-editor@6.4.0-prerelease.3
 - @patternfly/react-core@6.4.0-prerelease.3
 - @patternfly/react-docs@7.4.0-prerelease.4
 - @patternfly/react-drag-drop@6.4.0-prerelease.3
 - demo-app-ts@6.0.0-prerelease.163
 - @patternfly/react-table@6.4.0-prerelease.4
 - @patternfly/react-templates@6.4.0-prerelease.3
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
@gitdallas gitdallas force-pushed the fix/10974-truncate-remove-resizeObserver branch from f33716f to e0b9d9d Compare October 28, 2025 15:39
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
@rebeccaalpert
Copy link
Member

Looks like #11811 still works, woo!

});
});

test('Tooltip appears on keyboard focus when external triggerRef is provided (ClipboardCopy regression test)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

);

// Simulate keyboard focus on the external trigger element
fireEvent.focus(mockTriggerRef.current);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we instead import userEvent and utilize that to handle the focusing in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think fireEvent might actually be right here as it's how it would come into the Truncate component, rather than being a full integration test. currently the mockTriggerRef isn't actually rendered as part of the DOM to tab to. could update the .current and check, but now i'm thinking maybe that would be better tested in the clipboardcopy

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah maybe worth trying to see if wew can put this sort of test in ClipboardCopy, though having it live in Truncate could make sense if we were ever to use it in other components in the same way we are in ClipboardCopy.

Not a blocker for me, otherwise things lgtm here

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Above isn't a blocker to me, depending if we'd want to try quickly moving the new test to ClipboardCopy I'm good with things as-is

@gitdallas
Copy link
Contributor Author

@thatblindgeye added a clipboardcopy/truncate integration test.. separate file as i was having trouble not using the mock in the existing 😆


// This test file uses the real Truncate component for integration testing, instead of a mock

describe('ClipboardCopy Truncate Integration', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: It feels weird to wrap a single test in a describe block?

import userEvent from '@testing-library/user-event';
import { ClipboardCopy, ClipboardCopyVariant } from '../ClipboardCopy';

// This test file uses the real Truncate component for integration testing, instead of a mock
Copy link
Collaborator

Choose a reason for hiding this comment

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

It also feels weird in general having this test of ClipboardCopy integration for a change that we're making in Truncate 🤔

That being said I don't dislike this test, and I don't know better way of doing it after some quick poking around, so I won't block over it.

Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
@gitdallas gitdallas force-pushed the fix/10974-truncate-remove-resizeObserver branch from 9d7e85f to a07e291 Compare November 4, 2025 19:12
@thatblindgeye thatblindgeye merged commit 20fb229 into patternfly:main Nov 4, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - [Truncate] - remove resize observer

7 participants