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: Typography copyable not refreshing text to be copied #48075 #48332

Closed
wants to merge 3 commits into from

Conversation

LingJinT
Copy link
Contributor

@LingJinT LingJinT commented Apr 8, 2024

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

close #48075

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English fix Typography Unable to get the latest text while copying
🇨🇳 Chinese 修复 Typography 复制时无法拿到最新文本

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

stackblitz bot commented Apr 8, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Apr 8, 2024

👁 Visual Regression Report for PR #48332 Failed ❌

🎯 Target branch: master (8fc4fa0)
📖 View Full Report ↗︎

Image name Expected Actual Diff
steps-label-placement.compact.css-var.png master: 8fc4fa06c85e3184cac2b78d9fce5d9a8bf8ef00 current: pr-48332 diff
steps-label-placement.dark.css-var.png master: 8fc4fa06c85e3184cac2b78d9fce5d9a8bf8ef00 current: pr-48332 diff
steps-label-placement.default.css-var.png master: 8fc4fa06c85e3184cac2b78d9fce5d9a8bf8ef00 current: pr-48332 diff
steps-progress-debug.dark.css-var.png master: 8fc4fa06c85e3184cac2b78d9fce5d9a8bf8ef00 current: pr-48332 diff
steps-progress.compact.css-var.png master: 8fc4fa06c85e3184cac2b78d9fce5d9a8bf8ef00 current: pr-48332 diff

Check Full Report for details

Copy link
Contributor

github-actions bot commented Apr 8, 2024

Preview is ready

@LingJinT LingJinT changed the title Fix: Typography copyable not refreshing text to be copied #48075 fix: Typography copyable not refreshing text to be copied #48075 Apr 8, 2024
Copy link

codesandbox-ci bot commented Apr 8, 2024

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.

Copy link

codecov bot commented Apr 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (8fc4fa0) to head (25db6bc).

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #48332   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          744       744           
  Lines        12861     12861           
  Branches      3365      3365           
=========================================
  Hits         12861     12861           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@crazyair
Copy link
Member

crazyair commented Apr 8, 2024

https://github.com/ant-design/ant-design/blob/master/components/typography/demo/copyable.tsx#L23

text 还有方法的情况,增加 copyConfig 就会不管操作什么,都会重新 render

@LingJinT
Copy link
Contributor Author

LingJinT commented Apr 8, 2024

@crazyair 已改成copyConfig.text

@crazyair
Copy link
Member

crazyair commented Apr 8, 2024

text: () => 'xxx' 用户如果这样用,text 方法会导致 rerender

@crazyair
Copy link
Member

crazyair commented Apr 8, 2024

copy、edit、expand 等是否可以从 miscDeps 移除,这个才是修改的正确方式 @zombieJ

@LingJinT
Copy link
Contributor Author

LingJinT commented Apr 8, 2024

这种情况是不是需要用户自己保证?还是有什么好的办法可以组件内部处理掉?

@crazyair
Copy link
Member

crazyair commented Apr 8, 2024

如果 text 包裹 useCallback,就不会重新 render const text = useCallback(() => count: ${count}, [count]);
所以 copyConfig.text 的方式也可以。
补充个单测吧

@crazyair
Copy link
Member

crazyair commented Apr 8, 2024

@zombieJ 后续可以优化,copy 元素从 Ellipsis 抽离下,避免 copy.text() 会导致 Ellipsis rerender

@zombieJ zombieJ mentioned this pull request Apr 9, 2024
20 tasks
@@ -487,7 +487,7 @@ const Base = React.forwardRef<HTMLElement, BlockProps>((props, ref) => {
width={ellipsisWidth}
onEllipsis={onJsEllipsis}
expanded={expanded}
miscDeps={[copied, expanded, copyLoading]}
miscDeps={[copied, expanded, copyLoading, copyConfig.text]}
Copy link
Member

Choose a reason for hiding this comment

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

miscDeps is used for trigger measure ellipsis update. This will make useless re-render. I patched in onCopy side, pls help to check: #48347

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.

Typography copyable not refreshing text to be copied
3 participants