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(clerk-js): Replace generic ComponentContext with component-specific contexts #4486

Merged
merged 7 commits into from
Nov 6, 2024

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Nov 5, 2024

Description

This PR replaces the generic ComponentContext provider with component-specific versions.

The biggest benefit to this PR is reducing the amount of "magic" happening, and moving us towards a more typical approach to handling Context within React applications. Instead of a generic Context that can be one of 11 different types, we now have 11 separate Contexts. This adds a bit more safety in that there won't be an instance where the SignIn component tries to access the Context of another component (which we currently guard against via a runtime check of componentName). Ultimately it's a small change intended to simplify complexity and increase readability.

Progress:

  • SignIn
  • SignUp
  • UserProfile
  • UserVerification
  • UserButton
  • OrganizationSwitcher
  • OrganizationList
  • OrganizationProfile
  • CreateOrganization
  • GoogleOneTap
  • Waitlist

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Nov 5, 2024

🦋 Changeset detected

Latest commit: fdcbbed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dstaley dstaley marked this pull request as draft November 5, 2024 01:40
@dstaley dstaley marked this pull request as ready for review November 6, 2024 17:12
@@ -74,6 +148,12 @@ export const useSignUpContext = (): SignUpContextType => {
[],
);

if (!context || context.componentName !== 'SignUp') {
Copy link
Member Author

Choose a reason for hiding this comment

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

For simplicity we retain the componentName check. In a future PR we can refactor this out since we always know that we're accessing a value from the expected Context.

Comment on lines +354 to 359
const { componentName, ...ctx } = context;

return {
...ctx,
componentName,
};
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this could be simplified to just

Suggested change
const { componentName, ...ctx } = context;
return {
...ctx,
componentName,
};
return context;

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah this is left over from the previous implementation. When I refactor this to split these contexts into separate files and remove the componentName check I'll clean this up as well!

Copy link
Member

@jacekradko jacekradko left a comment

Choose a reason for hiding this comment

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

lgtm

@dstaley dstaley merged commit e25381d into main Nov 6, 2024
23 checks passed
@dstaley dstaley deleted the ds.feat/rm-component-context branch November 6, 2024 23:47
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.

4 participants