Skip to content

Commit 060122d

Browse files
authored
fix: Await configuration before initializing network logging (#243)
Without awaiting the GBKit configuration global, a race condition often led to disabled fetch interception, even though the `enableNetworkLogging` configuration was enabled.
1 parent 55b8b9a commit 060122d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/utils/editor-environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import './editor-styles';
2121
export async function setUpEditorEnvironment() {
2222
try {
2323
setUpGlobalErrorHandlers();
24-
initializeFetchInterceptor();
2524
setBodyClasses();
2625
await awaitGBKitGlobal();
26+
initializeFetchInterceptor();
2727
await configureLocale();
2828
await initializeWordPressGlobals();
2929
await configureApiFetch();

src/utils/editor-environment.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import { initializeWordPressGlobals } from './wordpress-globals.js';
1616
import { configureLocale } from './localization.js';
1717
import { configureApiFetch } from './api-fetch.js';
1818
import { initializeEditor } from './editor.jsx';
19+
import { initializeFetchInterceptor } from './fetch-interceptor.js';
1920

2021
vi.mock( './bridge.js' );
22+
vi.mock( './fetch-interceptor.js' );
2123
vi.mock( './logger.js' );
2224
vi.mock( './editor-styles.js' );
2325
vi.mock( './videopress-bridge.js' );
@@ -55,6 +57,7 @@ describe( 'setUpEditorEnvironment', () => {
5557
configureLocale.mockResolvedValue( undefined );
5658
initializeWordPressGlobals.mockImplementation( () => {} );
5759
configureApiFetch.mockImplementation( () => {} );
60+
initializeFetchInterceptor.mockImplementation( () => {} );
5861
initializeVideoPressAjaxBridge.mockImplementation( () => {} );
5962
initializeEditor.mockImplementation( () => {} );
6063
EditorLoadError.mockReturnValue( '<div>Error</div>' );
@@ -71,6 +74,10 @@ describe( 'setUpEditorEnvironment', () => {
7174
return Promise.resolve();
7275
} );
7376

77+
initializeFetchInterceptor.mockImplementation( () => {
78+
callOrder.push( 'initializeFetchInterceptor' );
79+
} );
80+
7481
configureLocale.mockImplementation( () => {
7582
callOrder.push( 'configureLocale' );
7683
return Promise.resolve();
@@ -96,6 +103,7 @@ describe( 'setUpEditorEnvironment', () => {
96103

97104
expect( callOrder ).toEqual( [
98105
'awaitGBKitGlobal',
106+
'initializeFetchInterceptor',
99107
'configureLocale',
100108
'loadRemainingGlobals',
101109
'configureApiFetch',

0 commit comments

Comments
 (0)