From a89b4f2ff5d4898aae928715bdca513bc42c4fac Mon Sep 17 00:00:00 2001 From: logonoff Date: Thu, 19 Nov 2026 15:22:58 -0500 Subject: [PATCH] fix(Tabs): don't disable accent transition when re-measuring on title/actions change Tab re-measures the current-tab accent whenever the title/actions prop identity changes, and passed `true` to setAccentStyles, which applies pf-m-initializing-accent (accent transition duration 0). React element props get a new identity on every parent render, so with the documented inline usage (title={...}) this effect fires on every render, including every tab switch. On React 18 the effect flushed after the componentDidUpdate accent update had already committed, so the transition ran and the later re-measure was a visual no-op. React 19 flushes pending passive effects before rendering the nested update from componentDidUpdate, so isInitializingAccent lands in the same commit as the new accent position values and the underline jumps instead of animating (fixes #12725). Re-measure without the initializing flag instead. Spurious re-runs become harmless: they queue the same accent values componentDidUpdate already queued, so nothing visually changes. The initial-mount measurement keeps using the flag via componentDidMount, so the underline still appears in place on first render. As a side effect, a genuine title/actions change now animates the accent to its new position, consistent with the pf-m-animate-current design. Assisted-by: Opencode glm-5-3 --- .../react-core/src/components/Tabs/Tab.tsx | 2 +- .../components/Tabs/__tests__/Tabs.test.tsx | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/react-core/src/components/Tabs/Tab.tsx b/packages/react-core/src/components/Tabs/Tab.tsx index a626b1e4a77..0e53035e43e 100644 --- a/packages/react-core/src/components/Tabs/Tab.tsx +++ b/packages/react-core/src/components/Tabs/Tab.tsx @@ -129,7 +129,7 @@ const TabBase: React.FunctionComponent = ({ ); useEffect(() => { - setAccentStyles(true); + setAccentStyles(); }, [title, actions]); return ( diff --git a/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx b/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx index 3aa1d847bd4..f643e69cdcc 100644 --- a/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx +++ b/packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, act } from '@testing-library/react'; +import { render, screen, act, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { Tabs, TabsProps } from '../Tabs'; import styles from '@patternfly/react-styles/css/components/Tabs/tabs'; @@ -1006,3 +1006,34 @@ test('should not render tablist aria-label or aria-labelledby when neither is pr expect(asFragment()).toMatchSnapshot(); }); + +test(`Does not render with class ${styles.modifiers.initializingAccent} when a controlled tab is selected`, async () => { + const user = userEvent.setup(); + const ControlledTabs = () => { + const [activeKey, setActiveKey] = useState(0); + + return ( + setActiveKey(eventKey)}> + Tab item 1} /> + Tab item 2} /> + + ); + }; + + render(); + + // Wait for the initial mount accent measurement to settle. + await waitFor(() => expect(screen.getByRole('region')).not.toHaveClass(styles.modifiers.initializingAccent)); + + // The initializing class is removed by a 0ms timeout, so track whether it + // ever transiently appears while selecting a tab with inline title elements. + const classLog: string[] = []; + const tabsRoot = screen.getByRole('region'); + const observer = new MutationObserver(() => classLog.push(tabsRoot.className)); + observer.observe(tabsRoot, { attributes: true, attributeFilter: ['class'] }); + + await user.click(screen.getByRole('tab', { name: 'Tab item 2' })); + + observer.disconnect(); + expect(classLog.some((className) => className.includes(styles.modifiers.initializingAccent))).toBe(false); +});