Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Improvements 🔥 #207

Merged
merged 66 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
083832d
perf: improved the registeration unstable breakpoints location to opt…
rezaelahidev Nov 12, 2024
fc17605
refactor: improved EditorAssetsProvider after inline scripts
rezaelahidev Nov 12, 2024
a35a224
fix: hook name
rezaelahidev Nov 12, 2024
03eb3ae
perf: optimized performance with detected bottlenecks
rezaelahidev Nov 12, 2024
c110831
refactor: BlockApp, and BlockBase with use cases
rezaelahidev Nov 13, 2024
ebf45f9
compat: Update the border e2e tests
rezaelahidev Nov 13, 2024
9f13489
test: Update the customSelect command
rezaelahidev Nov 13, 2024
9de208d
compat: Update the background-clip e2e tests
rezaelahidev Nov 13, 2024
7ae140e
compat: Update the gap e2e tests
rezaelahidev Nov 13, 2024
c1aa25b
compat: Update the font-family e2e tests
rezaelahidev Nov 13, 2024
8835ff0
compat: Update the font-color e2e tests
rezaelahidev Nov 13, 2024
aec412c
compat: Update the size e2e tests
rezaelahidev Nov 13, 2024
3289bef
compat: Update the blocks category some e2e tests
rezaelahidev Nov 13, 2024
85d2ac8
chore: Update the customized-selector-blocks-cache.json
rezaelahidev Nov 13, 2024
6c19ec2
compat: Update the WordPress tested up to v6.7
rezaelahidev Nov 13, 2024
5d5dbac
compat: Update the font-size e2e tests
rezaelahidev Nov 13, 2024
0acbc41
compat: Update the build category some e2e tests
rezaelahidev Nov 13, 2024
7c26ef7
compat: Update the plugins category some e2e tests
rezaelahidev Nov 13, 2024
e578957
compat: Update the icon block e2e tests
rezaelahidev Nov 13, 2024
d8936d3
test: Update the flex-layout e2e tests
rezaelahidev Nov 13, 2024
f369624
compat: Update the spacing e2e tests
rezaelahidev Nov 13, 2024
8c8c934
compat: Update the media-fit e2e tests
rezaelahidev Nov 13, 2024
4fa8313
test: Update the customSelect command
rezaelahidev Nov 13, 2024
079d064
compat: Update the typography e2e tests
rezaelahidev Nov 13, 2024
c77e2a0
compat: Update the gap e2e tests
rezaelahidev Nov 13, 2024
3a88b65
compat: Update the gap background-color tests
rezaelahidev Nov 13, 2024
0e7f02e
fix: undefined error
rezaelahidev Nov 16, 2024
c7ed89b
feat: sorted combined css declarations in style-engine
rezaelahidev Nov 16, 2024
0259b33
refactor: state-style component of style-engine
rezaelahidev Nov 16, 2024
c14b420
test: updated the e2e tests where use of WP select component
rezaelahidev Nov 16, 2024
a5a802b
compat: Updated the plugins category tests
rezaelahidev Nov 17, 2024
b431ec0
compat: __experimentalSetPreviewDeviceType is deprecated
rezaelahidev Nov 17, 2024
81ea413
test(Group Block Inner Blocks): pass
aliaghdam Nov 17, 2024
931ab76
feat: improve selector to make sure it have higher priority
aliaghdam Nov 17, 2024
9464db2
test: fix assertion
aliaghdam Nov 17, 2024
83e8d9e
test: pass test
aliaghdam Nov 17, 2024
dffe328
test: pass test
aliaghdam Nov 17, 2024
f31dfe2
test: pass test
aliaghdam Nov 17, 2024
6da6d25
test: pass test
aliaghdam Nov 17, 2024
c904d86
test: pass test
aliaghdam Nov 17, 2024
32f8e5a
test: pass test
aliaghdam Nov 17, 2024
a7a6370
test: pass test
aliaghdam Nov 17, 2024
bd59046
test: pass test
aliaghdam Nov 17, 2024
4881679
fix: issue for checking theme gradients cuz it can be undefined
aliaghdam Nov 17, 2024
678dc82
test: pass test
aliaghdam Nov 17, 2024
73e8496
test: pass test
aliaghdam Nov 18, 2024
50a0d7c
test: pass test
aliaghdam Nov 18, 2024
8faad03
test: pass test
aliaghdam Nov 18, 2024
079a317
test: pass test
aliaghdam Nov 18, 2024
187b2e1
test: pass test
aliaghdam Nov 18, 2024
8680513
test: pass test
aliaghdam Nov 18, 2024
9a24ae1
test: pass test
aliaghdam Nov 18, 2024
3e26551
test: pass test
aliaghdam Nov 18, 2024
c8bc705
test: pass test
aliaghdam Nov 18, 2024
1b23602
test: pass test
aliaghdam Nov 18, 2024
19ac8d5
test: pass test
aliaghdam Nov 18, 2024
66cb0c9
test: pass test
aliaghdam Nov 18, 2024
4056a1b
fix(Layout Matrix): style issue
aliaghdam Nov 18, 2024
6e34bb9
test: pass the media-fit e2e tests
rezaelahidev Nov 18, 2024
dfe6d4c
test: pass the style-engine e2e tests
rezaelahidev Nov 18, 2024
3b9e33b
perf: memoized size extensions child components
rezaelahidev Nov 18, 2024
4464104
refactor(Typography extension): merge font style and font weight feat…
aliaghdam Nov 18, 2024
bb90271
feat: improve typo extension settings and features interface
aliaghdam Nov 18, 2024
5bc58be
chore: reformat
aliaghdam Nov 18, 2024
c68f57a
test: fix assertion for new feature refactor
aliaghdam Nov 18, 2024
f738e21
test: fix assertion
aliaghdam Nov 18, 2024
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
2 changes: 1 addition & 1 deletion blockera.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://blockera.ai/products/site-builder/
* Description: The Advanced Mode for Block Editor
* Requires at least: 6.6
* Tested up to: 6.6
* Tested up to: 6.7
* Requires PHP: 7.4
* Author: Blockera AI
* Author URI: https://blockera.ai/about/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function boot(): void {

