mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Removes the remaining Next.js dependencies, compatibility shims, test
mocks, ESLint/TypeScript presets, and webpack/Next workarounds from
Studio following the TanStack Start migration.
Addresses FE-3107.
**Removed:**
- `next` and `next-router-mock` from `apps/studio/package.json` (and
updated `pnpm-lock.yaml`)
- Orphaned `apps/studio/compat/next/script.tsx` shim, `script.test.tsx`,
`compat/**` knip entry, and `nextCompat()` / `ssr.noExternal` `/^next/`
plumbing from `apps/studio/vite.config.ts`
- `apps/studio/tests/lib/route-mock.ts` and all `next-router-mock`
setup/imports across `tests/vitestSetup.ts`,
`tests/lib/custom-render.tsx`, and 12 test files
- `apps/studio/tests/pages/` directory (moved the 3 remaining tests to
`components/interfaces/Organization/Organization.utils.test.ts` and
`apps/studio/tests/routes/`)
- Unused `'use client'` directives across 23 Studio files
- Next.js/webpack workarounds: `graphiqlViteWorkers()` in
`vite.config.ts`, webpack `import.meta.glob` `try/catch` fallback in
`ConnectStepsSection.tsx`, shell `NODE_ENV=test` override in
`vite.config.ts` / root `package.json` / `studio-e2e-test.yml`, Next
`getPathMatch` and `_next` passthrough in `redirects.shared.*`,
`window.next?.router` check in `monaco-graphiql-coexistence.spec.ts`,
and unused `ANALYZE` env var in `apps/studio/turbo.jsonc`
- Next-only Sentry/chunk-load filters (`NEXT_NOT_FOUND`,
`NEXT_REDIRECT`, Next `/org/[slug]/` regex, `/app:\/\//`, dead
`includeThirdPartyErrorFilter` plumbing, webpack chunk error regex) and
stale Next/Pages Router comments, docs, and `#__next` CSS selector
**Changed:**
- `apps/studio/eslint.config.cjs`: switched from
`eslint-config-supabase/next` to the new `eslint-config-supabase/react`
preset (dropping `@next/next/no-img-element: off`, keeping `.next` /
`next-env.d.ts` ignored for local checkouts with stale pre-migration
build artifacts)
- `apps/studio/tsconfig.json`: extends `tsconfig/base.json` directly
instead of `tsconfig/nextjs.json` (identical resolved compiler options)
- `apps/studio/.github/eslint-rule-baselines.json`: pruned 33 stale
`pages/...` and `types/next.ts` entries without changing any rule
thresholds
- `apps/studio/tests/lib/custom-render.tsx`: backed
`TestFrameworkProvider` with TanStack Router instead of
`next-router-mock`
-
`apps/studio/components/interfaces/Integrations/GraphQL/GraphiQLTab.tsx`:
imports `graphiql/setup-workers/vite` directly
- `apps/studio/styles/globals.css`: replaced `@source
'../pages/**/*.{js,ts,jsx,tsx}'` with `@source
'../routes/**/*.{js,ts,jsx,tsx}'`
- `apps/studio/turbo.jsonc`: declared `"NEXT_PUBLIC_*"` in
`tasks.build.env` now that Turborepo infers `nitro` instead of `nextjs`
-
`apps/studio/components/interfaces/Organization/Organization.utils.ts`:
narrowed `buildOrgUrl`'s `slug` parameter to `string[] | undefined`
**Added:**
- `packages/eslint-config-supabase/shared.js` and
`packages/eslint-config-supabase/react.js` (plus `presets.test.ts`),
decoupling non-Next React apps from `eslint-config-next` with verified
zero non-`@next/*` rule drift while keeping
`eslint-config-supabase/next` unchanged for the Next.js apps
## To test
- Run `pnpm --filter eslint-config-supabase run test` and confirm preset
parity tests pass
- Run `pnpm --filter studio run lint`, `pnpm --filter studio run
lint:ratchet`, `pnpm --filter studio run typecheck`, `pnpm knip
--workspace apps/studio`, and `pnpm --filter studio run test`
- Run `pnpm --filter studio run build` and verify the production build,
prerendered routes, chunk-cycle check, and GraphiQL web workers succeed
- Smoke-test Studio locally (`pnpm dev:studio`): verify GraphiQL loads
cleanly, ConnectSheet framework steps render, and Tailwind styles on
route pages are intact
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
222 lines
7.3 KiB
TypeScript
222 lines
7.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
buildPathWithParams,
|
|
buildSignUpReturnPath,
|
|
DEFAULT_FALLBACK_PATH,
|
|
DEFAULT_SIGNUP_RETURN_PATH,
|
|
getReturnToPath,
|
|
getSignInQuery,
|
|
getSignUpReturnTo,
|
|
validateReturnTo,
|
|
} from './gotrue'
|
|
|
|
describe('getSignInQuery', () => {
|
|
it('drops returnTo when it is exactly /new and keeps other params', () => {
|
|
expect(getSignInQuery({ returnTo: '/new', destination: 'cli' })).toEqual({ destination: 'cli' })
|
|
expect(getSignInQuery({ returnTo: ['/new', '/other'] })).toEqual({})
|
|
})
|
|
|
|
it('keeps /new with a query string', () => {
|
|
expect(getSignInQuery({ returnTo: '/new?foo=bar' })).toEqual({ returnTo: '/new?foo=bar' })
|
|
})
|
|
|
|
it('keeps other destinations and params', () => {
|
|
const query = { returnTo: '/project/ref', destination: 'cli' }
|
|
expect(getSignInQuery(query)).toEqual(query)
|
|
})
|
|
|
|
it('returns the query unchanged when there is no returnTo', () => {
|
|
expect(getSignInQuery({})).toEqual({})
|
|
expect(getSignInQuery({ method: 'github' })).toEqual({ method: 'github' })
|
|
})
|
|
})
|
|
|
|
describe('getSignUpReturnTo', () => {
|
|
it('defaults to /new when returnTo is missing', () => {
|
|
expect(getSignUpReturnTo(undefined)).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
expect(getSignUpReturnTo('')).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
})
|
|
|
|
it('rewrites /org and /organizations to /new', () => {
|
|
expect(getSignUpReturnTo('/org')).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
expect(getSignUpReturnTo('/organizations')).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
})
|
|
|
|
it('rewrites org list paths while preserving query params', () => {
|
|
expect(getSignUpReturnTo('/org?foo=bar')).toBe('/new?foo=bar')
|
|
expect(getSignUpReturnTo('/organizations?foo=bar')).toBe('/new?foo=bar')
|
|
})
|
|
|
|
it('preserves explicit destinations including invite paths', () => {
|
|
expect(getSignUpReturnTo('/join?token=abc')).toBe('/join?token=abc')
|
|
expect(getSignUpReturnTo('/project/ref')).toBe('/project/ref')
|
|
})
|
|
|
|
it('uses the first value when returnTo is an array', () => {
|
|
expect(getSignUpReturnTo(['/join?token=abc', '/other'])).toBe('/join?token=abc')
|
|
expect(getSignUpReturnTo(['/org'])).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
expect(getSignUpReturnTo(['/organizations'])).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
})
|
|
})
|
|
|
|
describe('buildSignUpReturnPath', () => {
|
|
it('defaults to /new when returnTo is missing', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '' }
|
|
|
|
expect(buildSignUpReturnPath(undefined)).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
})
|
|
|
|
it('rewrites /org and /organizations to /new', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '' }
|
|
|
|
expect(buildSignUpReturnPath('/org')).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
expect(buildSignUpReturnPath('/organizations')).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
})
|
|
|
|
it('rewrites org list paths while preserving query params', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '' }
|
|
|
|
expect(buildSignUpReturnPath('/org?foo=bar')).toBe('/new?foo=bar')
|
|
expect(buildSignUpReturnPath('/organizations?foo=bar')).toBe('/new?foo=bar')
|
|
})
|
|
|
|
it('preserves invite returnTo paths', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '' }
|
|
|
|
expect(buildSignUpReturnPath('/join?token=abc')).toBe('/join?token=abc')
|
|
})
|
|
|
|
it('falls back to /new for invalid returnTo values', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '' }
|
|
|
|
expect(buildSignUpReturnPath('https://evil.com')).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
expect(buildSignUpReturnPath('//evil.com')).toBe(DEFAULT_SIGNUP_RETURN_PATH)
|
|
})
|
|
|
|
it('strips returnTo from the current location search params', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '?returnTo=/org&foo=bar' }
|
|
|
|
expect(buildSignUpReturnPath('/new')).toBe('/new?foo=bar')
|
|
})
|
|
|
|
it('uses the first value when returnTo is an array', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '' }
|
|
|
|
expect(buildSignUpReturnPath(['/join?token=abc', '/other'])).toBe('/join?token=abc')
|
|
})
|
|
})
|
|
|
|
describe('getReturnToPath', () => {
|
|
it('rebuilds a nested returnTo path with the params that rode alongside it', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '?ref=abc&name=OPENAI_API_KEY&returnTo=%2Fmcp%2Fsecrets' }
|
|
|
|
expect(getReturnToPath()).toBe('/mcp/secrets?ref=abc&name=OPENAI_API_KEY')
|
|
})
|
|
|
|
it('accepts a multi-segment returnTo rather than falling back', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search: '?returnTo=%2Fmcp%2Fsecrets' }
|
|
|
|
expect(getReturnToPath()).toBe('/mcp/secrets')
|
|
})
|
|
})
|
|
|
|
describe('transient auth params', () => {
|
|
const search =
|
|
'?error_description=Unable+to+exchange+external+code%3A+53f8&error=server_error&error_code=unexpected_failure&returnTo=%2Fnew'
|
|
|
|
it('buildPathWithParams does not carry them into the new path', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search }
|
|
|
|
expect(buildPathWithParams('/sign-in-mfa')).toBe('/sign-in-mfa?returnTo=%2Fnew')
|
|
})
|
|
|
|
it('getReturnToPath does not append them to the destination', () => {
|
|
// @ts-ignore
|
|
delete window.location
|
|
// @ts-ignore
|
|
window.location = { search }
|
|
|
|
expect(getReturnToPath()).toBe('/new')
|
|
})
|
|
})
|
|
|
|
describe('validateReturnTo', () => {
|
|
const fallback = DEFAULT_FALLBACK_PATH
|
|
|
|
it('should return the path if it is a valid internal path', () => {
|
|
expect(validateReturnTo('/dashboard')).toBe('/dashboard')
|
|
expect(validateReturnTo('/settings/profile')).toBe('/settings/profile')
|
|
expect(validateReturnTo('/projects?id=123')).toBe('/projects?id=123')
|
|
})
|
|
|
|
it('should return fallback if given an external URL', () => {
|
|
expect(validateReturnTo('https://example.com')).toBe(fallback)
|
|
expect(validateReturnTo('http://malicious-site.com')).toBe(fallback)
|
|
expect(validateReturnTo('//evil.com')).toBe(fallback)
|
|
})
|
|
|
|
it('should return fallback for potentially malicious paths', () => {
|
|
expect(validateReturnTo('/%2e%2e/etc/passwd')).toBe(fallback)
|
|
expect(validateReturnTo('/..')).toBe(fallback)
|
|
expect(validateReturnTo('/@evil/path')).toBe(fallback)
|
|
expect(validateReturnTo('/$malicious')).toBe(fallback)
|
|
})
|
|
|
|
it('should use custom fallback when provided', () => {
|
|
const customFallback = '/custom-fallback'
|
|
expect(validateReturnTo('https://example.com', customFallback)).toBe(customFallback)
|
|
expect(validateReturnTo('/%2e%2e/etc/passwd', customFallback)).toBe(customFallback)
|
|
})
|
|
|
|
it('should handle paths with query parameters correctly', () => {
|
|
expect(validateReturnTo('/dashboard?param1=value1¶m2=value2')).toBe(
|
|
'/dashboard?param1=value1¶m2=value2'
|
|
)
|
|
})
|
|
|
|
it('should reject encoded bracketed javascript: scheme payloads', () => {
|
|
expect(
|
|
validateReturnTo(
|
|
'%2F%5B%5Bx%5D%5Djavascript%3Aalert(%22H4CK3D%22)%2F%5By%5D%2F%5B%5Bx%5D%5D%2F%5By%5D%3Fx%26y'
|
|
)
|
|
).toBe(fallback)
|
|
expect(
|
|
validateReturnTo(
|
|
'/%2F%5B%5Bx%5D%5Djavascript%3Aalert(%22H4CK3D%22)%2F%5By%5D%2F%5B%5Bx%5D%5D%2F%5By%5D%3Fx%26y'
|
|
)
|
|
).toBe(fallback)
|
|
})
|
|
})
|