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

Make sure media scripts are loaded before we load our custom image generation JS #522

Merged
merged 1 commit into from
Jul 3, 2023

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Jun 30, 2023

Description of the Change

As reported in #520, on some screens we get a JS console error from our custom Media Modal code. This JS file is only loaded if we're on either post.php or post-new.php, which is good, but this does mean it loads on custom post creation/edit screens, which may not have any media handling (like the External Connection flow that Distributor uses).

It seems like the easy fix is to use the wp_enqueue_media function before loading our custom Media Modal JS file. In testing this, it fixed the reported issue and didn't cause any regressions from what I could see either in the Block Editor or Classic Editor image generation processes.

Closes #520

How to test the Change

  1. Check out this PR and run npm install && npm run build
  2. Go to a custom post screen, like the Distributor Add External Connection flow
  3. Ensure no JS errors show in the console
  4. Ensure you can still generate images in normal flows (Image block, featured image, inline images in the Classic Editor)

Changelog Entry

Fixed - Ensure we don't throw any JS errors in our image generation file

Credits

Props @dkotter, @ravinderk

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@dkotter dkotter added this to the 2.2.3 milestone Jun 30, 2023
@dkotter dkotter self-assigned this Jun 30, 2023
@dkotter dkotter requested review from a team and jeffpaul as code owners June 30, 2023 20:12
@dkotter dkotter requested review from ravinderk and removed request for a team and jeffpaul June 30, 2023 20:12
@dkotter dkotter merged commit 513769b into develop Jul 3, 2023
@dkotter dkotter deleted the fix/520 branch July 3, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

media-modal.js should not cause javascript error
2 participants