EnxDev commented on code in PR #44345:
URL: https://github.com/apache/superset/pull/44345#discussion_r4026485297
##########
superset-frontend/src/dashboard/components/gridComponents/Tabs/Tabs.tsx:
##########
@@ -166,6 +166,14 @@ const Tabs = (props: TabsProps): ReactElement => {
const prevTabIds = usePrevious(props.component.children);
useEffect(() => {
+ // A TABS component with no children resolves no tab id, so there is
+ // nothing to activate. Dispatching the unresolved id would register an
+ // `undefined` entry in dashboardState.activeTabs, which JSON.stringify
+ // coerces to `null` when the dashboard state is posted to the permalink
+ // endpoint.
+ if (!activeKey) {
+ return;
+ }
Review Comment:
Verified and confirmed — the guard did leave this gap, though not as a
regression: before the guard, an empty container that gained its first child
registered `undefined` in its place rather than the new tab, so the tab was
already missing from `activeTabs`. The guard made that silent instead of
writing junk.
Root cause is that `activeKey` is seeded from `useState(initActiveKey)`
once. The `initActiveKey` memo does recompute when `children` changes, but
nothing copies it into state: the `dashboardId` effect only fires on dashboard
change, and the `directPathToChild` effect bails out because `nextTabIndex !==
selectedTabIndex` is `0 !== 0` for a container whose `selectedTabIndex` was
clamped to 0 while empty.
Fixed in 472059e by resolving the key when children arrive:
```tsx
useEffect(() => {
const tabId = props.component.children[selectedTabIndex];
if (!activeKey && tabId) {
setActiveKey(tabId);
}
}, [activeKey, props.component.children, selectedTabIndex]);
```
Setting state rather than dispatching directly also fixes the visual half —
the new tab now renders selected, which it did not before.
Covered by `The first child added to an empty TABS component is activated`,
parameterized over view and edit mode. Without the fix it fails with
`setActiveTab.mock.calls` of `[]`; with it, exactly `[[tabId]]` — one
registration, real id, never an `undefined` for `JSON.stringify` to turn into
`null`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]