Skip to content

Conversation

@GuillaumeRx
Copy link
Contributor

This PR refactors constructState to use an util function called isStatefulComponent that uses an array of component types that includes all the stateful components.

Fixes: #3235

@GuillaumeRx GuillaumeRx requested a review from a team as a code owner March 21, 2025 13:51
@GuillaumeRx GuillaumeRx changed the title chore: Refactor how stateful component check in constructState chore: Refactor stateful component check in constructState Mar 21, 2025
@codecov
Copy link

codecov bot commented Mar 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.98%. Comparing base (b923057) to head (4648526).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3251      +/-   ##
==========================================
- Coverage   94.98%   94.98%   -0.01%     
==========================================
  Files         511      511              
  Lines       11314    11300      -14     
  Branches     1754     1737      -17     
==========================================
- Hits        10747    10733      -14     
  Misses        567      567              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

*/
export function isStatefulComponent(component: { type: string }): component is {
type: StatefulComponentType;
props: Record<string, any>;
Copy link
Member

Choose a reason for hiding this comment

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

This is not ideal 🤔 Is this required?

Copy link
Member

Choose a reason for hiding this comment

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

Can we at least type it to be a union of the stateful component's props?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought it was required at some point but it isn't anymore apparently, removed

* @returns Whether the component is a stateful component.
*/
export function isStatefulComponent(component: { type: string }): component is {
type: StatefulComponentType;
Copy link
Member

Choose a reason for hiding this comment

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

Oh, does this then properly infer the props inside the if-clause in constructState? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have no issues in my IDE and when I look at the infered type its an union of the stateful components, I would like to send you a screenshot but I can't hit ctrl without the IDE context widow closing 😅

Copy link
Member

Choose a reason for hiding this comment

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

Awesome! 👍

@GuillaumeRx GuillaumeRx added this pull request to the merge queue Mar 24, 2025
Merged via the queue into main with commit 2ad12d1 Mar 24, 2025
173 checks passed
@GuillaumeRx GuillaumeRx deleted the gr/use-array-stateful-component branch March 24, 2025 11:18
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 constructState to use an array for stateful components

4 participants