-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Prevent scripts from loading if behaviors are not used #52140
Conversation
Flaky tests detected in c15fbe4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5520312218
|
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.
Hi @michalczaplinski! I took a look and this PR works if the theme.json default value for the behavior is false, but it breaks the lightbox if the default value is true. To Illustrate further:
This works
"behaviors": {
"blocks": {
"core/image": {
"lightbox": {
"enabled": false
}
}
}
}
This doesn't work
"behaviors": {
"blocks": {
"core/image": {
"lightbox": {
"enabled": true
}
}
}
}
- Copy the logic from behaviors.php
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.
@michalczaplinski As I think on it, I believe we should also add a test for this.
Some quick comments on code & tests: 2023-07-11_14-08-25.mp4 |
Size Change: +2.41 kB (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
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.
@michalczaplinski It's working — looking good! I think we should also add the following test cases:
-Should add view script if lightbox is enabled via theme.json
-Should NOT add view script if lightbox is enabled via theme.json but overriden in block settings
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.
@michalczaplinski I've added the additional test cases. Let me know if all looks good to you! If so, I think we can merge.
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.
Looks good to me too.
Looks good, thanks for adding the extra tests @artemiomorales ! |
What?
When no behaviors are used, do not load the
interactivity-view.js
file.Why?
So that we don't wastefully load JS.
How?
Adding a workaround very similar to the one currently used in the Navigation block.
Testing Instructions
interactivity-view.js
file is not loaded.Lightbox
behavior and save the post.