Skip to content

fix(clerk-js): Replace generic ComponentContext with component-specific contexts - #4486

Merged
dstaley merged 7 commits into
mainfrom
ds.feat/rm-component-context
Nov 6, 2024
Merged

fix(clerk-js): Replace generic ComponentContext with component-specific contexts#4486
dstaley merged 7 commits into
mainfrom
ds.feat/rm-component-context

Conversation

@dstaley

@dstaley dstaley commented Nov 5, 2024

Copy link
Copy Markdown
Member

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:

@changeset-bot

changeset-bot Bot commented Nov 5, 2024

Copy link
Copy Markdown

🦋 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
[],
);

if (!context || context.componentName !== 'SignUp') {

Copy link
Copy Markdown
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 thread packages/clerk-js/src/ui/utils/test/createFixtures.tsx Outdated
Comment on lines +354 to 359
const { componentName, ...ctx } = context;

return {
...ctx,
componentName,
};

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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!

@jacekradko jacekradko left a comment

Copy link
Copy Markdown
Contributor

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
@dstaley
dstaley deleted the ds.feat/rm-component-context branch November 6, 2024 23:47
wobsoriano pushed a commit that referenced this pull request Feb 8, 2025
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