next.js
next.js copied to clipboard
Null safe window history state references
For Maintainers
Fixes MSAL issue: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/6851
What?
Make the reference to window.history.state.__PRIVATE_NEXTJS_INTERNALS_TREE in applyUrlHistoryPushReplace null safe.
Why?
All other references in app-router.tsx include checks that would prevent accessing window.history.state when it's null.
applyUrlFromHistoryPushReplace is the only spot missing that type of check.
Current behavior causes exceptions with MSAL redirect handling.
Redirects in MSAL have been broken since windowHistorySupport went live with 14.0.5.
How?
Add an extra null check when referencing: window.history.state.__PRIVATE_NEXTJS_INTERNALS_TREE