Skip to content

Commit

Permalink
Try bundling sync package (#54738)
Browse files Browse the repository at this point in the history
* 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 <isabel@tellthemachines.com>
  • Loading branch information
mikachan and tellthemachines committed Sep 25, 2023
1 parent 7b6e996 commit fb1ebb1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 40 deletions.
14 changes: 8 additions & 6 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
66 changes: 34 additions & 32 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/dependency-extraction-webpack-plugin/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const BUNDLED_PACKAGES = [
'@wordpress/icons',
'@wordpress/interface',
'@wordpress/undo-manager',
'@wordpress/sync',
];

/**
Expand Down
1 change: 1 addition & 0 deletions tools/webpack/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

1 comment on commit fb1ebb1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in fb1ebb1.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6299206545
📝 Reported issues:

Please sign in to comment.