chore(lint): convert ChartDataProvider and StatefulChart to function components#39456
chore(lint): convert ChartDataProvider and StatefulChart to function components#39456rusackas wants to merge 3 commits intochore/lint-cleanup-function-componentsfrom
Conversation
…components Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Bito Automatic Review Skipped - Branch Excluded |
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [formData, sliceId]); |
There was a problem hiding this comment.
Suggestion: The effect only depends on formData and sliceId, so changes to other fetch-driving props (client, loadDatasource, and request option props) do not trigger a refetch and the component can render stale or incomplete data. Make the effect depend on handleFetchData so it reruns whenever any input used by the fetch logic changes. [logic error]
Severity Level: Major ⚠️
- ❌ loadDatasource toggle ignored; datasource metadata never fetched afterwards.
- ⚠️ Updated request options ignored until IDs also change.| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, [formData, sliceId]); | |
| }, [handleFetchData]); |
Steps of Reproduction ✅
1. In
`superset-frontend/packages/superset-ui-core/test/chart/components/ChartDataProvider.test.tsx:69-82`,
use the existing `setup` helper to render `<ChartDataProvider {...props}
loadDatasource={false} />`, which mounts `ChartDataProvider` from
`src/chart/components/ChartDataProvider.tsx`.
2. After the initial load completes (where `handleFetchData` at
`ChartDataProvider.tsx:109-146` has run once and `mockLoadDatasource` has not been called
because `loadDatasource` was `false`), call `rerender` with the same `formData`/`sliceId`
but `loadDatasource` flipped to `true`, e.g. `rerender(<ChartDataProvider {...props}
loadDatasource />);` inside the same test file.
3. With the current implementation of the effect at `ChartDataProvider.tsx:148-155`
(`useEffect(() => { handleFetchData(); }, [formData, sliceId]);`), React compares the
dependency array, sees that `formData` and `sliceId` are unchanged, and does not re-run
the effect, so `handleFetchData` is not invoked a second time.
4. Because `handleFetchData` is the only place that calls
`chartClient.loadDatasource(...)`, the mocked `mockLoadDatasource` from
`ChartDataProvider.test.tsx:46-56` remains at zero calls even after enabling
`loadDatasource`, and the children never receive a payload with `datasource` populated;
the same behavior occurs if only `formDataRequestOptions`, `datasourceRequestOptions`, or
`queryRequestOptions` change while `formData`/`sliceId` stay the same, so updated fetch
configuration is ignored until IDs change.Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/packages/superset-ui-core/src/chart/components/ChartDataProvider.tsx
**Line:** 154:155
**Comment:**
*Logic Error: The effect only depends on `formData` and `sliceId`, so changes to other fetch-driving props (`client`, `loadDatasource`, and request option props) do not trigger a refetch and the component can render stale or incomplete data. Make the effect depend on `handleFetchData` so it reruns whenever any input used by the fetch logic changes.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.There was a problem hiding this comment.
Pre-existing behavior — the effect dependency list matches the componentDidUpdate semantics from the original class component. Not introduced by this PR.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mports to correct subpaths
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## chore/lint-cleanup-function-components #39456 +/- ##
==========================================================================
- Coverage 64.45% 64.45% -0.01%
==========================================================================
Files 2541 2541
Lines 131662 131654 -8
Branches 30517 30516 -1
==========================================================================
- Hits 84863 84855 -8
Misses 45333 45333
Partials 1466 1466
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
ChartDataProviderandStatefulChartinsuperset-ui-corefrom class components to function componentsPart of the broader class→function component lint cleanup tracked in #37902.
Test plan
Additional information
This is sub-PR 5 of ~10, each targeting
chore/lint-cleanup-function-components.🤖 Generated with Claude Code