From fb1ebb101dbee00a2a97a413e6e34b061161be91 Mon Sep 17 00:00:00 2001 From: Sarah Norris <1645628+mikachan@users.noreply.github.com> Date: Mon, 25 Sep 2023 12:35:09 +0100 Subject: [PATCH] Try bundling sync package (#54738) * Add sync package to bundled packages list * Wrap outputs in GB plugin check * Add sync to bundled packages in package config * Move plugin checks to core data * Move IS_GUTENBERG_PLUGIN inside __experimentalEnableSync checks --------- Co-authored-by: tellthemachines --- packages/core-data/src/actions.js | 14 ++-- packages/core-data/src/entities.js | 10 ++- packages/core-data/src/resolvers.js | 66 ++++++++++--------- .../lib/util.js | 1 + tools/webpack/packages.js | 1 + 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index 7bae4d218e65e7..3f6c3c12432f58 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -385,12 +385,14 @@ export const editEntityRecord = }, {} ), }; if ( window.__experimentalEnableSync && entityConfig.syncConfig ) { - const objectId = entityConfig.getSyncObjectId( recordId ); - getSyncProvider().update( - entityConfig.syncObjectType + '--edit', - objectId, - edit.edits - ); + if ( process.env.IS_GUTENBERG_PLUGIN ) { + const objectId = entityConfig.getSyncObjectId( recordId ); + getSyncProvider().update( + entityConfig.syncObjectType + '--edit', + objectId, + edit.edits + ); + } } else { if ( ! options.undoIgnore ) { select.getUndoManager().addRecord( diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index 5f728060adc771..fde8cdba93717d 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -401,8 +401,11 @@ export const getOrLoadEntitiesConfig = let configs = select.getEntitiesConfig( kind ); if ( configs && configs.length !== 0 ) { if ( window.__experimentalEnableSync ) { - registerSyncConfigs( configs ); + if ( process.env.IS_GUTENBERG_PLUGIN ) { + registerSyncConfigs( configs ); + } } + return configs; } @@ -415,8 +418,11 @@ export const getOrLoadEntitiesConfig = configs = await loader.loadEntities(); if ( window.__experimentalEnableSync ) { - registerSyncConfigs( configs ); + if ( process.env.IS_GUTENBERG_PLUGIN ) { + registerSyncConfigs( configs ); + } } + dispatch( addEntities( configs ) ); return configs; diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index e01bb12b2e253c..e8cf4e34a120ff 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -79,39 +79,41 @@ export const getEntityRecord = entityConfig.syncConfig && ! query ) { - const objectId = entityConfig.getSyncObjectId( key ); - - // Loads the persisted document. - await getSyncProvider().bootstrap( - entityConfig.syncObjectType, - objectId, - ( record ) => { - dispatch.receiveEntityRecords( - kind, - name, - record, - query - ); - } - ); + if ( process.env.IS_GUTENBERG_PLUGIN ) { + const objectId = entityConfig.getSyncObjectId( key ); + + // Loads the persisted document. + await getSyncProvider().bootstrap( + entityConfig.syncObjectType, + objectId, + ( record ) => { + dispatch.receiveEntityRecords( + kind, + name, + record, + query + ); + } + ); - // Boostraps the edited document as well (and load from peers). - await getSyncProvider().bootstrap( - entityConfig.syncObjectType + '--edit', - objectId, - ( record ) => { - dispatch( { - type: 'EDIT_ENTITY_RECORD', - kind, - name, - recordId: key, - edits: record, - meta: { - undo: undefined, - }, - } ); - } - ); + // Boostraps the edited document as well (and load from peers). + await getSyncProvider().bootstrap( + entityConfig.syncObjectType + '--edit', + objectId, + ( record ) => { + dispatch( { + type: 'EDIT_ENTITY_RECORD', + kind, + name, + recordId: key, + edits: record, + meta: { + undo: undefined, + }, + } ); + } + ); + } } else { if ( query !== undefined && query._fields ) { // If requesting specific fields, items and query association to said diff --git a/packages/dependency-extraction-webpack-plugin/lib/util.js b/packages/dependency-extraction-webpack-plugin/lib/util.js index ac637eb33fbb2f..47dd1a0b7adf4c 100644 --- a/packages/dependency-extraction-webpack-plugin/lib/util.js +++ b/packages/dependency-extraction-webpack-plugin/lib/util.js @@ -3,6 +3,7 @@ const BUNDLED_PACKAGES = [ '@wordpress/icons', '@wordpress/interface', '@wordpress/undo-manager', + '@wordpress/sync', ]; /** diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index 3dc8407d7974b9..3f105886cd2d11 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -28,6 +28,7 @@ const BUNDLED_PACKAGES = [ '@wordpress/icons', '@wordpress/interface', '@wordpress/undo-manager', + '@wordpress/sync', ]; // PHP files in packages that have to be copied during build.