Skip to content

fix(sql-lab): prevent crash when host shell lacks useAppDispatch export#40591

Merged
richardfogaca merged 10 commits into
apache:masterfrom
richardfogaca:richardfogaca/fix-sql-lab-dispatch-shim-cycle
Jun 2, 2026
Merged

fix(sql-lab): prevent crash when host shell lacks useAppDispatch export#40591
richardfogaca merged 10 commits into
apache:masterfrom
richardfogaca:richardfogaca/fix-sql-lab-dispatch-shim-cycle

Conversation

@richardfogaca
Copy link
Copy Markdown
Contributor

SUMMARY

Fixes TypeError: o.useAppDispatch is not a function when loading SQL Lab in Module Federation deployments where the host shell shares an older src/views/store singleton.

The SQL Lab remote can be built from a version that expects useAppDispatch, while the host shell may provide a shared store module built before that export existed. This PR routes SQL Lab dispatch usage through a SQL Lab-local shim that falls back to react-redux's useDispatch, so SQL Lab does not crash under that version skew.

The shim imports AppDispatch as a type only and avoids runtime imports from src/views/store. That keeps the fix isolated to SQL Lab without introducing a store bootstrap cycle through store.ts -> persistSqlLabStateEnhancer -> EditorAutoSync -> useAppDispatch.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable.

TESTING INSTRUCTIONS

Manual verification:

  1. Build/run a deployment where the shell provides a src/views/store shared singleton from before useAppDispatch was exported.
  2. Open SQL Lab.
  3. Confirm SQL Lab loads without TypeError: useAppDispatch is not a function.
  4. Confirm dashboard/list pages still complete app bootstrap and do not remain stuck on the loading spinner.

Local checks run:

  • npm run lint -- src/SqlLab/hooks/useAppDispatch.ts
  • git diff --check

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

yousoph and others added 8 commits May 28, 2026 17:42
In Module Federation deployments where the host shell shares
src/views/store as a singleton, a version skew between the shell and
the SQL Lab remote chunk can leave useAppDispatch undefined at runtime.
This causes `TypeError: o.useAppDispatch is not a function` when any
SQL Lab component tries to render.

Root cause: commit 785a08c added useAppDispatch to store.ts and
commit 6842bb3 migrated all SQL Lab components to call it. When a
host shell is built against a version of store.ts that predates
785a08c, the shared store module it provides has no useAppDispatch
export. SQL Lab (built from the newer code) destructures an undefined
value and then immediately tries to call it.

Fix: introduce a thin shim at src/SqlLab/hooks/useAppDispatch.ts that
re-exports useAppDispatch with a nullish-coalesce fallback to
useDispatch. All SQL Lab components now import from the shim instead of
directly from src/views/store. In a correctly up-to-date deployment the
shim is transparent; in a version-skewed deployment SQL Lab continues to
work (with untyped dispatch) rather than crashing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@richardfogaca richardfogaca marked this pull request as ready for review June 1, 2026 22:30
Copilot AI review requested due to automatic review settings June 1, 2026 22:30
@dosubot dosubot Bot added change:frontend Requires changing the frontend sqllab Namespace | Anything related to the SQL Lab labels Jun 1, 2026
Copy link
Copy Markdown
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.

Pull request overview

This PR hardens SQL Lab against Module Federation version skew by decoupling SQL Lab’s dispatch hook usage from the host shell’s shared src/views/store singleton. It introduces a SQL Lab–local useAppDispatch shim that falls back to react-redux’s useDispatch, preventing a runtime crash when the host store module is older and lacks the useAppDispatch export.

Changes:

  • Added src/SqlLab/hooks/useAppDispatch.ts to provide a SQL Lab–local useAppDispatch implementation without runtime imports from src/views/store.
  • Updated SQL Lab components to import useAppDispatch from the new shim instead of src/views/store.
  • Left existing selector usage (useAppSelector) unchanged where needed.

Reviewed changes

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

