Skip to content

Conversation

panteliselef
Copy link
Member

Description

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:

@panteliselef panteliselef self-assigned this May 31, 2024
Copy link

changeset-bot bot commented May 31, 2024

🦋 Changeset detected

Latest commit: 553cf16

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

This PR includes changesets to release 1 package
Name Type
@clerk/nextjs 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


if (windowNav) {
window.__clerk_internal_navFun = (to, opts) => {
registerNavigationType(name).fun = (to, opts) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
registerNavigationType(name).fun = (to, opts) => {
const registerNavigation = registerNavigationType(name)
registerNavigation.fun = (to, opts) => {

❓ Is there any issue changing to the above, so we don't always running the function as it is called many times?

registerNavigationType(name).promisesBuffer = [];
}
window.__clerk_internal_navPromisesBuffer.push(res);
registerNavigationType(name).promisesBuffer!.push(res);
Copy link
Member

Choose a reason for hiding this comment

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

❓ Does this need to be always push, shouldn't we calling push/replace depending the strategy? (Not exactly part of what the PR changes here but I'm curious)

cc @nikosdouvlis @desiprisg

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 separate from the concept of router push/replace, we're just pushing a promise onto the internal buffer here. I think this should be okay.

registerNavigationType(name).promisesBuffer = [];
}
window.__clerk_internal_navPromisesBuffer.push(res);
registerNavigationType(name).promisesBuffer!.push(res);
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 separate from the concept of router push/replace, we're just pushing a promise onto the internal buffer here. I think this should be okay.

Comment on lines 19 to 30
const registerNavigationType = (name: string) => {
if (!window.__clerk_internal_navigations) {
window.__clerk_internal_navigations = {};
}

if (!(name in window.__clerk_internal_navigations)) {
// @ts-ignore
window.__clerk_internal_navigations[name] = {};
}

return window.__clerk_internal_navigations[name];
};
Copy link
Member

Choose a reason for hiding this comment

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

nit, this feels more like a getter:

Suggested change
const registerNavigationType = (name: string) => {
if (!window.__clerk_internal_navigations) {
window.__clerk_internal_navigations = {};
}
if (!(name in window.__clerk_internal_navigations)) {
// @ts-ignore
window.__clerk_internal_navigations[name] = {};
}
return window.__clerk_internal_navigations[name];
};
const getClerkNavigationObject = (name: string) => {
window.__clerk_internal_navigations ??= {};
window.__clerk_internal_navigations[name] ??= {}
return window.__clerk_internal_navigations[name];
};

// as ClerkProvider might be unmounted and remounted during navigations
// If we use a ref, it will be reset when ClerkProvider is unmounted
window.__clerk_internal_navPromisesBuffer = [];
registerNavigationType(name).promisesBuffer = [];
Copy link
Member

Choose a reason for hiding this comment

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

Could be simplified with:

Suggested change
registerNavigationType(name).promisesBuffer = [];
registerNavigationType(name).promisesBuffer ??= [];

Can remove the wrapped if that way.

@panteliselef panteliselef enabled auto-merge (squash) June 4, 2024 19:21
@panteliselef panteliselef merged commit c5bd714 into main Jun 4, 2024
@panteliselef panteliselef deleted the elef/sdk-1782-debug-failing-navigationtestts-integration-test branch June 4, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants