Skip to content

Commit

Permalink
Fixed rendering performance in editor (#222)
Browse files Browse the repository at this point in the history
* fixed slow rendering issue when first page load and when duplicate blocks without any extensions on blocks

* fixed counters animation callback

* Update frontend.js

* revert back animation for Accordion and improved animation to properly run without blinks

* fixed InputGroup component styles

* build
  • Loading branch information
nk-o authored Dec 18, 2024
1 parent 09d6223 commit 42479b2
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build/gutenberg/blocks/accordion/frontend.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '07f8b5d1e865ee742849');
<?php return array('dependencies' => array(), 'version' => '61ceb041748865c11d7d');
2 changes: 1 addition & 1 deletion build/gutenberg/blocks/accordion/frontend.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/gutenberg/editor-rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/gutenberg/editor.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/gutenberg/extend/effects/frontend.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'b6f99e2d5bf8a8e6cf12');
<?php return array('dependencies' => array(), 'version' => '42f5f2cc501efadd2b31');
2 changes: 1 addition & 1 deletion build/gutenberg/extend/effects/frontend.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/gutenberg/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('jquery', 'lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-plugins', 'wp-rich-text', 'wp-token-list'), 'version' => '513bbfd525041dd2bd20');
<?php return array('dependencies' => array('jquery', 'lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-plugins', 'wp-rich-text', 'wp-token-list'), 'version' => '15c30a586b736b5631ce');
2 changes: 1 addition & 1 deletion build/gutenberg/index.js

Large diffs are not rendered by default.

58 changes: 43 additions & 15 deletions gutenberg/blocks/accordion/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@ const { events } = GHOSTKIT;

let pageHash = location.hash;

const ANIMATION_SPEED = 300;
const ANIMATION_SPEED = 400;

function getCurrentContentStyles($el) {
return {
display: $el.style.display,
overflow: $el.style.overflow,
height: $el.style.height,
paddingTop: $el.style.paddingTop,
paddingBottom: $el.style.paddingBottom,
};
}
function resetContentStyles($el) {
$el.style.display = '';
$el.style.overflow = '';
$el.style.height = '';
$el.style.paddingTop = '';
$el.style.paddingBottom = '';
}

function show($item, animationSpeed, cb) {
const $button = $item.querySelector(
Expand All @@ -29,6 +46,10 @@ function show($item, animationSpeed, cb) {
$button.setAttribute('aria-expanded', 'true');
}

const currentStyles = getCurrentContentStyles($content);

resetContentStyles($content);

const contentStyles = window.getComputedStyle($content);

const endHeight = contentStyles.height;
Expand All @@ -37,6 +58,9 @@ function show($item, animationSpeed, cb) {

$content.style.display = 'block';
$content.style.overflow = 'hidden';
$content.style.height = currentStyles.height || 0;
$content.style.paddingTop = currentStyles.paddingTop || 0;
$content.style.paddingBottom = currentStyles.paddingBottom || 0;

const animation = animate(
$content,
Expand All @@ -47,17 +71,19 @@ function show($item, animationSpeed, cb) {
},
{
duration: animationSpeed / 1000,
easing: 'easeOut',
ease: [0.6, 0, 0.3, 1],
}
);

animation.then(() => {
// Reset styles.
$content.style.display = '';
$content.style.overflow = '';
$content.style.height = '';
$content.style.paddingTop = '';
$content.style.paddingBottom = '';
// Check if animation stopped manually.
const isStopped =
$item.gktAccordion.animation?.animations?.[0]?.isStopped || false;

if (!isStopped) {
resetContentStyles($content);
}

$item.gktAccordion.animation = null;

cb();
Expand All @@ -84,17 +110,19 @@ function hide($item, animationSpeed, cb) {
},
{
duration: animationSpeed / 1000,
easing: 'easeOut',
ease: [0.6, 0, 0.3, 1],
}
);

animation.then(() => {
// Reset styles.
$content.style.display = '';
$content.style.overflow = '';
$content.style.height = '';
$content.style.paddingTop = '';
$content.style.paddingBottom = '';
// Check if animation stopped manually.
const isStopped =
$item.gktAccordion.animation?.animations?.[0]?.isStopped || false;

if (!isStopped) {
resetContentStyles($content);
}

$item.gktAccordion.animation = null;

cb();
Expand Down
6 changes: 3 additions & 3 deletions gutenberg/components/input-group/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

// Better help styles.
.components-base-control__help {
margin-top: -6px;
margin-top: 0;
font-size: 9px;
font-weight: 500;
text-align: center;
Expand Down Expand Up @@ -68,8 +68,8 @@
// Important toggle.
.ghostkit-control-important-toggle {
position: absolute;
top: 6px;
right: 1px;
top: 10px;
right: 2px;
opacity: 0;
}

Expand Down
14 changes: 6 additions & 8 deletions gutenberg/extend/effects/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ events.on(document, 'init.blocks.gkt', () => {
const config = {
from,
to,
duration: 0.8,
duration: 1,
easing: [0.6, 0, 0.3, 1],
cb(progress) {
const position = (to - from) * progress + from;
Expand Down Expand Up @@ -233,15 +233,13 @@ events.on(document, 'init.blocks.gkt', () => {
});
}

animate(
(progress) => {
animate(0, 1, {
duration: config.duration,
ease: config.easing,
onUpdate: (progress) => {
config.cb(progress);
},
{
duration: config.duration,
ease: config.easing,
}
).then(() => {
}).then(() => {
events.trigger($counter, 'counted.counter.gkt', {
config,
});
Expand Down
9 changes: 4 additions & 5 deletions gutenberg/extend/styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ function CustomStylesComponent(props) {

// Reset unused styles and ID.
if (reset) {
const newClassName = replaceClass(
className,
'ghostkit-custom',
''
);
// Convert to undefined when empty to prevent unnecessary
// rerenders if className remains unchanged.
const newClassName =
replaceClass(className, 'ghostkit-custom', '') || undefined;

if (newClassName !== className) {
newAttrs.className = !newClassName
Expand Down
2 changes: 1 addition & 1 deletion languages/ghostkit.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-12-18T14:37:32+00:00\n"
"POT-Creation-Date: 2024-12-18T20:25:17+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.9.0\n"
"X-Domain: ghostkit\n"
Expand Down

0 comments on commit 42479b2

Please sign in to comment.