Show a summary per file
File Description
superset-frontend/src/SqlLab/hooks/useAppDispatch.ts Adds SQL Lab-local dispatch hook shim using react-redux useDispatch with AppDispatch as a type-only import.
superset-frontend/src/SqlLab/components/TablePreview/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/TableExploreTree/useTreeData.ts Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/TableExploreTree/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/TableElement/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/SqlEditorTopBar/useDatabaseSelector.ts Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/SqlEditorTabHeader/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/SqlEditor/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/SouthPane/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx Switches only useAppDispatch to SQL Lab-local shim (keeps useAppSelector from store).
superset-frontend/src/SqlLab/components/ResultSet/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/QueryTable/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/QueryAutoRefresh/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/PopEditorTab/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/ExploreCtasResultsButton/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/EditorWrapper/useKeywords.ts Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx Switches useAppDispatch import to SQL Lab-local shim.
superset-frontend/src/SqlLab/components/EditorAutoSync/index.tsx Switches useAppDispatch import to SQL Lab-local shim.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.94%. Comparing base (97be689) to head (4588ed9).
⚠️ Report is 32 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40591      +/-   ##
==========================================
- Coverage   63.94%   63.94%   -0.01%     
==========================================
  Files        2658     2660       +2     
  Lines      143011   143008       -3     
  Branches    32866    32866              
==========================================
- Hits        91454    91451       -3     
  Misses      49994    49994              
  Partials     1563     1563              
Flag Coverage Δ
javascript 67.37% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Jun 2, 2026

Code Review Agent Run #d5e2a2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 20 · Commit Range: 69cc9e2..0cc8571
    • superset-frontend/src/SqlLab/components/EditorAutoSync/index.tsx
    • superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx
    • superset-frontend/src/SqlLab/components/EditorWrapper/useKeywords.ts
    • superset-frontend/src/SqlLab/components/ExploreCtasResultsButton/index.tsx
    • superset-frontend/src/SqlLab/components/PopEditorTab/index.tsx
    • superset-frontend/src/SqlLab/components/QueryAutoRefresh/index.tsx
    • superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx
    • superset-frontend/src/SqlLab/components/QueryTable/index.tsx
    • superset-frontend/src/SqlLab/components/ResultSet/index.tsx
    • superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx
    • superset-frontend/src/SqlLab/components/SouthPane/index.tsx
    • superset-frontend/src/SqlLab/components/SqlEditor/index.tsx
    • superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx
    • superset-frontend/src/SqlLab/components/SqlEditorTabHeader/index.tsx
    • superset-frontend/src/SqlLab/components/SqlEditorTopBar/useDatabaseSelector.ts
    • superset-frontend/src/SqlLab/components/TableElement/index.tsx
    • superset-frontend/src/SqlLab/components/TableExploreTree/index.tsx
    • superset-frontend/src/SqlLab/components/TableExploreTree/useTreeData.ts
    • superset-frontend/src/SqlLab/components/TablePreview/index.tsx
    • superset-frontend/src/SqlLab/hooks/useAppDispatch.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

import { styled } from '@apache-superset/core/theme';
import { extendedDayjs as dayjs } from '@superset-ui/core/utils/dates';
import { useAppDispatch, useAppSelector } from 'src/views/store';
import { useAppSelector } from 'src/views/store';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

useAppSelector still imports from src/views/store, could this also crash the app if shell lacks useAppSelector?

@bito-code-review
Copy link
Copy Markdown
Contributor

The useAppSelector hook is imported from react-redux, not from src/views/store. Therefore, it does not depend on the useAppDispatch migration or the src/views/store file structure. It will continue to function as expected regardless of changes to useAppDispatch imports.

Copy link
Copy Markdown
Contributor

@rebenitez1802 rebenitez1802 left a comment

Choose a reason for hiding this comment

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

Left a comment that is worth checking before merging otherwise, LGTM

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 2, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 9d7cbfc
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a1ecf00eadf69000832e090
😎 Deploy Preview https://deploy-preview-40591--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Jun 2, 2026

Code Review Agent Run #b9d9a9

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 0cc8571..4588ed9
    • superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx
    • superset-frontend/src/SqlLab/hooks/useAppSelector.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@richardfogaca
Copy link
Copy Markdown
Contributor Author

Addressed the SQL Lab concern by routing both useAppDispatch and useAppSelector through SQL Lab-local hooks that avoid runtime imports from src/views/store.

I also live-validated this against a local Superset OSS environment: SQL Lab loads, the SQL editor mounts after adding a tab, and there are no useAppDispatch / useAppSelector runtime errors or React error boundary crashes.

@richardfogaca richardfogaca merged commit 88abd41 into apache:master Jun 2, 2026
62 checks passed
@richardfogaca richardfogaca deleted the richardfogaca/fix-sql-lab-dispatch-shim-cycle branch June 2, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:frontend Requires changing the frontend size/M sqllab Namespace | Anything related to the SQL Lab

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants