Skip to content

Commit

Permalink
release: verson 2.5.2
Browse files Browse the repository at this point in the history
### Bug Fixes
- **Fixes Performance Issue**: Fixes an issue with Otter making repeated calls to Rest API and slowing down the editor.
  • Loading branch information
HardeepAsrani authored Nov 22, 2023
2 parents ff3187e + 25efcd0 commit fdab03f
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 399 deletions.
4 changes: 3 additions & 1 deletion docs/coding-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ In this project, we do not have cases when the code must do a lot of things at a
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.

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.
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.

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
2 changes: 1 addition & 1 deletion plugins/blocks-animation/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== Blocks Animation: CSS Animations for Gutenberg Blocks ===
Contributors: themeisle, hardeepasrani, mariamunteanu1
Tags: gutenberg, block, block editor, editor, animation, animations, animate, styles, block animations
Requires at least: 5.9
Requires at least: 6.2
Tested up to: 6.4
Requires PHP: 5.4
Stable tag: trunk
Expand Down
2 changes: 1 addition & 1 deletion plugins/blocks-css/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== Blocks CSS: CSS Editor for Gutenberg Blocks ===
Contributors: themeisle, hardeepasrani
Tags: gutenberg, block, css, css editor, blocks css
Requires at least: 5.9
Requires at least: 6.2
Tested up to: 6.4
Requires PHP: 5.4
Stable tag: trunk
Expand Down
2 changes: 1 addition & 1 deletion plugins/blocks-export-import/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== Blocks Export Import ===
Contributors: themeisle, hardeepasrani
Tags: gutenberg, block, blocks, export, import, exporter, importer, block exporter, block export, block import, block importer
Requires at least: 5.9
Requires at least: 6.2
Tested up to: 6.4
Requires PHP: 5.4
Stable tag: trunk
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== Otter Blocks - Gutenberg Blocks, Page Builder for Gutenberg Editor & FSE ===
Contributors: themeisle, hardeepasrani, soarerobertdaniel7, mariamunteanu1, arinat, uriahs-victor, john_pixle, wildmisha, irinelenache
Tags: block, blocks, gutenberg, gutenberg blocks, wordPress blocks, editor, block Editor, page Builder, post blocks, post grids
Requires at least: 5.9
Requires at least: 6.2
Tested up to: 6.4
Requires PHP: 5.6
Stable tag: trunk
Expand Down
50 changes: 25 additions & 25 deletions src/blocks/helpers/use-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import api from '@wordpress/api';

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

import { dispatch } from '@wordpress/data';

import {
useEffect,
useState
} from '@wordpress/element';
dispatch,
useSelect
} from '@wordpress/data';

import { useState } from '@wordpress/element';

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

const [ settings, setSettings ] = useState({});
const [ status, setStatus ] = useState( 'loading' );
const [ settings, setSettings ] = useState({});

const getSettings = () => {
api.loadPromise.then( async() => {
try {
const settings = new api.models.Settings();
const response = await settings.fetch();
setSettings( response );
} catch ( error ) {
setStatus( 'error' );
} finally {
setStatus( 'loaded' );
}
});
};
useSelect( select => {
const { getEntityRecord } = select( 'core' );

// Bail out if settings are already loaded.
if ( Object.keys( settings ).length ) {
return;
}

const request = getEntityRecord( 'root', 'site' );

useEffect( () => {
getSettings();
}, []);
if ( request ) {
setStatus( 'loaded' );
setSettings( request );
}
}, [ settings ]);

/**
* Get the value of the given option.
Expand All @@ -60,7 +59,7 @@ const useSettings = () => {
* @returns {any} Option value.
*/
const getOption = option => {
return settings?.[option];
return updatedSettings?.[option] || settings?.[option];
};

/**
Expand Down Expand Up @@ -107,7 +106,8 @@ const useSettings = () => {
);
}

getSettings();
updatedSettings = response;
setSettings( response );
onSuccess?.( response );
});

Expand Down
Loading

0 comments on commit fdab03f

Please sign in to comment.