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

Router: Fix addition and removal of empty classnames #67378

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export function useHistory() {
! options.transition
) {
performPush();
return;
}

await new Promise< void >( ( resolve ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can probably remove the ?? '' fallback here

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you added it mostly to satisfy types there. Without it, TS will not be happy because classname could be undefined and classList.add() can't work with undefined. Happy to keep it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the early return will tell typescript that the classname is not empty there anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would have been the case if the calls were synchronous, but this is called in an async function.

Copy link
Member

Choose a reason for hiding this comment

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

Currently TypeScript cannot narrow down the type from string | undefined to undefined because the options.transition usage is inside a nested function (the promise constructor). In such a case it's harder to guarantee in what order code is executed.

But you could solve this by extracting most of the code out of the new Promise callback. The only part that needs to be async is the final transition.finished.finally call. Everything before it is sync.

Expand Down
Loading