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

refactor: affix FC rewrite #44408

Closed
wants to merge 6 commits into from

Conversation

rickythink
Copy link
Contributor

@rickythink rickythink commented Aug 24, 2023

[中文版模板 / 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 #39892
related #39900

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English refactor: (Affix) CC => FC
🇨🇳 Chinese refactor: (Affix) CC => FC

☑️ 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

🚀 Summary

🤖 Generated by Copilot at e58e7a8

This pull request refactors the Affix component and its test file to use modern React features and best practices. It replaces class components with functional components and hooks, and updates the test cases to use @testing-library/react. This improves code quality, performance, and reliability.

🔍 Walkthrough

🤖 Generated by Copilot at e58e7a8

  • Convert InternalAffix class component to functional component with forward ref and use React hooks to manage state, effects, and refs (link, link, link, link, link)
  • Simplify AffixProps interface by removing getInstance prop and move Affix component inside index.tsx file (link, link, link)
  • Remove unused import of InternalAffixClass from test file (link)
  • Remove getInstance prop from AffixMounter component and spread the rest of the props to Affix component (link)
  • Simplify test cases by using @testing-library/react helpers and checking the presence and style of the rendered elements, instead of accessing the internal state and ref of the InternalAffix component (link, link, link)

@stackblitz
Copy link

stackblitz bot commented Aug 24, 2023

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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2023

@li-jia-nan
Copy link
Member

@rickythink
Copy link
Contributor Author

are you still working on it ? I can continue your work if you don't have much time.

@li-jia-nan
Copy link
Member

are you still working on it ? I can continue your work if you don't have much time.

of course, i will finish it.

@rickythink rickythink closed this Aug 25, 2023
@li-jia-nan
Copy link
Member

Hello, would you like to reopen PR? I've been quite busy lately. If you're willing

@rickythink rickythink reopened this Aug 31, 2023
@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (1e0c3b8) 100.00% compared to head (ee2661c) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #44408   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          686       686           
  Lines        11647     11635   -12     
  Branches      3123      3120    -3     
=========================================
- Hits         11647     11635   -12     
Files Changed Coverage Δ
components/affix/index.tsx 100.00% <100.00%> (ø)

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

@rickythink rickythink changed the base branch from master to feature August 31, 2023 09:10
}
this.measure();
}
const status = React.useRef(AffixStatus.None);
Copy link
Member

Choose a reason for hiding this comment

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

This should all be controlled by useState instead of useRef

Copy link
Contributor Author

Choose a reason for hiding this comment

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

status and lastAffix are intermediate variables used in calculating the style, rather than being directly consumed by render. I think using useRef could help avoid unnecessary re-renders.

What do you think? I'm open to discussing this further.
Please let me know if you would like me to clarify or expand on anything.

Copy link
Member

Choose a reason for hiding this comment

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

@zombieJ ping

this.measure();
}
const status = React.useRef(AffixStatus.None);
const lastAffix = React.useRef(false);
Copy link
Member

Choose a reason for hiding this comment

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

This too

@li-jia-nan
Copy link
Member

马上发 5.9.0 了,能顺便上车么?

@li-jia-nan
Copy link
Member

ping

@li-jia-nan li-jia-nan mentioned this pull request Sep 27, 2023
20 tasks
@li-jia-nan li-jia-nan closed this Oct 7, 2023
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.

refactor Affix to function component
4 participants