Skip to content

ref(charts): replace useRouter with specific hooks in useChartZoom#110094

Closed
evanpurkhiser wants to merge 15 commits into
masterfrom
evanpurkhiser-remove-userouter-use-chart-zoom
Closed

ref(charts): replace useRouter with specific hooks in useChartZoom#110094
evanpurkhiser wants to merge 15 commits into
masterfrom
evanpurkhiser-remove-userouter-use-chart-zoom

Conversation

@evanpurkhiser

Copy link
Copy Markdown
Member

Part of the React Router 6 cleanup — replaces useRouter() with specific hooks (useNavigate, useLocation, useParams, etc.)

Moves the "Test Monitor" button to the Verification section header as a
trailing item, and moves the "Suggest Assertions" button next to the
"+ Add Assertion" button in the assertions field.

Fixes [NEW-763](https://linear.app/getsentry/issue/NEW-763)
@evanpurkhiser evanpurkhiser requested a review from a team March 6, 2026 17:10
@evanpurkhiser evanpurkhiser requested review from a team as code owners March 6, 2026 17:10
@github-actions github-actions Bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Mar 6, 2026
@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

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

end: endFormatted,
},
router,
null,

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.

Passing null router breaks URL sync on chart zoom

High Severity

Passing null as the second argument to updateDateTime causes updateParams to early-return without updating URL query parameters (it checks if (!router) { return; }). Previously the legacy router object was passed, which allowed updateDateTime to sync the zoomed date range into the URL. Now the PageFiltersStore is updated but the URL never reflects the zoom, breaking URL-based state for any consumer using saveOnZoom (e.g. automationStatsChart.tsx). This means zoomed state is lost on page refresh and can't be shared via URL.

Fix in Cursor Fix in Web

Comment on lines +182 to 186
null,
{save: saveOnZoom}
);
}
},

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.

Bug: Passing a null router to updateDateTime prevents the chart's zoom state from being saved to the URL, breaking state persistence on refresh or navigation.
Severity: HIGH

Suggested Fix

Instead of passing null to updateDateTime, use the useNavigate hook to manually update the URL's query parameters. Construct a new query object containing the updated time range and use navigate to apply it. This will ensure the URL state remains synchronized with the page filter store, restoring persistence.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: static/app/components/charts/useChartZoom.tsx#L182-L186

Potential issue: In `useChartZoom.tsx`, the call to `updateDateTime` was changed to pass
`null` for the `router` argument. The `updateDateTime` function relies on this `router`
object to update the URL's query parameters via `updateParams`. When `router` is `null`,
`updateParams` returns early, and the URL is never updated. This causes a state mismatch
where the chart's zoom level is updated in the page filters store but not reflected in
the URL. Consequently, sharing links, using browser history, or refreshing the page will
result in the loss of the selected zoom range for components that use `saveOnZoom:
true`, such as issue detail charts and dashboard widgets.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/uptime/migrations/0055_backfill_2xx_status_assertion.py

for 0055_backfill_2xx_status_assertion in uptime

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

@github-actions github-actions Bot locked and limited conversation to collaborators Mar 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant