Skip to content

fix(images): wait for metadata before lazy-loading detection - #9727

Open
whoalin1 wants to merge 1 commit into
nextcloud:mainfrom
whoalin1:devin/1795943099-lazy-image-metadata
Open

whoalin1 wants to merge 1 commit into
nextcloud:mainfrom
whoalin1:devin/1795943099-lazy-image-metadata

Conversation

@whoalin1

Copy link
Copy Markdown

📝 Summary

Image placeholders are sized from attachment metadata, but the lazy-loading intersection observer was created before that metadata resolved. At that point every placeholder was still small enough to intersect the viewport, so all images were loaded immediately. Waiting for the metadata before creating the observer lets the placeholder reach its real size first, restoring deferred loading for off-screen images.

🖼️ Screenshots

Not applicable: this changes loading timing rather than visible UI.

🚧 TODO

  • None

🏁 Checklist

  • Code is properly formatted (npx eslint src/nodes/ImageView.vue src/tests/nodes/ImageViewLazyLoading.spec.ts passed)
  • Sign-off message is added to all commits
  • Tests passing and the changes are covered with tests
  • Documentation has been updated or is not required

Validation

  • Full Vitest suite passed: 81 test files, 1809 tests
  • Focused lazy-loading and accessibility specs passed after the final test placement: 2 files, 5 tests
  • vue-tsc --noEmit passed
  • Targeted ESLint passed

Not run: live Nextcloud validation or Playwright/Cypress end-to-end tests, because no live Nextcloud instance was available. Concrete manual validation steps: open a long Text document with several below-the-fold images on a remote server, confirm off-screen image previews are not requested immediately, then scroll and confirm each image loads as it approaches the viewport.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI tools
  • The AI-generated content was reviewed, comprehended and tested by a human

Implemented and validated with Devin assistance; the contributor reviewed and submits this pull request.

Image placeholders are sized from attachment metadata. Creating the intersection observer before that metadata resolves makes every placeholder look visible, so all images load immediately instead of lazily.

Assisted-by: Devin:adaptive

Signed-off-by: Man Alin <whoalin414@gmail.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@whoalin1
whoalin1 force-pushed the devin/1795943099-lazy-image-metadata branch from 77c0e7e to 4073585 Compare November 29, 2026 16:05

@mejo- mejo- left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the fix itself looks right. A few comments before merging:

  1. Move setupResizeObserver() before the await. Right now wrapperWidth is still 0 when the IntersectionObserver is created, so blurhashSize yields a negative width and the placeholder only gets its real height if the ResizeObserver callback happens to run first. Starting the ResizeObserver before awaiting the metadata measures the wrapper while the attachment list loads and removes that dependency:

    async mounted() {
            this.attachmentPromise = this.$attachmentResolver.resolve(this.src)
            this.setupResizeObserver()
            await this.loadAttachmentMetadata()
            if (this.isUnmounted) {
                    return
            }
            …
  2. Guard against unmounting during the await. If the image node is removed while the attachment list is still loading, beforeUnmount has already run, and mounted() then creates an IntersectionObserver that is never disconnected. A flag set in beforeUnmount (see code snippet as above) avoids that.

  3. Please replace the unit test with an end-to-end test. The Vitest spec mocks every node view prop and only checks when the IntersectionObserver constructor is called, so it's tied to the implementation rather than the behaviour. What we want to guarantee is that images below the fold aren't requested until they're scrolled into view. That needs real layout, so it belongs in Playwright, e.g. playwright/e2e/nodes/images.spec.ts. It needs the photos app to be installed in Playwright and enabled in the test in question. See e.g. how it's done for the files_lock app in Playwright.

@mejo-

mejo- commented Dec 1, 2026

Copy link
Copy Markdown
Member

@whoalin1 if you don't think you find time to address the review comments, you can also give me write permissions to the branch and I can take over.

This branch has not been deployed

No deployments
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.

Lazy image loading never defers: IntersectionObserver runs before the placeholder is sized

2 participants