YuriyKrasilnikov commented on PR #37367:
URL: https://github.com/apache/superset/pull/37367#issuecomment-3837006116
## Explanation of the fix
### The Problem
Console errors appeared in embedded dashboards:
```
Failed to query feature flag ENABLE_JAVASCRIPT_CONTROLS
```
This happened because `isFeatureEnabled()` was called **before**
`initFeatureFlags()`.
### Why the first attempt didn't work
The initial fix moved `initFeatureFlags()` call before `setupPlugins()`:
```typescript
// This didn't work!
import setupPlugins from 'src/setup/setupPlugins';
initFeatureFlags(bootstrapData.common.feature_flags);
setupPlugins(); // Too late - imports already executed
```
**The issue**: ES modules execute at **import time**, not when functions are
called. By the time we call `initFeatureFlags()`, all imports have already been
processed, including `setupPlugins` which imports DeckGL plugins that call
`isFeatureEnabled()` at module load time.
### The Solution
Create a dedicated module `initEmbedded.ts` that initializes feature flags
**as a side effect of being imported**:
```typescript
// initEmbedded.ts
const bootstrapData = getBootstrapData();
initFeatureFlags(bootstrapData.common.feature_flags); // Executes on import!
export { bootstrapData };
```
Then import it **first** in `index.tsx`:
```typescript
import 'src/public-path';
import { bootstrapData } from './initEmbedded'; // Feature flags now
initialized
import setupPlugins from 'src/setup/setupPlugins'; // Safe to import plugins
```
### Call chain that was failing
```
index.tsx imports setupPlugins
→ setupPlugins imports MainPreset
→ MainPreset imports DeckGLChartPreset
→ DeckGLChartPreset imports Shared_DeckGL.tsx
→ Shared_DeckGL.tsx exports call jsFunctionControl()
→ jsFunctionControl() calls
isFeatureEnabled('ENABLE_JAVASCRIPT_CONTROLS')
→ ERROR: feature flags not initialized yet!
```
Now with `initEmbedded.ts` imported first, feature flags are initialized
before this chain executes.
--
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]