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

WordPress 5.8: Prevent white screen and errors on Widget Screen #1390

Merged
merged 5 commits into from
Jun 30, 2021

Conversation

laurelfulford
Copy link
Contributor

@laurelfulford laurelfulford commented Jun 29, 2021

All Submissions:

Changes proposed in this Pull Request:

With WordPress 5.8's introduction of Widget Blocks, enqueue_block_editor_assets is now also being used on the Appearance > Widgets screen, to make sure all of the block assets are loaded. In the theme we have a number of JS files we're loading into the editor using this hook that are strictly for posts/pages: featured image placements, hiding page titles and updated dates, and article subtitles. In particular, the post-meta-toggle.js is causing an error on the Widgets screen that makes it unusable. This PR adds a check for the current screen before enqueuing any of these assets.

In one related issue in the Gutenberg repo (WordPress/gutenberg#28538), there's a suggestion for possibly adding screen-specific hooks (enqueue_block_editor_assets-$screen) on top of what's there now; if that happens down the road, it should be easy to switch the current approach to use the new hook.

In WP 5.8, some front-end scripts and styles are also being loaded into the Widgets screen; the amp-fallback.js is currently firing errors because it can't find specific HTML elements. Rather than totally blocking this script (I want to try to let WordPress do it's own thing on these updated screens as much as possible!), I increased the checks for different elements so if they're not found, the code doesn't try to run.

Notes:

  • I was able to consistently recreate the "white screen" issue on my local test sites, but not a Jurassic Ninja one; so it's possible this won't be as catastrophic on live sites, but we still should probably not be loading unnecessary files on the widgets screen.
  • This PR pulls double-duty, fixing two completely unrelated issues on the Appearance > Widgets screen. If it's less confusing to handle them separately, let me know!
  • I'm open to feedback on either approach here; I'm especially unsure about the first one. I also tried adding checks to the post-meta-toggle.js because it's the problem file, but I can't actually see needing any of these files on the Widget screen as it works now.

Closes #1386

How to test the changes in this Pull Request:

Note: I've outlined the steps to test using two different test sites, since it saves you from having to upgrade, then downgrade, a site, but it all can be tested on one site if desired.

If you haven't already, set up a test site to run the latest WordPress 5.8 Beta (beta 4):

  1. On a test site, install and activate the WordPress Beta Tester plugin.
  2. Navigate to Tools > Beta Testing WordPress, and under Select the update channel you would like this website to use: pick Bleeding Edge; click 'Save'.
  3. The screen will update on save to add new options; under Select one of the stream options below: pick Beta/RC Only and click 'Save'.
  4. Navigate to Dashboard > Updates; you should have the option to update to version 5.8-beta4. Click that, and go grab a coffee!

Steps to test the PR:

  1. Disable AMP, so the site is always loading the AMP fallback script.
  2. Navigate to WP Admin > Widgets.
  3. Note that the page doesn't load:

image

  1. Apply the PR and run npm run build, then reload the page; confirm that it's now loading:

image

  1. There are still a number of errors in the console, at least on my localhost; double-check that none are coming from the AMP fallback JS. (Some of the errors seem to be related to the Newspack Blocks plugin -- or at least they disappear when I disable it -- but I need to do more testing to confirm before filing an issue).
  2. Just a precaution, make sure the per-page/post options (hide page title, featured image position, etc...) are still loading when you edit a page or post.
  3. Confirm that the mobile menu/search/slide-out sidebar toggles still work on the front end.
  4. Test this PR on a site running WP 5.7.2 and confirm that the per-page/post options (hide page title, featured image position, etc...), and AMP fallback JavaScript still works.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@laurelfulford laurelfulford added the [Status] Needs Review The issue or pull request needs to be reviewed label Jun 29, 2021
@laurelfulford laurelfulford requested a review from dkoo June 29, 2021 20:02
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Works as described! I have a few non-blocking suggestions below, but feel free to ignore if they're not applicable.

@@ -42,12 +42,8 @@
const mobileToggle = document.getElementsByClassName( 'mobile-menu-toggle' ),
body = document.getElementsByTagName( 'body' )[ 0 ],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
body = document.getElementsByTagName( 'body' )[ 0 ],
body = document.body,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Updated in 4675b36.

Comment on lines 95 to 96
const mobileOpenButton = headerContain.getElementsByClassName( 'mobile-menu-toggle' )[ 0 ],
mobileCloseButton = mobileSidebar.getElementsByClassName( 'mobile-menu-toggle' )[ 0 ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is there any reason not to use querySelector instead, since we're looking for single elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None at all! 😄 updated in 4675b36.

@@ -111,6 +110,9 @@

// Desktop menu (AKA slide-out sidebar) fallback.
for ( let i = 0; i < desktopToggle.length; i++ ) {
const desktopOpenButton = headerContain.getElementsByClassName( 'desktop-menu-toggle' )[ 0 ],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is there any reason not to use querySelector instead, since we're looking for single elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 4675b36!

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Jun 30, 2021
@laurelfulford
Copy link
Contributor Author

Thanks @dkoo! I made the JS tweaks; the main issue there is that I'm pretty clumsy with vanilla JavaScript :) thanks for catching those!

@laurelfulford laurelfulford merged commit 5731581 into master Jun 30, 2021
matticbot pushed a commit that referenced this pull request Jul 6, 2021
## [1.39.3-alpha.1](v1.39.2...v1.39.3-alpha.1) (2021-07-06)

### Bug Fixes

* ads media queries ([239ff6e](239ff6e))
* correct custom fonts in block widget preview ([#1401](#1401)) ([878b6a1](878b6a1))
* figcaption rendering bug in Safari ([#1382](#1382)) ([e274499](e274499))
* improve donate block appearance for WP 5.8 ([#1398](#1398)) ([51fc4f7](51fc4f7))
* prevent white screen and errors on Widget Screen ([#1390](#1390)) ([5731581](5731581))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.39.3-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jul 6, 2021
## [1.39.3](v1.39.2...v1.39.3) (2021-07-06)

### Bug Fixes

* ads media queries ([239ff6e](239ff6e))
* correct custom fonts in block widget preview ([#1401](#1401)) ([878b6a1](878b6a1))
* figcaption rendering bug in Safari ([#1382](#1382)) ([e274499](e274499))
* improve donate block appearance for WP 5.8 ([#1398](#1398)) ([51fc4f7](51fc4f7))
* prevent white screen and errors on Widget Screen ([#1390](#1390)) ([5731581](5731581))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.39.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Widget screen blank with 5.8
3 participants