-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Read only once the theme.json files from the styles/
folder.
#6843
Read only once the theme.json files from the styles/
folder.
#6843
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
styles/
folder only once.
styles/
folder only once.styles/
folder.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely a good idea to avoid rereading these same files. I wonder if we can also avoid the potential of processing the same decoded files multiple times as well?
This PR was an initial step given issues encountered in an original attempt to also cache the additional processing of those files in: WordPress/gutenberg#62610 |
Cache reading theme.json files from styles/ folder.
Tested and LGTM Gutenberg sync PR over here: |
Very good question! I'll keep that in mind when testing WordPress/gutenberg#62638, maybe there's an way to test in the plugin first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
✅ Theme style variations continue to work
✅ Block style variations are registered from partials correctly
Screen.Recording.2024-06-18.at.2.39.11.PM.mp4
Might be worth adding a note about the caching to the @since
comment?
I've taken then liberty to push this minor tweak. |
Just gave this a test run and switching styles and variations works as expected! |
committed in r58428. |
Trac ticket https://core.trac.wordpress.org/ticket/61451
What
Read only once the theme.json files stored in the
styles/
folder.Why
I've realized that, unlike the
theme.json
files defined by core & theme, we don't cache these — hence we end up reading them a few times from the filesystem.How
By using the existing
read_json_file
function instead of usingwp_json_file_decode
directly.How to test
Go to "Site Editor > Styles" and apply one of them. Verify the changes are reflected in the front end. Do the same from the global styles sidebar in the site editor.
Create a
partial.json
file within thestyles/
folder with the following contents:Go to any editor, add a group block, and verify there is a "Partial" style variation (Block Settings > Styles). Apply the variation and save the changes. Verify the contents are the expected (background color is aliceblue) — also in the front-end.
Commit
Commit message, to make it easy for committers: