## Problem
We need simple counts of every pageview and every global crash for SLO
monitoring. These counts need to go to observability ingest, not to
Sentry, etc., so they can be part of our Grafana dashboards pipeline.
## Solution
- `usePageviewMetric` sends one `pageview` event on first load
(hydration) and on every client-side navigation that changes the
pathname. Changes to only the query string or hash do not count.
- A `global_crash` event is sent once when the global crash screen is
shown. That covers both the root `ErrorBoundary` and the root route
`errorComponent`. Chunk-load errors that are recovered by an automatic
reload are not counted, which matches what is reported to Sentry.
- Both are gated by a new `IS_STAGING_OR_PREVIEW` constant. It is false
on production, local development, self-hosted and Nimbus.
- The request is a fire-and-forget `fetch` with `keepalive: true` and
`credentials: 'omit'`. It uses a `text/plain` body, so there is no CORS
preflight. Errors are swallowed.
- The endpoint origin is added to `connect-src` for all platform
environments, because production will need it later. No other CSP
directive changes.
## Review instructions
1. Open the Studio preview deployment for this PR with the network panel
open.
2. Load any page. See one `POST /api/metrics` request that returns 204.
3. Navigate to another page. See one more request.
4. Change only a query parameter (for example a table filter). See no
new request.
## Checklist
Check all before review:
- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
Part 2 of a 6-PR stack migrating all `next/router` and
`next/compat/router` imports in `apps/studio` onto TanStack Router hooks
and removing the router shims.
| Part | PR | Scope |
| --- | --- | --- |
| 1 | #54053 | Core navigation helpers, `hooks/**`, `lib/**`,
`data/prefetchers/**` |
| **2** | **#54054 ← this PR** | **`components/ui/**`** |
| 3 | #54055 | `components/layouts/**` and `state/tabs.tsx` |
| 4 | #54056 | Database, Branching, Compute, Edge Functions, Explorer,
SQL Editor, Storage, Table Editor |
| 5 | #54057 | Remaining `components/interfaces/**` and
`QueryInsightsTable` router events |
| 6 | #54058 | Remove `next/router` & `next/compat/router` shims,
`_router-events.ts`, Vite aliases, and test mocks |
Migrates all 15 `apps/studio/components/ui/**` files off `next/router`.
**Changed:**
- Replaced `useRouter` across `AIAssistantPanel` (`AIAssistant`,
`ModelSelector`), `Charts/ComposedChartHandler`, `EditorPanel`,
`ErrorBoundary` (`ClientSideExceptionHandler`,
`GlobalErrorBoundaryState`, `InsertBeforeRemoveChildErrorHandler`),
`GlobalShortcuts/ShortcutsReferenceSheet`, `HelpPanel`
(`HelpOptionsList`, `HelpPanel`), `ProductMenu/ProductMenuShortcuts`,
`QueryBlock/EditQueryButton`, and `ResourceExhaustionWarningBanner` with
TanStack's `useNavigate`, `useLocation`, `useRoutePattern`, and
`useParams` from `common`
- Updated `AIAssistant.test.tsx`, `HelpOptionsList.test.tsx`, and
`ProductMenuShortcuts.test.tsx` to use TanStack Router instead of
`next/router` mocks
**Simplified:**
- `EditQueryButton` and `ShortcutsReferenceSheet` match against
`useRoutePattern()` instead of the real pathname, as `router.pathname`
did before. A ref or slug containing `sql` or `advisors` no longer
misfires.
- Removed the unused `restrictToRoutes` field from
`ResourceExhaustionWarningBanner` (no warning sets it)
- `AIAssistant` clears the handoff param with `navigate({ to: '.' })`,
dropping a pathname subscription and an `AnyRouter` cast
- `ProductMenuShortcuts` inlines its handler (`useShortcut` always calls
the latest callback)
- Moved the `AdvisorsNavigationShortcuts.test.tsx` fix into this PR so
it passes on its own
- Tests use the shared `createTestRouter` and `customRender` router
Addresses
[FE-5109](https://linear.app/supabase/issue/FE-5109/replace-the-nextrouter-shims-with-tanstack-router-hooks)
## To test
- [ ] AI Assistant panel links, model selector navigation, and "Edit in
SQL Editor" (`EditQueryButton`) navigate cleanly
- [ ] Keyboard shortcuts in `ProductMenuShortcuts` and the shortcuts
reference sheet (`?`) match the active section and navigate as expected
- [ ] Error boundary recovery ("Reload page" / navigation actions) and
Help panel links still work
- [ ] Resource exhaustion warning banner matches project routes as
before
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
Drops the remaining Next-era shims and aliases that only existed for the
dual runtime (FE-3106). Part 14 of the stack.
**Depends on:** #53222
**Changed:**
- ~45 files – import Sentry from `@sentry/react` directly instead of the
aliased `@sentry/nextjs`
- `hooks/ui/usePreventNavigationOnUnsavedChanges.ts` – is now the
TanStack `useBlocker` implementation (previously swapped in by a Vite
alias)
- `components/interfaces/App/RouteValidationWrapper.tsx` – `next/router`
→ `useNavigate` + the leaf route's `fullPath` (`/project/$ref/sql/$id`)
for the exempt-route and last-visited checks
- `hooks/misc/withAuth.tsx` – no `getLayout` forwarding
- `TemplateEditor.test.tsx` – renders inside a router for the
unsaved-changes blocker
**Removed:**
- `compat/sentry-nextjs.ts` and its Vite alias, the
`usePreventNavigationOnUnsavedChanges` alias and Next hook,
`types/next.ts` (`NextPageWithLayout`), the `@sentry/nextjs` dependency
The `compat/next/*` shims for `link`, `router`, `head`, `image`,
`navigation`, `dynamic` and `script` stay: about 300 components outside
`routes/**` still import them.
Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).
## To test
- Trigger an error (e.g. a failing query) – it reaches Sentry as before
- Edit an email template or edge function and navigate away – the
unsaved-changes prompt appears
- Open an org you don't belong to – toast and redirect home; open a SQL
snippet, leave and come back – last snippet is restored
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
When a lazy-loaded JS/CSS chunk fails to load (flaky or mobile
networks), users land on the global error screen and stay there until
they refresh by hand. This reloads the page once instead, in both
runtimes.
A reload is the only reliable recovery: WebKit (Safari and every iOS
browser) caches a failed module fetch in the document's module map, so
every later `import()` of that URL fails instantly until the page is
replaced. TanStack's `lazyRouteComponent` already reloads once for route
chunks, but it keys its guard on the error message, and Safari's message
("Importing a module script failed.") is the same for every chunk and
survives reloads, so after the first time in a tab it never reloads
again. Non-route lazy imports (`next/dynamic`, `React.lazy`, Monaco) had
no recovery at all.
**Added:**
- `lib/chunk-load-error.ts`: `isChunkLoadError` (Chrome, Firefox,
WebKit, webpack `ChunkLoadError` and Vite's CSS preload wording) and a
reload guard
- The guard is time-based (`sessionStorage`, 30s window), not
message-based: a second failure within 30s of a reload shows the normal
error screen instead of looping. It's also capped at 3 automatic reloads
per tab, and the guard is read back after writing it. If storage is
unavailable, or silently drops the write, it never reloads
- Unit tests for every message form, the guard window, the per-tab cap,
and broken, missing or write-dropping storage
**Changed:**
- The global error boundary in `pages/_app.tsx` and `routes/__root.tsx`,
plus TanStack's root `errorComponent`, reload once for chunk-load errors
and render nothing while the reload is in flight. Fallbacks only peek at
the guard during render; the reload is claimed after commit
(`useChunkLoadReload`), so a discarded render can't use up the guard
- Chunk-load errors that a reload recovers from are no longer reported
to Sentry. One that recurs within the guard window (the user actually
saw the error screen) is reported, tagged `chunkLoadError: true`
No `vite:preloadError` listener: it also fires for hover/intent route
preloads, so reloading on it would refresh the page under someone who
only hovered a link.
## To test
- On the preview, open DevTools → Network, block one route chunk URL
(e.g. the SQL editor's), then navigate to it: the page reloads once and
recovers (unblock after the reload), with no error screen flash
- Keep the chunk blocked: after the one reload you get the normal error
screen, not a reload loop
- Repeat after 30s+ in the same tab: it reloads again
- Sentry: the recovered reload sends no event; the persistent failure
sends one tagged `chunkLoadError`
- Normal navigation and genuine non-chunk errors behave as before
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
## Context
This is largely just a mechanical change here:
Opting to use lucide icons with the `Icon` suffix across all icon
imports within `studio`
- so that it’s clearer which components are icons + reduces the
possibility of name collision with our own components
- e.g <User /> vs <UserIcon />
Also added a eslint rule for this:
<img width="1069" height="167" alt="image"
src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc"
/>
And updated `AGENTS.md` as such:
```
Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced).
```
## Problem
AlertError forces a vertical layout whenever additional actions are
supplied, even when the caller explicitly requests horizontal or
responsive layout. Stripe Sync Engine's uninstall error is one affected
call site, the other was Pipelines as demoed in #51311.
## Solution
Honour an explicit layout. Preserve the existing defaults: vertical with
additional actions, responsive otherwise.
Replace the standalone Contact support action with an InlineLink in the
contact support prose, preserving support form context and breadcrumb
capture. Keep custom actions such as Retry. If instructions are hidden
or custom prose omits contact support, retain a separate inline support
link. With `hideContactSupport`, show no support link and shorten the
default instructions to “Try refreshing your browser.” Custom
descriptions remain unchanged. The local Pipelines configuration error
explicitly hides support. Add the explicit responsive layout at the
Pipelines call site.
| Before | After |
| --- | --- |
| <img width="914" height="426" alt="CleanShot 2026-10-07 at 17 51
20@2x"
src="https://github.com/user-attachments/assets/6cbddfee-97f5-4a7a-bafa-7b5dfd6ab8bf"
/> | <img width="916" height="422" alt="CleanShot 2026-10-07 at 18 26
06@2x"
src="https://github.com/user-attachments/assets/a21952a6-1c1a-437c-af73-c5736f33fd98"
/> |
| <img width="1566" height="384" alt="CleanShot 2026-10-07 at 18 28
07@2x"
src="https://github.com/user-attachments/assets/bdc2a043-421f-4c22-9bd3-37859c6e85c7"
/> | <img width="1568" height="308" alt="CleanShot 2026-10-07 at 18 26
58@2x"
src="https://github.com/user-attachments/assets/da0f2c6a-6254-4196-944b-5665e87b3c3c"
/> |
## Review instructions
1. In a fresh local test project with no existing `stripe` schema, run
this in SQL Editor:
```sql
begin;
create schema stripe;
comment on schema stripe is
'{"status":"uninstall error","errorMessage":"Local layout test: uninstallation failed"}';
commit;
```
2. Open **Integrations → Stripe Sync Engine → Overview** and reload.
Check **Failed to uninstall Stripe Sync Engine** at wide and narrow
widths, including **Retry uninstallation** and the inline **contact
support** link. Do not click Retry: it invokes the real uninstall
operation.
3. Remove the empty fixture with `drop schema stripe restrict;`.
4. Block the Pipelines source-status request and resize the page: Retry
uses the responsive layout.
5. AlertError callers without an explicit layout should retain their
existing presentation. Confirm default and custom contact support prose
use an inline link, with no standalone support action. Hidden
instructions and custom prose without contact support retain an inline
fallback. With `hideContactSupport`, the default prose is “Try
refreshing your browser.” and no support link appears; custom
descriptions remain unchanged.
6. Automated regression coverage checks that an explicit responsive
layout survives additional actions, and that hiding support removes the
default support wording while preserving custom descriptions.
---------
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Follow-up to #48344: collapses the two resolution paths for the
Admonition module into one.
`src/admonition.tsx` was a back-compat shim re-exporting
`src/Admonition/`. Two ways to resolve one module is exactly what
produced the macOS self-import bug fixed in #48344, and the local
typecheck errors that #48374 worked around. This removes the shim and
standardizes on the PascalCase subpath, matching every other export in
the package.
**Changed:**
- Codemodded all 246 `ui-patterns/admonition` imports to
`ui-patterns/Admonition` (240 `.tsx`, 5 `.mdx`, 1 `.ts` across studio,
docs, www, design-system, and lite-studio)
- Pointed the 5 internal `'../admonition'` imports back at the
`'../Admonition'` directory
**Removed:**
- `packages/ui-patterns/src/admonition.tsx`, and its `./admonition`
entry in the exports map (regenerated with `pnpm gen:exports`)
## To test
- `grep -r "ui-patterns/admonition" --include='*.ts*'` → no hits
- `pnpm test:case-hazards` → passes
- `pnpm typecheck` → all 15 tasks green
- `pnpm --filter studio run lint:ratchet` → passes
- `pnpm --filter ui-patterns vitest run src/Admonition` → 11 tests pass
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Standardized Admonition component imports across the application and
documentation.
* Improved compatibility with case-sensitive environments by using the
canonical component path.
* Removed the legacy Admonition import entry point.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
## Problem
We now export components under a subpath in ui-patterns to avoid barrel
files as they slow down every tools (from IDE to linters, etc.) and may
also affect bundles our users have to download.
## Solution
- Remove the UI patterns index file
- Fix invalid impors
## Problem
Our `<Button>` component breaks the default `button` contract by
redefining the `type` prop to set its variant (`primary`, `default`,
etc) instead of the button type (`submit`, `button`, etc).
This is confusing and forces to write more code when using it with
shadcn components that expect/inject the standard button props.
## Solution
- rename the `type` prop to `variant`
- rename the `htmlType` prop to `type`
- propagate the changes where necessary
- format code
## How to test
As this is just prop renaming, if it builds it's ok
---------
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.
YES
## What kind of change does this PR introduce?
- Noticing our code we have many patterns of calling localstorage and
handling those errors
- We should add those in a single well tested file
- Handle those errors in the singleton which makes it easier for us to
debug customer issues. Logger is outputing local storage warnings for
feature we expose
- Side effect of this is random crashes on studio when local storage
isn't available or handled correctly
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Improved browser storage handling across the app for more reliable
persistence and graceful behavior in restricted or non-browser
environments (settings, previews, charts, tabs, sign-in/session flows,
integrations, and UI state).
* **New Features**
* Introduced a safe storage layer to standardize and harden
local/session persistence.
* **Tests**
* Added comprehensive tests covering the new safe storage behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->