Commit Graph
2 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
Alaister YoungandAlaister Young 23b93e9123 fix(studio): guard unsaved edits in TanStack (#51042)
Unsaved Edge Function, email template, and report edits block TanStack
navigation until the user chooses whether to leave. Keep editing
preserves the current route and draft, while Discard changes navigates
on the first click.

Depends on #51067 for the coordinated TanStack upgrade and published
history fix. This layer contains only the navigation behavior and its
regression coverage.

**Changed:**

- Select a native TanStack blocker through the Vite alias while
retaining the original Next hook for the fallback runtime.
- Preserve the latest navigation destination across repeated
cancel/confirm attempts and browser history traversal.

**Added:**

- Regression coverage for dirty state, cancel/confirm, unload protection
after traversal, encoded URLs, browser history, and the original Next
hook.

## To test

- In TanStack Studio, open a new Edge Function draft, edit its code, and
navigate to another section. Keep editing should preserve the URL and
code; retrying with Discard changes should navigate immediately.
- Repeat with browser Back and Forward. Cancel should restore the editor
URL; confirm should reach the intended history entry.
- Repeat an unsaved edit in an existing function or email template, then
discard it without saving.
- Undo an edit back to its original value and confirm navigation does
not prompt.
- In Next Studio, confirm dirty-editor cancellation and `/dashboard`
destinations still use the original guard.

Validation on the upgraded dependency graph: 73 focused guard,
navigation, URL and SSR tests passed, including 15 native TanStack cases
and four original Next guard cases. Studio typecheck, lint ratchet,
scoped ESLint, formatting and knip passed. The prerequisite's Next and
UI Library production builds passed; this layer changes only TanStack's
runtime alias and leaves the original Next guard source unchanged.

The restacked TanStack Vercel/skew production build passed with uploads
disabled. Local TanStack browser checks passed for repeated Keep
editing, ordinary native Back/Forward cancellation, one Discard toward
the latest breadcrumb destination, and Undo-to-clean navigation/reload.
Disposable local drafts were fully discarded without deploying or
editing existing functions. Native Next UI, multi-entry history jumps
and unload prompts were not browser-tested; dedicated guard tests cover
the latter two behaviors separately.



## Latest restack

Head `d6e7e7f23800319ceba15570057f5227a904debe` is stacked on #51067
head `e11cce3ad28bec3e0656e98da7d00a80810da30d`. The guard patch is
unchanged. The lower layer now skips unchanged table-filter URL sync to
preserve Forward history; its conditional reproduction is separate from
this guard change. Both PRs are mergeable after the trunk lockfile
conflict was resolved. All 56 focused router/filter/Next/guard checks,
Studio typecheck and scoped lint/format pass on the restack; all 20
required CI checks pass on both exact heads, including Next and TanStack
E2E, full Studio tests, builds, Docker and typecheck/lint.

The reviewer independently rechecked the earlier identical guard head
and did not reproduce the reported unguarded Back behavior. Both history
invocation methods showed the dialog, cancellation retained the draft
and restored its URL, and Discard completed navigation. No additional
guard change is justified by that retest; it does not establish the
cause of the earlier failed snapshot. Final-head browser coverage
remains distinct from this previous-head retest.

Both final Studio staging deployments are ready and serve TanStack/Nitro
assets. The upper sign-in page renders successfully; its unchanged guard
behavior was not additionally browser-retested on this final head.

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-10-19 21:22:40 +02:00