YuriyKrasilnikov commented on PR #37367:
URL: https://github.com/apache/superset/pull/37367#issuecomment-4060971898
Rebased on latest upstream/master. Did an additional code review and found
room for improvement:
Moved `initFeatureFlags()` from `initEmbedded.ts` into `preamble.ts`, before
the first `await`. Since webpack prepends `preamble.ts` to all entry points
(spa, embedded, menu), feature flags are now initialized synchronously before
any plugin imports that call `isFeatureEnabled()` at module load time. This
eliminates the fragile import-ordering dependency in `index.tsx` — previously,
the fix relied on a comment (`// IMPORTANT: initEmbedded MUST be imported
before setupPlugins!`) to enforce correct order, which could be broken by
refactoring or automated tools without any test catching it.
Simplified `initEmbedded.ts` to only export `bootstrapData` (no more
`initFeatureFlags` call). Added `preamble.test.ts` to verify feature flags are
initialized in preamble. Verified via Playwright: both SPA and embedded entry
points load with zero console errors.
Production code diff: +6/-3 lines in preamble.ts, -11 lines in
initEmbedded.ts, -2 lines in index.tsx.
```mermaid
sequenceDiagram
participant Webpack
participant Preamble as preamble.ts
participant Entry as embedded/index.tsx
participant Plugins as setupPlugins
participant DeckGL as Shared_DeckGL.tsx
Webpack->>Preamble: Prepend to entry point (all bundles)
Preamble->>Preamble: getBootstrapData() (sync)
Preamble->>Preamble: initFeatureFlags() (before await)
Note over Preamble: Feature flags available
Preamble->>Preamble: await fetch(languagePack)
Webpack->>Entry: Load embedded/index.tsx
Entry->>Plugins: import setupPlugins
Plugins->>DeckGL: import Shared_DeckGL
DeckGL->>DeckGL: isFeatureEnabled() at import time
Note over DeckGL: Flags already initialized ✓
```
**Before:** `initFeatureFlags()` was called after `await fetch()` in
preamble — by that point DeckGL had already tried to read flags and got `false`.
**After:** `initFeatureFlags()` moved before the first `await` — flags are
available synchronously for all entry points.
--
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]