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

Fix: Rest global styles controller accessing config that may not exist #36047

Merged

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Oct 28, 2021

After a fix on #35801 the post is now created on the database by "get_user_data_from_custom_post_type" as {"version": ' . WP_Theme_JSON_Gutenberg::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }. And I think it is right by default the user has no settings and styles.
Our code was assuming that on the database existing settings and styles were always present by unconditionally doing $config['settings'] = $existing_config['settings'] when $existing_config['settings'] may not exist.
In the case where $existing_config['settings'] did not exist there would occur a PHP warning and on the database, we would then serialize { settings: null }. Settings being null is not something the frontend code that compiles the styles accepts and as a consequence no global styles would be output at all. As a different issue, we need to make sure that if user global styles are not valid theme styles are still output.

How has this been tested?

Delete the current global styles post if there is any.
Open the site editor and change the global background color.
Verify global styles are still output on the frontend (on trunk they are not).

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth adding a unit test about this case?

@jorgefilipecosta jorgefilipecosta merged commit 59b5243 into trunk Oct 28, 2021
@jorgefilipecosta jorgefilipecosta deleted the fix/accesing-exisring-config-that-may-not-exist branch October 28, 2021 15:39
@github-actions github-actions bot added this to the Gutenberg 11.9 milestone Oct 28, 2021
@jorgefilipecosta
Copy link
Member Author

Do you think it's worth adding a unit test about this case?

Yes, I think testing this may be useful I will look into expanding our API test cases.

@youknowriad
Copy link
Contributor

Looks like this PR introduced some linting issues on trunk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants