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): Revalidate environment on window focus for Keyless #4813

Merged

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Dec 19, 2024

Description

We have decided to open a new tab for developers to claim their application while on Keyless mode. This means we need to "listen" for the updated claimedAt property from environment when the developer has claimed and returns back to the tab where application is running.

Checklist

  • pnpm test runs as expected.
  • pnpm 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:

@panteliselef panteliselef requested a review from a team December 19, 2024 12:44
@panteliselef panteliselef self-assigned this Dec 19, 2024
Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 19, 2024 3:54pm

Copy link

changeset-bot bot commented Dec 19, 2024

🦋 Changeset detected

Latest commit: 27e9630

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

Comment on lines +36 to +48
const maxRetries = 2;

for (let i = 0; i < maxRetries; i++) {
const {
authConfig: { claimedAt },
} = await environment.fetch();

if (claimedAt !== null) {
forceUpdate();
break;
}
}
},
Copy link
Member Author

Choose a reason for hiding this comment

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

If you claim in dashboard and quickly switch the fetched environment will not reflect the claimed status. We are trying to fetch a couple of times until we get it.

* Revalidates environment on focus, highly optimized for Keyless mode.
* Attention: this is not a generic solution, and should not be used for revalidating environment inside UI components that are end-user facing (e.g. SignIn)
*/
function useRevalidateEnvironment() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently there is not pattern for "updating" the environment context after a component has already mounted. This is a quick hack to get this working for Keyless mode, which is a dev facing UI component.

@BRKalow BRKalow merged commit a52029c into main Dec 20, 2024
31 checks passed
@BRKalow BRKalow deleted the elef/actls-37-change-ui-links-for-api-keys-to-open-in-new-tab branch December 20, 2024 15:52
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.

6 participants