Prevent scripts from loading if behaviors are not used#52140
Prevent scripts from loading if behaviors are not used#52140michalczaplinski merged 8 commits intotrunkfrom
Conversation
|
Flaky tests detected in c15fbe4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5520312218
|
artemiomorales
left a comment
There was a problem hiding this comment.
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
artemiomorales
left a comment
There was a problem hiding this comment.
@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
|
artemiomorales
left a comment
There was a problem hiding this comment.
@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
artemiomorales
left a comment
There was a problem hiding this comment.
@michalczaplinski I've added the additional test cases. Let me know if all looks good to you! If so, I think we can merge.
cbravobernal
left a comment
There was a problem hiding this comment.
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.jsfile.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.jsfile is not loaded.Lightboxbehavior and save the post.