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] Fix the image is not loaded normally when the src in Ima… #1579

Merged
merged 1 commit into from
Apr 28, 2023

Conversation

YyumeiZhang
Copy link
Collaborator

…ge changes in lazy loading mode

中文模板 / Chinese Template

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Test Case
  • TypeScript definition update
  • Document improve
  • CI/CD improve
  • Branch sync
  • Other, please describe:

PR description

Fixes #1526

Changelog

🇨🇳 Chinese


🇺🇸 English

  • Fix: Fix the problem that the src of Image changes in lazy loading mode, and the image cannot be loaded normally.

Checklist

  • Test or no need
  • Document or no need
  • Changelog or no need

Other

  • Skip Changelog

Additional information

懒加载使用的是 IntersectionObserver, 原来的方式是在 preivew 层的 componentDidmout 去找到所有的 img元素,加入observe,此方式对 src 变化不友好(比如远程加载,修改src)

修改:

  1. new 出来的 IntersectionObserver在 Preview的constructor中,通过 context 传给子组件
  2. 在 Image 中 componentdidMout / componentdidUpdate 中查看 src 是否更新,将子组件注册给 observer

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9aa6c87:

Sandbox Source
pr-story Configuration
Semi Design: Simple Story Configuration

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.80 🎉

Comparison is base (a31dd2d) 88.00% compared to head (670cc00) 88.80%.

❗ Current head 670cc00 differs from pull request most recent head 9aa6c87. Consider uploading reports for the commit 9aa6c87 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1579      +/-   ##
==========================================
+ Coverage   88.00%   88.80%   +0.80%     
==========================================
  Files         433      433              
  Lines       25060    25063       +3     
  Branches     6291     6290       -1     
==========================================
+ Hits        22053    22257     +204     
+ Misses       3007     2806     -201     
Impacted Files Coverage Δ
packages/semi-ui/image/previewContext.tsx 100.00% <ø> (ø)
packages/semi-ui/image/image.tsx 95.50% <100.00%> (+19.55%) ⬆️
packages/semi-ui/image/preview.tsx 94.82% <100.00%> (+3.02%) ⬆️
packages/semi-ui/table/Table.tsx 88.34% <100.00%> (+0.45%) ⬆️

... and 14 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pointhalo pointhalo merged commit fb51ad5 into main Apr 28, 2023
@pointhalo pointhalo deleted the fix/image-images-change branch April 28, 2023 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] <Image> 远程获取Src, 懒加载机制会导致图片无法显示
3 participants