You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Image block “Enlarge on click” throws JS error and locks page scrolling on first load #74184
When using the Image block with “Enlarge on click” enabled, the page becomes unscrollable after closing the lightbox, but only on the first page load. After a browser reload, the issue no longer occurs.
I investigated this myself and found a JavaScript console error coming from WordPress core, which prevents the scroll-unlock logic from running.
Steps to Reproduce
Open a page with large images using the Image block
I'm unable to reproduce the issue with the Gutenberg plugin enabled. Can you confirm that you're testing this with WP 6.9 and without the Gutenberg plugin? Also, which browser are you using for testing? Just to ensure, it's not a browser-specific bug.
I have reproduced this issue in another person's website while browsing in Mozilla Firefox.
The website uses WordPress v6.9 and the console says that the view.min.js file inside block-library creates the problem.
Thank you, @ivanbachev! I was able to reproduce the issue in Chrome and Firefox using incognito windows to ensure a fresh state. However, I cannot reproduce the same behavior locally.
Here's the code in question. @luisherranz, @DAreRodz, you might have a better idea why this might be failing.
Today I made a global change to my site to use Fancybox.
I need the functionality and since the WordPress default “Enlarge on click” is causing issues with the scroll, I decided to use a plugin instead.
I'll check back with the next WordPress release if the issue is fixed.
I was able to reproduce it locally, with a WP Studio site. It occurs in both Chrome and Firefox with cache disabled and network throttling, so it appears to be some kind of race condition. I'll keep investigating.
Okay. I've found that when a connection is slow, and two or more script modules import @wordpress/interactivity, one module may not have been downloaded yet, while the others begin evaluation.
That causes the @wordpress/interactivity module to be evaluated as well, triggering the hydration phase. The hydration phase keeps going even when the remaining module is ready to be evaluated, so I think the browser somehow prioritizes the tasks created by Scheduler.yield() (created with splitTask()) over the script evaluation.
As hydration occurs before the Image's view.js file is evaluated, all callbacks used by data-wp-init directives don't run, because the related elements have already been rendered once.
One thing that comes to mind is to modify the data-wp-init implementation to support "pending callbacks", in a similar way we do for pending getters. Still, I guess the ideal approach would be to improve the initialization phase. 🤔
Activity
Mamaduka commentedon Dec 23, 2025
Thanks for contributing, @mehrazmorshed!
I'm unable to reproduce the issue with the Gutenberg plugin enabled. Can you confirm that you're testing this with WP 6.9 and without the Gutenberg plugin? Also, which browser are you using for testing? Just to ensure, it's not a browser-specific bug.
mehrazmorshed commentedon Dec 23, 2025
Hi @Mamaduka,
I have reproduced this issue in another person's website while browsing in Mozilla Firefox.
The website uses WordPress v6.9 and the console says that the
view.min.jsfile insideblock-librarycreates the problem.The website link is: https://work.ivanbachev.com/case-study-automatepro-monitor
(access code: BACH)
Mamaduka commentedon Dec 23, 2025
Thanks, @mehrazmorshed!
Unfortunately, I don't see "Enlarge on click" enabled on any of the images on the linked page.
mehrazmorshed commentedon Dec 23, 2025
It looks like he has turned off the feature which I suggested him.
Here is the full conversation: https://wordpress.org/support/topic/enlarge-on-click-page-scroll-issue/
I have opened a ticket in WordPress Core Trac: https://core.trac.wordpress.org/ticket/64450
I think, I should close the issue now.
Mamaduka commentedon Dec 23, 2025
This is the correct place for Image block-related issues. I closed the Trac ticket.
ivanbachev commentedon Dec 23, 2025
Thank you for your assistance @mehrazmorshed .
@Mamaduka here is a test page I created with the "Enlarge on click" enabled for the images.
https://work.ivanbachev.com/test/
password: TEST
(Ignore the rest of the pages, I've temporarily disabled the feature across my website)
Mamaduka commentedon Dec 24, 2025
Thank you, @ivanbachev! I was able to reproduce the issue in Chrome and Firefox using incognito windows to ensure a fresh state. However, I cannot reproduce the same behavior locally.
Here's the code in question. @luisherranz, @DAreRodz, you might have a better idea why this might be failing.
gutenberg/packages/block-library/src/image/view.js
Lines 146 to 161 in f398e78
mehrazmorshed commentedon Dec 24, 2025
Hello @ivanbachev, thanks for joining here.
Hi @Mamaduka, What I have found till now:
Error:
Source:
/wp-includes/js/dist/script-modules/block-library/image/view.min.jsmehrazmorshed commentedon Dec 24, 2025
According to my knowledge, here’s what happens:
On close, WordPress tries to:
mehrazmorshed commentedon Dec 24, 2025
On first page load, buttonRef is undefined, so this line fails:
r.currentImage.buttonRef.focus()Because of the JS error:
t-hamano commentedon Dec 24, 2025
@ivanbachev Are you using Fancybox? The library might be conflicting with the core lightbox feature.
ivanbachev commentedon Dec 24, 2025
Today I made a global change to my site to use Fancybox.
I need the functionality and since the WordPress default “Enlarge on click” is causing issues with the scroll, I decided to use a plugin instead.
I'll check back with the next WordPress release if the issue is fixed.
DAreRodz commentedon Jan 8, 2026
Hi there! Just taking a look at this issue.
I was able to reproduce it locally, with a WP Studio site. It occurs in both Chrome and Firefox with cache disabled and network throttling, so it appears to be some kind of race condition. I'll keep investigating.
DAreRodz commentedon Jan 9, 2026
Okay. I've found that when a connection is slow, and two or more script modules import
@wordpress/interactivity, one module may not have been downloaded yet, while the others begin evaluation.That causes the
@wordpress/interactivitymodule to be evaluated as well, triggering the hydration phase. The hydration phase keeps going even when the remaining module is ready to be evaluated, so I think the browser somehow prioritizes the tasks created byScheduler.yield()(created withsplitTask()) over the script evaluation.As hydration occurs before the Image's
view.jsfile is evaluated, all callbacks used bydata-wp-initdirectives don't run, because the related elements have already been rendered once.One thing that comes to mind is to modify the
data-wp-initimplementation to support "pending callbacks", in a similar way we do for pending getters. Still, I guess the ideal approach would be to improve the initialization phase. 🤔I'm open to ideas about how to fix this. 🙂
luisherranz commentedon Jan 12, 2026
Possible solution:
aaronjorbin commentedon May 19, 2026
@ivanbachev Thank you for helping on this! Would you be able to link your WordPress and Github accounts to ensure your work is properly credited in WordPress releases?