Skip to content

fix(extensions): load extensions async to avoid blocking initial page render#40915

Open
michael-s-molina wants to merge 2 commits into
apache:masterfrom
michael-s-molina:fix-extensions-loading
Open

fix(extensions): load extensions async to avoid blocking initial page render#40915
michael-s-molina wants to merge 2 commits into
apache:masterfrom
michael-s-molina:fix-extensions-loading

Conversation

@michael-s-molina

Copy link
Copy Markdown
Member

SUMMARY

Extension loading was blocking the entire React render tree on every page load. ExtensionsStartup wrapped the full route tree and returned null until initializeExtensions() resolved.

Root cause: ExtensionsStartup awaited extension initialization before rendering children, blocking all routes including pages that have no dependency on extensions (e.g. the welcome page).

Fix — two parts:

  1. ExtensionsStartup: remove blocking gate.
    window.superset setup is synchronous. Extension loading is now fire-and-forget — children render immediately and extensions register in the background.

  2. views and menus registries: make reactive.
    The registries were plain module-level data structures (a Map and an array). Components reading from them on render would miss any extensions that registered after initial paint. Added a listeners set and notify() calls on every registerView/registerMenuItem, and exported useViews(location) / useMenu(location) hooks that subscribe to changes and trigger re-renders when extensions register. Updated all four consumers:

    • StatusBaruseViews
    • SouthPaneuseViews
    • AppLayoutuseViews
    • PanelToolbaruseMenu

    Note: EditorHost already used a reactive pattern (onDidRegisterEditor events) and required no changes.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before After
Page renders blank until all extensions are fetched and loaded (~1–3s) Page renders immediately; extension contributions appear once loaded

TESTING INSTRUCTIONS

  1. Enable the ENABLE_EXTENSIONS feature flag and configure at least one extension with a remoteEntry.
  2. Navigate to the welcome page — confirm it renders immediately without delay.
  3. Navigate to SQL Lab — confirm the page renders immediately.
  4. Wait for extensions to finish loading — confirm extension-contributed panels (SouthPane tabs), status bar items, right sidebar panels, and toolbar menus appear after load without a page refresh.
  5. To reproduce the pre-fix regression, temporarily add a delay in ExtensionsLoader.initializeExtensions() before the API call and confirm extension contributions appear reactively after the delay.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: ENABLE_EXTENSIONS
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot Bot added the change:frontend Requires changing the frontend label Jun 9, 2026
Comment thread superset-frontend/src/extensions/ExtensionsStartup.tsx Outdated
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. Using if (!userId) return; treats a userId of 0 as falsy, causing the initialization logic to be skipped for users with that ID. To resolve this, you should use an explicit check for null or undefined.

Here is the corrected implementation for superset-frontend/src/extensions/ExtensionsStartup.tsx:

    useEffect(() => {
      if (userId === null || userId === undefined) return;

      // Provide the implementations for @apache-superset/core

I have checked the available PR comments and diffs, and there are no other pending review comments to address. Would you like me to perform any other analysis on this PR?

superset-frontend/src/extensions/ExtensionsStartup.tsx

useEffect(() => {
      if (userId === null || userId === undefined) return;

      // Provide the implementations for @apache-superset/core

@bito-code-review bito-code-review Bot left a comment

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.

Code Review Agent Run #23a437

Actionable Suggestions - 1
  • superset-frontend/src/core/menus/index.ts - 1
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset-frontend/src/SqlLab/components/AppLayout/index.tsx - 1
Review Details
  • Files reviewed - 7 · Commit Range: f0ce4e8..f0ce4e8
    • superset-frontend/src/SqlLab/components/AppLayout/index.tsx
    • superset-frontend/src/SqlLab/components/SouthPane/index.tsx
    • superset-frontend/src/SqlLab/components/StatusBar/index.tsx
    • superset-frontend/src/components/PanelToolbar/index.tsx
    • superset-frontend/src/core/menus/index.ts
    • superset-frontend/src/core/views/index.ts
    • superset-frontend/src/extensions/ExtensionsStartup.tsx
  • 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

Comment thread superset-frontend/src/core/menus/index.ts Outdated
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.13%. Comparing base (00e3682) to head (a5a6f1e).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
superset-frontend/src/core/menus/index.ts 94.11% 1 Missing ⚠️
superset-frontend/src/core/views/index.ts 94.11% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #40915   +/-   ##
=======================================
  Coverage   64.12%   64.13%           
=======================================
  Files        2654     2654           
  Lines      143715   143740   +25     
  Branches    33150    33150           
=======================================
+ Hits        92160    92182   +22     
- Misses      49943    49946    +3     
  Partials     1612     1612           
Flag Coverage Δ
javascript 67.88% <95.12%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

- Use `userId == null` instead of `!userId` to handle userId=0 correctly
- Add getServerSnapshot to useSyncExternalStore in useMenu and useViews

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jun 9, 2026

@villebro villebro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice improvement. One question: should the corresponding editor functionality be refactored to be in line with these new hooks?

@bito-code-review bito-code-review Bot left a comment

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.

Code Review Agent Run #d1e15d

Actionable Suggestions - 1
  • superset-frontend/src/core/menus/index.ts - 1
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset-frontend/src/core/views/index.ts - 1
Review Details
  • Files reviewed - 3 · Commit Range: f0ce4e8..a5a6f1e
    • superset-frontend/src/core/menus/index.ts
    • superset-frontend/src/core/views/index.ts
    • superset-frontend/src/extensions/ExtensionsStartup.tsx
  • 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

}
return menuCache.get(location);
},
() => undefined,

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.

useSyncExternalStore hydration mismatch

The added () => undefined as getServerSnapshot causes a hydration mismatch: server returns undefined while the client getSnapshot returns a Menu object. Per React docs, omit this argument when no server value is meaningful, or return the same value as getSnapshot.

Code suggestion
Check the AI-generated fix before applying
 --- a/superset-frontend/src/core/menus/index.ts
 +++ b/superset-frontend/src/core/menus/index.ts
 @@ -95,11 +95,10 @@ export const useMenu = (location: string): Menu | undefined =>
    useSyncExternalStore(
      subscribe,
      () => {
        if (!menuCache.has(location)) {
          menuCache.set(location, getMenu(location));
        }
        return menuCache.get(location);
 -    },
 -    () => undefined,
 -  );
 +    },
 +  );

Code Review Run #d1e15d


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

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/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants