Skip to content

ref(api): migrate auth-error navigation off browserHistory#115935

Merged
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/ref-api-migrate-auth-error-navigation-off-browserhistory
May 20, 2026
Merged

ref(api): migrate auth-error navigation off browserHistory#115935
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/ref-api-migrate-auth-error-navigation-off-browserhistory

Conversation

@evanpurkhiser
Copy link
Copy Markdown
Member

api.tsx is consumed outside React, so it can't use the useNavigate hook. Replace its two browserHistory.replace calls with a once-cell pattern:

  • api.tsx exports setApiNavigate(navigate) which stores a module-level ReactRouter3Navigate function.
  • The app bootstrap (static/app/main.tsx and static/gsAdmin/init.tsx) calls it alongside DANGEROUS_SET_REACT_ROUTER_6_HISTORY with a navigate function built from the router.
  • The auth-error handler invokes the stored navigate (or no-ops if not yet installed).

createReactRouter3Navigate(router) is added to useNavigate.tsx so any other non-React module that needs an imperative navigate can reuse the same helper.

@evanpurkhiser evanpurkhiser requested a review from a team as a code owner May 20, 2026 18:57
@evanpurkhiser evanpurkhiser enabled auto-merge (squash) May 20, 2026 18:57
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

📊 Type Coverage Diff

✅ No new type safety issues introduced. Coverage: 93.57%

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 655c66c. Configure here.

Comment thread static/app/api.tsx

if (EXPERIMENTAL_SPA) {
browserHistory.replace('/auth/login/');
apiNavigate?.('/auth/login/', {replace: true});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Auth replace drops scroll behavior

Low Severity

The auth-error paths now call apiNavigate with only {replace: true}, but the removed browserHistory.replace shim always passed preventScrollReset: true on replace. Session-expiry and member-limit redirects can now reset scroll differently than before.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 655c66c. Configure here.

Comment thread static/app/api.tsx

if (EXPERIMENTAL_SPA) {
browserHistory.replace('/auth/login/');
apiNavigate?.('/auth/login/', {replace: true});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tests skip api navigate setup

Medium Severity

Auth errors now depend on setApiNavigate, but the shared test render helper still only calls DANGEROUS_SET_REACT_ROUTER_6_HISTORY. Tests that mount App, register initApiClientErrorHandling, and hit a 401 will treat the error as handled while navigation no-ops.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 655c66c. Configure here.

`api.tsx` is consumed outside React, so it can't use the `useNavigate` hook. Replace its two `browserHistory.replace` calls with a once-cell pattern: api.tsx exports `setApiNavigate`, which the app bootstrap calls alongside `DANGEROUS_SET_REACT_ROUTER_6_HISTORY` with a `ReactRouter3Navigate`-compatible function built from the router. Adds `createReactRouter3Navigate(router)` in `useNavigate.tsx` so the same helper can be reused if other non-React modules ever need an imperative navigate.
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-api-migrate-auth-error-navigation-off-browserhistory branch from 655c66c to 0123c3b Compare May 20, 2026 19:25
@evanpurkhiser evanpurkhiser merged commit 881089c into master May 20, 2026
71 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-api-migrate-auth-error-navigation-off-browserhistory branch May 20, 2026 19:44
JonasBa pushed a commit that referenced this pull request May 21, 2026
`api.tsx` is consumed outside React, so it can't use the `useNavigate`
hook. Replace its two `browserHistory.replace` calls with a once-cell
pattern:

- `api.tsx` exports `setApiNavigate(navigate)` which stores a
module-level `ReactRouter3Navigate` function.
- The app bootstrap (`static/app/main.tsx` and
`static/gsAdmin/init.tsx`) calls it alongside
`DANGEROUS_SET_REACT_ROUTER_6_HISTORY` with a navigate function built
from the router.
- The auth-error handler invokes the stored navigate (or no-ops if not
yet installed).

`createReactRouter3Navigate(router)` is added to `useNavigate.tsx` so
any other non-React module that needs an imperative navigate can reuse
the same helper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants