Gutenberg Experiments: Ensure the experiment is active before outputting flags#77728
Conversation
ramonjd
left a comment
There was a problem hiding this comment.
I checked the affected experiments that run clientside, e.g., upload modal and experimental blocks.
This PR ensures that toggling on/off works (they are off)
Toggling back on activates the experiments too.
Good spotting @andrewserong
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for the quick review! 🙇 |
|
Flaky tests detected in 30164c4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25028630141
|
|
Thanks for the follow-up 🙇♂️ |
…ing flags (#77728) Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
What?
Follows:
Ensure that Gutenberg experiments are actually active and truthy before outputting their JS global flags.
Why?
In #77443 where the experiments page was redesigned, switching an experiment to be off now means that the flag is set to
falseexplicitly. Many of the experiments only checked to see if the array key exists, and so if the key existed but was set tofalsethe experiment would unexpectedly be active 😱This change updates all the experiments that were doing that to use the
gutenberg_is_experiment_enabledutility function that performs a! empty()check which means explicit false values will be treated as the experiment not being enabled.How?
gutenberg_is_experiment_enabledcheck instead of an array key exists checkTesting Instructions
trunktry toggling the Media Upload Modal on and off and notice that after activating it's impossible to switch offScreenshots or screencast
To show what I mean, toggle this experiment on and off at http://localhost:8888/wp-admin/admin.php?page=experiments-wp-admin:
Then go to the post editor and go to add a featured image, and you should see the core media modal:
And not this one, which should only show if the experiment is on:
Use of AI Tools
Claude Code