@@ -214,17 +214,23 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
214214 }
215215
216216 /** STORE **/
217- const reducers = (function createReducers(redux, keplerGl) {
217+ // Pre-seed styleType so the correct basemap fetch starts on the very
218+ // first render, avoiding a flash of the default dark basemap.
219+ // options.config has the versioned envelope shape: { version, config: { mapStyle, ... } }
220+ const savedStyleType = ${ JSON . stringify ( options . config ?. config ?. mapStyle ?. styleType ?? null ) } ;
221+
222+ const reducers = (function createReducers(redux, keplerGl, styleType) {
218223 return redux.combineReducers({
219224 // mount keplerGl reducer
220225 keplerGl: keplerGl.keplerGlReducer.initialState({
221226 uiState: {
222227 readOnly: ${ options . mode === EXPORT_HTML_MAP_MODES . READ } ,
223228 currentModal: null
224- }
229+ },
230+ ...(styleType ? {mapStyle: {styleType}} : {})
225231 })
226232 });
227- }(Redux, KeplerGl));
233+ }(Redux, KeplerGl, savedStyleType ));
228234
229235 const middleWares = (function createMiddlewares(keplerGl) {
230236 return keplerGl.enhanceReduxMiddleware([
@@ -237,11 +243,9 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
237243 }(Redux, middleWares));
238244
239245 const store = (function createStore(redux, enhancers) {
240- const initialState = {};
241-
242246 return redux.createStore(
243247 reducers,
244- initialState ,
248+ {} ,
245249 redux.compose(enhancers)
246250 );
247251 }(Redux, enhancers));
@@ -403,7 +407,11 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
403407 config
404408 );
405409
406- // For some reason Kepler overwrites the config without extra wait time
410+ // The 500 ms delay is a historical workaround for a race where
411+ // keplerGl re-initialises and overwrites config applied synchronously.
412+ // The pre-seeded styleType above removes the basemap flash on first
413+ // render; this dispatch still applies the full saved config (layers,
414+ // viewport, layer groups, etc.) once the component has settled.
407415 window.setTimeout(() => {
408416 store.dispatch(
409417 keplerGl.addDataToMap({
0 commit comments