Skip to content

Commit fdab03f

Browse files
release: verson 2.5.2
### Bug Fixes - **Fixes Performance Issue**: Fixes an issue with Otter making repeated calls to Rest API and slowing down the editor.
2 parents ff3187e + 25efcd0 commit fdab03f

File tree

8 files changed

+444
-399
lines changed

8 files changed

+444
-399
lines changed

docs/coding-best-practices.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,6 @@ In this project, we do not have cases when the code must do a lot of things at a
101101
102102
The challenge in this project is to extend the code to support more features. The more we have, the harder it will be to maintain the code. Fancy tricks without a good reason are not good.
103103

104-
A piece code that is performant, easy to read and understand, and easy to maintain is the best. [But sometime you can not have it all](https://www.youtube.com/watch?v=hFDcoX7s6rE). So, you need to choose what is more important for your case.
104+
A piece code that is performant, easy to read and understand, and easy to maintain is the best. [But sometime you can not have it all](https://www.youtube.com/watch?v=hFDcoX7s6rE). So, you need to choose what is more important for your case.
105+
106+
If you are using filters or HOC to add, for example, a Toolbar to all Blocks, it's recommended that you make useSelect or other requests inside child components to avoid them being triggered when they're not needed. An example of what type of issues it can cause: https://github.com/Codeinwp/otter-blocks/pull/1974

plugins/blocks-animation/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== Blocks Animation: CSS Animations for Gutenberg Blocks ===
22
Contributors: themeisle, hardeepasrani, mariamunteanu1
33
Tags: gutenberg, block, block editor, editor, animation, animations, animate, styles, block animations
4-
Requires at least: 5.9
4+
Requires at least: 6.2
55
Tested up to: 6.4
66
Requires PHP: 5.4
77
Stable tag: trunk

plugins/blocks-css/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== Blocks CSS: CSS Editor for Gutenberg Blocks ===
22
Contributors: themeisle, hardeepasrani
33
Tags: gutenberg, block, css, css editor, blocks css
4-
Requires at least: 5.9
4+
Requires at least: 6.2
55
Tested up to: 6.4
66
Requires PHP: 5.4
77
Stable tag: trunk

plugins/blocks-export-import/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== Blocks Export Import ===
22
Contributors: themeisle, hardeepasrani
33
Tags: gutenberg, block, blocks, export, import, exporter, importer, block exporter, block export, block import, block importer
4-
Requires at least: 5.9
4+
Requires at least: 6.2
55
Tested up to: 6.4
66
Requires PHP: 5.4
77
Stable tag: trunk

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== Otter Blocks - Gutenberg Blocks, Page Builder for Gutenberg Editor & FSE ===
22
Contributors: themeisle, hardeepasrani, soarerobertdaniel7, mariamunteanu1, arinat, uriahs-victor, john_pixle, wildmisha, irinelenache
33
Tags: block, blocks, gutenberg, gutenberg blocks, wordPress blocks, editor, block Editor, page Builder, post blocks, post grids
4-
Requires at least: 5.9
4+
Requires at least: 6.2
55
Tested up to: 6.4
66
Requires PHP: 5.6
77
Stable tag: trunk

src/blocks/helpers/use-settings.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import api from '@wordpress/api';
55

66
import { __ } from '@wordpress/i18n';
77

8-
import { dispatch } from '@wordpress/data';
9-
108
import {
11-
useEffect,
12-
useState
13-
} from '@wordpress/element';
9+
dispatch,
10+
useSelect
11+
} from '@wordpress/data';
12+
13+
import { useState } from '@wordpress/element';
1414

1515
/**
16-
* useSettings Hook.
16+
* useSettings Hook, modifed for Otter usage.
1717
*
1818
* useSettings hook to get/update WordPress' settings database.
1919
*
@@ -29,29 +29,28 @@ import {
2929
* @returns {[(optionName: string) => any, (option: string, value: any, success?: string, noticeId?: string, onSuccess: Function) => void, 'loading' | 'loaded' | 'error' | 'saving']} [ getOption, updateOption, status ]
3030
*
3131
*/
32+
let updatedSettings = {};
3233
const useSettings = () => {
3334
const { createNotice } = dispatch( 'core/notices' );
3435

35-
const [ settings, setSettings ] = useState({});
3636
const [ status, setStatus ] = useState( 'loading' );
37+
const [ settings, setSettings ] = useState({});
3738

38-
const getSettings = () => {
39-
api.loadPromise.then( async() => {
40-
try {
41-
const settings = new api.models.Settings();
42-
const response = await settings.fetch();
43-
setSettings( response );
44-
} catch ( error ) {
45-
setStatus( 'error' );
46-
} finally {
47-
setStatus( 'loaded' );
48-
}
49-
});
50-
};
39+
useSelect( select => {
40+
const { getEntityRecord } = select( 'core' );
41+
42+
// Bail out if settings are already loaded.
43+
if ( Object.keys( settings ).length ) {
44+
return;
45+
}
46+
47+
const request = getEntityRecord( 'root', 'site' );
5148

52-
useEffect( () => {
53-
getSettings();
54-
}, []);
49+
if ( request ) {
50+
setStatus( 'loaded' );
51+
setSettings( request );
52+
}
53+
}, [ settings ]);
5554

5655
/**
5756
* Get the value of the given option.
@@ -60,7 +59,7 @@ const useSettings = () => {
6059
* @returns {any} Option value.
6160
*/
6261
const getOption = option => {
63-
return settings?.[option];
62+
return updatedSettings?.[option] || settings?.[option];
6463
};
6564

6665
/**
@@ -107,7 +106,8 @@ const useSettings = () => {
107106
);
108107
}
109108

110-
getSettings();
109+
updatedSettings = response;
110+
setSettings( response );
111111
onSuccess?.( response );
112112
});
113113

0 commit comments

Comments
 (0)