-
Notifications
You must be signed in to change notification settings - Fork 83
Add Enqueued_Scripts_Size_Check class #76
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
Add Enqueued_Scripts_Size_Check class #76
Conversation
felixarntz
left a comment
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.
@vishalkakadiya There are a couple things that need iteration here; mostly small things, but a few are critical to be addressed prior to merge (e.g. the modification to the test bootstrap script, and a cleanup routine for globals).
Please see my below feedback.
tests/testdata/plugins/test-plugin-with-errors/test-plugin-with-errors.php
Outdated
Show resolved
Hide resolved
tests/testdata/plugins/test-plugin-with-errors/enqueued-scripts-size-check.php
Outdated
Show resolved
Hide resolved
|
@jjgrainger @vishalkakadiya Regarding the problem that the test plugin code never runs in the unit tests, the issue is that the test plugin is never actually loaded. And we shouldn't force it to load generally via the test bootstrap file as that would pollute other tests (see my comment in the review above). Since plugins are only loaded once, very early in the WordPress load cycle, we have to find ways to write test plugins so that they can be loaded on demand in the test suite without polluting global scope.
Also see my related review feedback above, we should use separate test single-file plugins per individual check that we test, otherwise, if we have a single plugin with all errors, things will get messy and they may conflict with each other. We should be able to change the test plugin with errors that we have so far to make it two separate plugins and have both of those plugins satisfy the above requirements in order not to irrevocably pollute global scope. |
|
Thanks @felixarntz the feedback here and the discussions with @joemcgill on Slack have been helpful here! I've gone over the changes requested and made the updates to the test plugins based on your feedback. This has been helpful in cleaning things up and avoiding issues around loading the plugins for testing. The changes I've made has got test working but there are a couple of things I want to highlight.
Let me know if you have any questions or feedback on this. Thanks |
| wp_enqueue_scripts(); | ||
| wp_head(); | ||
| wp_footer(); |
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.
My main question about this approach is that it can introduce other side effects when all of this is called. I'm also unsure how this accounts for situations where someone is conditionally loading scripts based on some state associated with the URL, like the template type, etc.
Instead of calling wp_head() and wp_footer() directly, you could call WP_Scripts::do_head_items() and WP_Scripts::do_footer_items(), respectively without introducing other side effects if there are other actions hooked to header/footer actions.
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.
Thanks @joemcgill I agree it would be cleaner using the WP_Scripts methods you've mentioned. I've updated the PR to use these.
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.
Thanks @jjgrainger. Can you clarify my other question about how the $url is intended to be used in relationship to what scripts are being enqueued?
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.
@joemcgill we simulate the URL being requested by modifying the main WP_Query. We have a URL_Aware trait which handles this and provides methods to use within checks. The run method in this check uses those to loop over each of the URLs and run the check logic against each publicly viewable post type and home page. Let me know if you have any other questions.
joemcgill
left a comment
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.
I'm not seeing anything that stands out as a blocker here. I think it will be good to get this merged and do some field analysis on a few known plugins to make sure this performing the way we expect, particularly since mocking state changes to globals can be tricky to account for.
felixarntz
left a comment
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.
@vishalkakadiya @jjgrainger This looks great now, thank you for the iterations!
I have a few last bits of feedback here, but it's almost good to merge.
|
Thanks @felixarntz I've updated the PR based on the feedback. This is ready for review |
felixarntz
left a comment
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.
@jjgrainger Thank you for the updates, LGTM!
Add Enqueued_Scripts_Size_Check class
Closes #17