-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Image lightbox: move image data from context to state #63348
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
a9d9274
to
4085ad2
Compare
Size Change: +2.87 kB (+0.16%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
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.
This is more of a smoke-test result, but I gave this a test and I can see the lightbox is behaving the same for both the Image block and the Gallery block. I can't see any errors or issues 🙌
Looks like there's a small coding standards issue in image/index.php, but other than that, the code reads well to me 👍 I can see the changes to data-wp-context
and wp_interactivity_state
are moving the image data from context to state, which looks good to me. With the caveat that I'm not too familiar with wp_interactivity_state
yet!
4085ad2
to
6972c58
Compare
7aea9b1
to
a24fa62
Compare
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.
In general, it looks good to me. Thanks Madhu for making these changes 🙂
I am going to make a few small tweaks listed below.
@SantosGuillamot could you please test this with your image set? If everything works, feel free to dismiss my review and approve the pull request 🙂 |
Thanks for the review and changes @luisherranz |
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.
The UX seems broken in my local tests:
In this pull request
Lightbox.PR.mp4
In trunk
Lightbox.trunk.mp4
After taking a quick look, it seems it breaks after this commit: Use hash instead of counter for the unique id. If I revert that changes, all the images seem to work as expected.
Since multiple images can have same image source URL, same has is generated for all those images and so the image context is getting overridden.
|
There are already some uses of |
@SantosGuillamot could you take another look? Thanks! |
state.metadata[ imageId ].imageButtonTop = imageButtonTop; | ||
state.metadata[ imageId ].imageButtonRight = imageButtonRight; |
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.
@luisherranz we might have to revert to keep the data in context instead, because it is being used in the template, not anywhere else.
It is breaking the icon placement.
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 can reproduce this as well.
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.
We can use derived state, similar to how we are using in other places:
store('...', {
state: {
get imageButtonRight() {
const { imageId } = getContext();
return state.metadata[imageId].imageButtonRight;
},
get imageButtonTop() ...
},
});
<button
data-wp-style--right="state.imageButtonRight"
data-wp-style--top="state.imageButtonTop"
>
...
</button>
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 for the suggestion. The issue is fixed now.
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.
It looks good on my testing 🙂
EDIT: I didn't check the icon as reported here. It's true that part is broken.
Flaky tests detected in d0d8a85. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9936606436
|
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.
Ok, this should be ready now. Thanks, Madhu and Mario.
Let's merge it and continue working on the fix for the duplicate images and the Gallery block 🙂
* move the image context data to state * move image and button refs from context to state * Use hash instead of counter for the unique id * Don't use immutability * Fix reading prop from old context * Only store the current image ID in the state * Replace hash based on url with PHP's uniqid() * fix lightbox trigger image position --------- Co-authored-by: madhusudhand <madhudollu@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: mikachan <mikachan@git.wordpress.org> Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
What?
This change moves the image data from context to state.
The data is set in the set against a
unique_id
created for the image.After this change, image data of all images can be accessed directly from the 'core/image` state.
Why?
This helps to control the image lightbox from containing blocks such as
gallery
.In a future change, gallery can will hold list of
image_ids
in its context, and sets the image block with currentimage_id
to show lightbox as a carousel.Gallery block cannot access context data of all images.
Alternatively, gallery could have an array and each image block may push its context data to gallery array
on image init
, but it make the same data to be present in two places.Hence the image metadata is moved to its state.
Testing Instructions