Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions assets/dev/js/editor/editor-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,15 +1137,16 @@ export default class EditorBase extends Marionette.Application {
}

requestWidgetsConfig() {
const excludeWidgets = {};
const run = () => {
const excludeWidgets = {};

jQuery.each( this.widgetsCache, ( widgetName, widgetConfig ) => {
if ( widgetConfig.controls ) {
excludeWidgets[ widgetName ] = true;
}
} );
jQuery.each( this.widgetsCache, ( widgetName, widgetConfig ) => {
if ( widgetConfig.controls ) {
excludeWidgets[ widgetName ] = true;
}
} );

elementorCommon.ajax.addRequest( 'get_widgets_config', {
elementorCommon.ajax.addRequest( 'get_widgets_config', {
data: {
exclude: excludeWidgets,
},
Expand All @@ -1166,7 +1167,23 @@ export default class EditorBase extends Marionette.Application {
} );
}
},
} );
} );
};

// Defer the schema-prefetch (request body + ~394 KB JSON response parse + the
// per-widget deep-merge in addWidgetsCache) into idle time so it does not race
// with the initial canvas render. The data is only needed when the user opens
// the widget panel to add a new element; in-page widgets already have their
// schemas in the boot config. Falls back to setTimeout where requestIdleCallback
// is unavailable (Safari pre-15.4).
const useDefer = elementorCommon?.config?.experimentalFeatures?.e_memoize_active_controls;
if ( useDefer && 'function' === typeof window.requestIdleCallback ) {
window.requestIdleCallback( run, { timeout: 3000 } );
} else if ( useDefer ) {
setTimeout( run, 0 );
} else {
run();
}
}

async refreshWidgets() {
Expand Down