$skip = false;

add_filter( 'blockera/wordpress/' . $this->getId() . '/inline-script', [ $this, 'createInlineScript' ] );
add_filter( 'blockera/wordpress/' . $this->getId() . '/inline-script/after', [ $this, 'createInlineScript' ] );
add_filter( 'blockera/wordpress/' . $this->getId() . '/handle/inline-script', [ $this, 'getHandler' ] );

} elseif ( ! blockera_telemetry_opt_in_is_off( 'blockera' ) ) {
Expand Down
91 changes: 69 additions & 22 deletions packages/blockera/php/Providers/EditorAssetsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getId(): string {
*
* @return string the handler name.
*/
public function getHandler():string {
public function getHandler(): string {

return '@blockera/blockera';
}
Expand All @@ -41,8 +41,9 @@ public function getHandler():string {
*/
public function boot(): void {

add_filter( 'blockera/wordpress/' . $this->getId() . '/inline-script', [ $this, 'createInlineScript' ] );
add_filter( 'blockera/wordpress/' . $this->getId() . '/handle/inline-script', [ $this, 'getHandler' ] );
add_filter( 'blockera/wordpress/' . $this->getId() . '/inline-script/before', [ $this, 'beforeInlineScript' ] );
add_filter( 'blockera/wordpress/' . $this->getId() . '/inline-script/after', [ $this, 'afterInlineScript' ] );

$this->app->make(
$this->getId(),
Expand All @@ -63,37 +64,90 @@ public function boot(): void {
}

/**
* Create inline script for blockera editor handler.
* @return string
*/
protected function getEditorObject(): string {

$editor_package_file = blockera_core_config( 'app.root_path' ) . 'vendor/blockera/editor/package.json';

if ( ! file_exists( $editor_package_file ) ) {

return '';
}

ob_start();
require $editor_package_file;
$editor_package = json_decode( ob_get_clean(), true );
$editor_version = str_replace( '.', '_', $editor_package['version'] );

return 'blockeraEditor_' . $editor_version;
}

/**
* Create before inline script for blockera editor handler.
*
* @param string $inline_script the previous inline script.
*
* @hooked 'blockera/wordpress/{$this->getId()}/inline-script'
* @hooked 'blockera/wordpress/{$this->getId()}/inline-script/before'
*
* @throws BindingResolutionException BindingResolutionException to handle errors.
* @return string the inline script for initialize blockera some package's configuration.
*/
public function createInlineScript( string $inline_script ): string {
public function beforeInlineScript( string $inline_script ): string {

if ( ! $this->app instanceof Blockera ) {

return $inline_script;
}

$editor_package_file = blockera_core_config( 'app.root_path' ) . 'vendor/blockera/editor/package.json';
$editor_object = $this->getEditorObject();

if ( ! file_exists( $editor_package_file ) ) {
if ( empty( $editor_object ) ) {

return $inline_script;
}

ob_start();
require $editor_package_file;
$editor_package = json_decode( ob_get_clean(), true );
$editor_version = str_replace( '.', '_', $editor_package['version'] );
$editor_object = 'blockeraEditor_' . $editor_version;

$dynamic_value_bootstrapper = $editor_object . '.coreData.unstableBootstrapServerSideDynamicValueDefinitions(' . wp_json_encode( $this->app->getRegisteredValueAddons( 'dynamic-value', false ) ) . ');';

$script = 'window.onload = () => {
' . $editor_object . '.coreData.unstableBootstrapServerSideEntities(' . wp_json_encode( $this->app->getEntities() ) . ');
' . $editor_object . '.editor.unstableBootstrapServerSideBreakpointDefinitions(' . wp_json_encode( $this->app->getEntity( 'breakpoints' ) ) . ');
' . $editor_object . '.coreData.unstableBootstrapServerSideVariableDefinitions(' . wp_json_encode( $this->app->getRegisteredValueAddons( 'variable', false ) ) . ');
' . $editor_object . '.editor.init();
' . ( blockera_get_experimental( [ 'data', 'dynamicValue' ] ) ? $dynamic_value_bootstrapper : '' ) . '
};';

if ( false !== strpos( $inline_script, $script ) ) {

return $inline_script;
}

return sprintf( '%s%s', $inline_script . PHP_EOL, $script );
}

/**
* Create after inline script for blockera editor handler.
*
* @param string $inline_script the previous inline script.
*
* @hooked 'blockera/wordpress/{$this->getId()}/inline-script/after'
*
* @throws BindingResolutionException BindingResolutionException to handle errors.
* @return string the inline script for initialize blockera some package's configuration.
*/
public function afterInlineScript( string $inline_script ): string {

if ( ! $this->app instanceof Blockera ) {

return $inline_script;
}

$editor_object = $this->getEditorObject();

if ( empty( $editor_object ) ) {

return $inline_script;
}

/**
* Filterable shared block attributes,
* For external developers to extending blockera shared block attributes.
Expand Down Expand Up @@ -124,14 +178,7 @@ function ( string $block_type ) use ( $editor_object, $app ): string {
);

$script = implode( ";\n", $blocks_attributes_scripts ) . '
' . $editor_object . '.editor.unstableRegistrationSharedBlockAttributes(' . wp_json_encode( $shared_block_attributes ) . ');
window.onload = () => {
' . $editor_object . '.coreData.unstableBootstrapServerSideEntities(' . wp_json_encode( $this->app->getEntities() ) . ');
' . $editor_object . '.editor.unstableBootstrapServerSideBreakpointDefinitions(' . wp_json_encode( $this->app->getEntity( 'breakpoints' ) ) . ');
' . $editor_object . '.coreData.unstableBootstrapServerSideVariableDefinitions(' . wp_json_encode( $this->app->getRegisteredValueAddons( 'variable', false ) ) . ');
' . $editor_object . '.editor.init();
' . ( blockera_get_experimental( [ 'data', 'dynamicValue' ] ) ? $dynamic_value_bootstrapper : '' ) . '
};';
' . $editor_object . '.editor.unstableRegistrationSharedBlockAttributes(' . wp_json_encode( $shared_block_attributes ) . ');';

if ( false !== strpos( $inline_script, $script ) ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ describe('Icon Block → Inner Blocks → WP Compatibility', () => {
settings: {
name: 'Base',
id: 'base',
value: '#f9f9f9',
value: '#FFFFFF',
reference: {
type: 'theme',
theme: 'Twenty Twenty-Four',
theme: 'Twenty Twenty-Five',
},
type: 'color',
var: '--wp--preset--color--base',
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('Icon Block → Inner Blocks → WP Compatibility', () => {
value: '#111111',
reference: {
type: 'theme',
theme: 'Twenty Twenty-Four',
theme: 'Twenty Twenty-Five',
},
type: 'color',
var: '--wp--preset--color--contrast',
Expand All @@ -298,69 +298,69 @@ describe('Icon Block → Inner Blocks → WP Compatibility', () => {
});

// change variable
cy.selectValueAddonItem('contrast-2');
cy.selectValueAddonItem('accent-1');

cy.getParentContainer('Text Color').within(() => {
cy.clickValueAddonButton();
});

// change variable
cy.selectValueAddonItem('base-2');
cy.selectValueAddonItem('accent-5');

//
// Check
//
getWPDataObject().then((data) => {
expect('base-2').to.be.equal(
expect('accent-5').to.be.equal(
getSelectedBlock(data, 'iconColor')
);
expect(undefined).to.be.equal(
getSelectedBlock(data, 'customIconColor')
);
expect('#ffffff').to.be.equal(
expect('#FBFAF3').to.be.equal(
getSelectedBlock(data, 'iconColorValue')
);
expect({
settings: {
name: 'Base / Two',
id: 'base-2',
value: '#ffffff',
name: 'Accent 5',
id: 'accent-5',
value: '#FBFAF3',
reference: {
type: 'theme',
theme: 'Twenty Twenty-Four',
theme: 'Twenty Twenty-Five',
},
type: 'color',
var: '--wp--preset--color--base-2',
var: '--wp--preset--color--accent-5',
},
name: 'Base / Two',
name: 'Accent 5',
isValueAddon: true,
valueType: 'variable',
}).to.be.deep.equal(
getSelectedBlock(data, 'blockeraFontColor')
);

expect('contrast-2').to.be.equal(
expect('accent-1').to.be.equal(
getSelectedBlock(data, 'iconBackgroundColor')
);
expect(undefined).to.be.equal(
getSelectedBlock(data, 'customIconBackgroundColor')
);
expect('#636363').to.be.equal(
expect('#FFEE58').to.be.equal(
getSelectedBlock(data, 'iconBackgroundColorValue')
);
expect({
settings: {
name: 'Contrast / Two',
id: 'contrast-2',
value: '#636363',
name: 'Accent 1',
id: 'accent-1',
value: '#FFEE58',
reference: {
type: 'theme',
theme: 'Twenty Twenty-Four',
theme: 'Twenty Twenty-Five',
},
type: 'color',
var: '--wp--preset--color--contrast-2',
var: '--wp--preset--color--accent-1',
},
name: 'Contrast / Two',
name: 'Accent 1',
isValueAddon: true,
valueType: 'variable',
}).to.be.deep.equal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Avatar Block → Selectors test', () => {

cy.get('@borderContainer').within(() => {
cy.get('[aria-haspopup="listbox"]').click();
cy.get('li').eq(1).click();
cy.get('div[aria-selected="false"]').eq(1).click();
});
cy.getBlock('core/avatar')
.first()
Expand Down
Loading
Loading