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

fix: prevent fatal errors with DOMHelpers methods by improving typesafety and returning early #257

Merged
merged 7 commits into from
Aug 7, 2024

Conversation

justlevine
Copy link
Contributor

What

This PR:

  • Updates the methods in the DOMHelpers class to return early if no HTML is passed to the method.
  • Improves type safety of the DOMHelpers methods by inlining their types to the method signatures. To maintain back-compatiblity, the old methods have been deprecated, with snake_case alternatives created with the stricter signatures.

Important

This PR is based on #256 which should be merged first.
The relevant diff for this PR is: 5b59fe3

Why

Without returning early, numerous DIDOM methods we call internally can fatal error. The improved type safety is to prevent this sort of issue leaking through again in the future.

To Test

  1. Add the following placeholder image block to a page (extracted from a TT4 pattern):

    <!-- wp:image {"width":"150px","aspectRatio":"4/3","scale":"contain","linkDestination":"none"} -->
    <figure class="wp-block-image is-resized"><img alt="" style="aspect-ratio:4/3;object-fit:contain;width:150px"/></figure>
    <!-- /wp:image -->
  2. Query for CoreBlockImageAttributes:

    {
     nodeByUri(uri: "/sample-page") { # change the URI to your page
       ... on NodeWithEditorBlocks {
         editorBlocks {
           __typename
           ... on CoreImage {
             attributes {
               width
               alt
             }
           }
         }
       }
      }
    }
  3. Ensure no errors, and attributes are returned.

Screenshots

  • Before:
    image

  • After:
    image

@justlevine justlevine requested a review from a team as a code owner July 23, 2024 04:15
Copy link

changeset-bot bot commented Jul 23, 2024

🦋 Changeset detected

Latest commit: c83a124

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@wpengine/wp-graphql-content-blocks Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@justlevine
Copy link
Contributor Author

@jasonbahl for your review

theodesp
theodesp previously approved these changes Jul 25, 2024
@theodesp
Copy link
Member

@justlevine there is a small conflict there; if you could resolve it, I can merge. Thank you

@justlevine justlevine dismissed theodesp’s stale review July 25, 2024 12:36

The merge-base changed after approval.

@justlevine
Copy link
Contributor Author

@theodesp conflicts resolved ✔️

@josephfusco josephfusco requested a review from theodesp August 2, 2024 15:20
@justlevine
Copy link
Contributor Author

#258 will fix the failing ci

Please let me know what else I can do to help advance this ticket.

@theodesp
Copy link
Member

theodesp commented Aug 6, 2024

@justlevine I merged #258

@justlevine
Copy link
Contributor Author

@theodesp I merged main into the PR, If you trigger the CI again, you should see them all passing now (besides SonarQube)

@theodesp theodesp merged commit 6241c4e into wpengine:main Aug 7, 2024
9 of 10 checks passed
@justlevine justlevine deleted the fix/DOMHelpers-return-early branch August 7, 2024 12:28
@justlevine justlevine mentioned this pull request Aug 12, 2024
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.

2 participants