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: image fields (and other connection fields) not properly resolving when queried asPreview #189

Merged
merged 7 commits into from Mar 15, 2024

Conversation

jasonbahl
Copy link
Contributor

@jasonbahl jasonbahl commented Mar 13, 2024

What does this implement/fix? Explain your changes.

This fixes a bug where Image fields (and other fields that return Connections) were not properly resolving when querying a page asPreview: true.

In order to support preview resolution, all field names and keys are tracked and then during resolution filters are applied to ensure the meta is resolved properly for each field (either the published post or the preview post).

Fields that return Connection types were not properly being tracked in this registry, leading to the preview resolver filter not being applied for these fields, so they would return preview data from the published node instead of the preview node.

Does this close any currently open issues?

closes #187

Any other comments?

I published a page with the following image uploaded for the image fields:

  • http://uri-debugging.local/wp-content/uploads/2024/03/1920x1080.png

When I query the page with asPreview: false I see the image returned as expected:

CleanShot 2024-03-13 at 16 39 29

When I query the page as an authenticated user with asPreview: true, I see the published image value (expected, since I have not made any un-published changes yet):

CleanShot 2024-03-13 at 16 41 08

Now, if I go replace the image:

  • published: http://uri-debugging.local/wp-content/uploads/2024/03/1920x1080.png
  • preview: http://uri-debugging.local/wp-content/uploads/2024/03/andrea-de-santis-kq3hRVDiYYY-unsplash-scaled.jpg

And query asPreview: true again:

BEFORE

I still see the published image, not the preview image. 😭

CleanShot 2024-03-13 at 16 44 37

AFTER

I see the image that was added to the preview but not yet published! 🥳

CleanShot 2024-03-13 at 16 43 43

… they're tracked for things like preview support, but also to prevent duplicate registration.

- ensure field types that return a connection are tracked in the registry. This fixes a bug related to previews not resolving, and likely also prevents duplicate registration of some fields in some cases.
@coveralls
Copy link

coveralls commented Mar 13, 2024

Pull Request Test Coverage Report for Build 046b302be979fdbff9d14a546b3ee38b1f51ab2b-PR-189

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.3%) to 63.714%

Files with Coverage Reduction New Missed Lines %
src/FieldConfig.php 1 91.84%
Totals Coverage Status
Change from base Build ece620b9f911b507d9cc9754d75449bf2879bc0e: 0.3%
Covered Lines: 2093
Relevant Lines: 3285

💛 - Coveralls

…inst previews

- update TextFieldTest.php to test querying against a preview
…1 as the published image, 1 as the preview image, for example)

- update ImageFieldTest to test querying the image field on a post and querying the image field on a preview
@jasonbahl jasonbahl merged commit 071cfec into develop Mar 15, 2024
21 of 25 checks passed
@jasonbahl jasonbahl mentioned this pull request Mar 15, 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.

preview query returns wrong page data (ACF Fields, no Gutenberg)
2 participants