Skip to content

Image block “Enlarge on click” throws JS error and locks page scrolling on first load #74184

Closed

Description

@mehrazmorshed

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

  1. Open a page with large images using the Image block
  2. Ensure “Enlarge on click” is enabled
  3. Scroll down the page
  4. Click an image to open it in the lightbox
  5. Close the image
  6. Try to scroll the page

Issue Source: https://wordpress.org/support/topic/enlarge-on-click-page-scroll-issue/

Screenshot:
Image

Activity

  1. added
    [Type] Bug
    Needs Testing
    [Block] Image
    on Dec 23, 2025
  2. Mamaduka commented on Dec 23, 2025

    @Mamaduka
    Member

    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.

  3. added
    [Status] Needs More Info
    and removed
    Needs Testing
    on Dec 23, 2025
  4. mehrazmorshed commented on Dec 23, 2025

    @mehrazmorshed
    ContributorAuthor

    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.js file inside block-library creates the problem.

    The website link is: https://work.ivanbachev.com/case-study-automatepro-monitor
    (access code: BACH)

  5. Mamaduka commented on Dec 23, 2025

    @Mamaduka
    Member

    Thanks, @mehrazmorshed!

    Unfortunately, I don't see "Enlarge on click" enabled on any of the images on the linked page.

  6. mehrazmorshed commented on Dec 23, 2025

    @mehrazmorshed
    ContributorAuthor

    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.

  7. Mamaduka commented on Dec 23, 2025

    @Mamaduka
    Member

    This is the correct place for Image block-related issues. I closed the Trac ticket.

  8. ivanbachev commented on Dec 23, 2025

    @ivanbachev

    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)

  9. Mamaduka commented on Dec 24, 2025

    @Mamaduka
    Member

    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.

    // Waits until the close animation has completed before allowing a
    // user to scroll again. The duration of this animation is defined in
    // the `styles.scss` file, but in any case we should wait a few
    // milliseconds longer than the duration, otherwise a user may scroll
    // too soon and cause the animation to look sloppy.
    setTimeout( function () {
    // Delays before changing the focus. Otherwise the focus ring will
    // appear on Firefox before the image has finished animating, which
    // looks broken.
    state.currentImage.buttonRef.focus( {
    preventScroll: true,
    } );
    // Resets the current image id to mark the overlay as closed.
    state.currentImageId = null;
    }, 450 );

  10. mehrazmorshed commented on Dec 24, 2025

    @mehrazmorshed
    ContributorAuthor

    Hello @ivanbachev, thanks for joining here.

    Hi @Mamaduka, What I have found till now:

    Error:

    Uncaught TypeError: can't access property "focus",
    r.currentImage.buttonRef is undefined
    

    Source:
    /wp-includes/js/dist/script-modules/block-library/image/view.min.js

  11. mehrazmorshed commented on Dec 24, 2025

    @mehrazmorshed
    ContributorAuthor

    According to my knowledge, here’s what happens:

    1. I click an image with “Enlarge on click” enabled
    2. WordPress opens its core lightbox
    3. WordPress locks scrolling
    4. WordPress stores a reference to the clicked image button (buttonRef)

    On close, WordPress tries to:

    1. Restore focus to the original image
    2. Unlock scrolling
  12. mehrazmorshed commented on Dec 24, 2025

    @mehrazmorshed
    ContributorAuthor

    On first page load, buttonRef is undefined, so this line fails:
    r.currentImage.buttonRef.focus()

    Because of the JS error:

    1. The close routine aborts
    2. Scroll-unlock code never runs
    3. Page remains stuck and unscrollable
  13. t-hamano commented on Dec 24, 2025

    @t-hamano
    Contributor

    here is a test page I created with the "Enlarge on click" enabled for the images.

    https://work.ivanbachev.com/test/

    @ivanbachev Are you using Fancybox? The library might be conflicting with the core lightbox feature.

    Image
  14. ivanbachev commented on Dec 24, 2025

    @ivanbachev

    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.

  15. DAreRodz commented on Jan 8, 2026

    @DAreRodz
    Contributor

    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.

  16. DAreRodz commented on Jan 9, 2026

    @DAreRodz
    Contributor

    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. 🤔

    I'm open to ideas about how to fix this. 🙂

  17. luisherranz commented on Jan 12, 2026

    @luisherranz
    Member
  18. removed
    [Status] Needs More Info
    on Jan 16, 2026
  19. aaronjorbin commented on May 19, 2026

    @aaronjorbin
    Member

    @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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Image[Type] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions