5 Commits
Author SHA1 Message Date
Alaister YoungandAlaister Young bbb0af65cb [FE-3106] (part 14) – refactor(studio): drop the dual-runtime shims and aliases (#53223)
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>
2026-11-17 17:49:20 +09:00
Charis 4d28d1a809 feat(studio): throw MalformedResponse for empty JSON GET bodies (#53182)
Follows supabase/supabase#53048. Part of
[FE-4772](https://linear.app/supabase/issue/FE-4772/error-core-tagged-error-types-and-rough-fault-classification-in).

## What

`normalizeEmptyBodyResponse` already tries to recover empty success
bodies (original body, then one `no-store` refetch). When a JSON `GET`
is still empty after that, it now throws `MalformedResponseError`
(reason `empty_body`) carrying `endpoint`, `method`, `requestId` and
status, instead of resolving with `{}`, which crashes components.

* Unchanged: 204s, `HEAD`, non-`GET` requests and empty non-JSON
responses keep the `Content-Length: 0` normalization.
* Reporting: the error rejects like a network failure, so React Query
gets the tagged instance and `reportQueryError` reports it once after
the last retry. The refetch diagnostics are attached as Sentry context,
and the standalone empty-body diagnostic event is skipped for this case
to avoid double reporting. Recovered cases still send the diagnostic.
* Routing: `MalformedResponse` moves to `SAMPLE_ALWAYS`. It is rare, and
while we confirm the recovery path is sufficient every unrecovered case
should be visible.
* An abort during recovery throws `RequestAborted`, not
`MalformedResponse`

## Notes

* Callers using `get()` directly outside React Query are not reported
automatically, same as network errors.
* No GET endpoint showed up as legitimately returning an empty JSON body
in the existing empty-body diagnostics.

## Testing

* `pnpm vitest run data lib components/interfaces/ErrorHandling state`
passes.
* Lint ratchet passes; `tsc` shows only a pre-existing error in
`packages/ui-patterns` (`InstructionBlocks.tsx`).
2026-11-10 09:39:10 -05:00
Ivan VasilovandClaude Opus 5.5 d69d8e1bc1 fix(studio): retry empty JSON GET responses without the HTTP cache (#53089)
## Problem

Successful GET requests sometimes reach Studio as a `200` with an empty
body. The fetcher turns these into `data: {}`, which doesn't match the
generated types, so components crash on nested reads such as
`pages[0].pagination.count`, `project.ref` and `features.vectorBuckets`.

Sentry diagnostics from #51123 show:

- Nearly all of these events come from Firefox.
- A `cache: 'no-store'` refetch of the same request returns a normal
body in more than 99% of events, so the API isn't sending empty
responses.
- The API sends no `Cache-Control` and a weak ETag, so Firefox
revalidates stored entries with `If-None-Match`. A browser cache or
revalidation bug is the most likely cause, but it isn't proven.

## Solution

When a successful response has an empty body,
`normalizeEmptyBodyResponse` now tries to recover it before falling back
to `{}`:

1. If only the clone used for the peek was empty, it reads the original
response and uses that body.
2. For JSON GET requests, it re-fetches once with `cache: 'no-store'`
and a new `X-Request-Id`, using plain `fetch` so the middleware can't
recurse. The retry uses the query's abort signal. A `2xx` response with
a body is returned to the caller.
3. Otherwise it keeps today's behavior: `Content-Length: 0`, which gives
`data: {}`.

The retry only covers GET requests with an `application/json` response,
so these stay unchanged:

- empty mutation responses
- the branch diff endpoint, which legitimately returns an empty
`text/html` body when there's no diff

The retry replaces the diagnostic probe, so a failure costs two requests
instead of three. The Sentry report gets a new `recovered_by` tag
(`original_body`, `refetch` or `none`), which will show whether the fix
works and whether the clone or the cache was at fault. The existing
`probe_*` fields keep their names, and Sentry still only receives body
lengths, never bodies.

### Why not bypass the cache for every request?

We chose not to send every request with `cache: 'no-store'`. It would
remove every `304 Not Modified` response, so unchanged data would come
back as a full `200` body each time and more data would go over the
network. The retry keeps HTTP caching for normal requests and only skips
the cache for requests that already came back empty.

## How to test

- `pnpm vitest run data/empty-body-diagnostics.test.ts
data/normalizeEmptyBodyResponse.test.ts` from `apps/studio` covers:
  - refetch recovery, and the secret value never reaching Sentry
- fallbacks when the retry is empty, rejects, returns non-2xx or is
aborted
  - no retry for non-JSON responses or non-GET requests
  - the original-body path
- After release, check the `recovered_by` tag on the "Empty response
body on successful API request" Sentry issues, and confirm the related
crash issues (`pagination is undefined`, `can't access property "ref"`)
trend down.

Part of FE-4665
Related to FE-4912

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-09 13:45:25 +01:00
Joshen Lim 60b51d74d5 Audit existing unit tests + Remove redundant ones (#52215)
## Context

_TLDR: Changes here speeds up unit tests on CI from ~14 minutes to ~3
minutes_ 😂
_TLDR 2: The file changes are solely only test files +
`studio-unit-tests.yml`_

We've currently got a lot of unit tests in the repository which while
great for coverage, hasn't been ideally written. There's a lot of
redundancy + overly specific tests that break easily, and our current
unit test takes about 15 minutes to run in the GHA per PR. Hence am
doing a audit clean up of all existing unit tests in the studio repo.

## Changes involved
- `.test.ts` files now run in `node`, `.test.tsx` in `jsdom`
- jsdom costs about 1s of setup per file. A `.ts` test that needs the
DOM opts in with `// @vitest-environment jsdom` (46 files do).
- Removed redundant and over-specific tests
- Duplicates are merged into `test.each`. Tests that only covered
libraries, existed for coverage, or asserted class names and snapshots
are deleted. 19 files are merged into a sibling or deleted.
- Fixed about 15 tests that couldn't fail 
- Examples: unawaited assertions, fixtures equal to the default, and a
`semverGte` test calling `semverLte`.
- Sped up the slowest files 
- Real sleeps are replaced with fake timers, `user.type` with paste, and
Radix option queries are scoped to the open listbox. For example,
`RestoringState` went from 18s to 0.3s and
`useTableEditorFiltersSort.navigation` from 20s to 3s.
- These ^ already shave down the unit tests time from 14 mins to 9 mins,
but am also sharding unit tests across 4 jobs to increase speed up
further which then shaves down time to 3 mins now
2026-10-23 18:51:27 +08:00
Ali Waseem ee3bec08af fix: intercept responses missing content lenght and re-add (#46885)
## 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?

Cases with cloudflares http/3 the content-length header is optional, so
in many cases we need to make sure in this case `openapi-fetch` can
safely parse this (i.e ignore when the body is empty and no header is
present)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **Bug Fixes**
* Fixed JSON parsing failures when successful API responses contain
empty bodies without `Content-Length` headers. Improves compatibility
with HTTP/3 and similar response types.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-12 11:16:12 -06:00