-
Notifications
You must be signed in to change notification settings - Fork 391
fix(nextjs): Use separate buffers for each awaitable navigation type #3480
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(nextjs): Use separate buffers for each awaitable navigation type #3480
Conversation
🦋 Changeset detectedLatest commit: 553cf16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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]; | ||
}; |
There was a problem hiding this comment.
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:
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 = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be simplified with:
registerNavigationType(name).promisesBuffer = []; | |
registerNavigationType(name).promisesBuffer ??= []; |
Can remove the wrapped if that way.
…-integration-test
Description
Checklist
npm test
runs as expected.npm run build
runs as expected.Type of change