Files
Brian-AnandDanny White f1082e28c7 chore: migrate Framer Motion imports to Motion (#51520)
## Problem

Closes #31221.
The applications and shared UI packages still import the former
`framer-motion` package instead of Motion's React entry point.

## Solution

Replace runtime imports, type imports, and three test mocks with
`motion/react` across the consuming workspaces.
Replace the seven direct dependency declarations with `motion:
^11.18.2`.
Preserve the existing animation engine version and all other dependency
resolutions, including the asynchronous `domMax` feature loader.
Historical blog examples remain as published; `framer-motion` remains a
transitive implementation dependency of Motion.

## Review instructions

1. Run `pnpm install --frozen-lockfile` and check the seven dependency
replacements in the lockfile.
2. Open the WWW Auth page and Docs homepage at desktop and mobile
widths, with normal and reduced motion preferences.
3. Open the mobile navigation, expand Product on WWW, and close the menu
using Escape and the close button.
4. Check the existing animation components, shared form validation, and
Studio tests for unchanged behavior.

Validation:

- Studio: 731 test files, 8,334 passing tests and one expected failure,
with `--maxWorkers=4`.
- Shared UI, UI patterns, WWW, and UI library: 615 passing tests.
- `pnpm run typecheck --concurrency=1`: all 16 repository tasks pass.
- All six application source lint scripts and lint ratchets pass;
generated Docs example copies are excluded from local lint.
- Repository Prettier source check, lockfile formatting, and case hazard
check pass.
- WWW: 10 existing end-to-end checks across nine pages.
- Docs: 5 existing guide link and accessibility checks across Database
and Auth.
- WWW and Docs mobile navigation pass at desktop/mobile sizes with
normal/reduced motion; SQL-to-REST translation tabs exercise the
asynchronous feature loader without browser errors.
- Frozen-lockfile installation passes; all existing package and snapshot
resolutions are unchanged.
- Learn and UI library command palettes open, filter results, and close
with Escape without browser errors.
- Independent code review finds no actionable defects.
- `npm run build -- --filter=www --filter=docs --filter=studio
--filter=learn --filter=library --concurrency=1 --continue=always`: all
five affected applications build successfully (9 tasks including
prerequisites); asset uploads disabled for local validation.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] 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)
(no docs topics changed)

---------

Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
2026-10-14 07:16:00 +00:00

190 lines
6.0 KiB
TypeScript

import { LOCAL_STORAGE_KEYS, useFlag, useParams } from 'common'
import { AnimatePresence, motion } from 'motion/react'
import { useRouter } from 'next/router'
import { PropsWithChildren, useMemo } from 'react'
import type {
ProjectSecurityActionDetails,
ProjectSecurityActionType,
} from './ProjectNeedsSecuring.types'
import { getExposedSchemas, getTableKey, sortTables } from './ProjectNeedsSecuring.utils'
import { ProjectNeedsSecuringView } from './ProjectNeedsSecuringView'
import { useProjectPostgrestConfigQuery } from '@/data/config/project-postgrest-config-query'
import { useProjectLintsQuery } from '@/data/lint/lint-query'
import { useTablePrivilegesQuery } from '@/data/privileges/table-privileges-query'
import { useTablesQuery } from '@/data/tables/tables-query'
import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { isApiAccessRole, isApiPrivilegeType } from '@/lib/data-api-types'
import { useTrack } from '@/lib/telemetry/track'
const PROJECT_SECURITY_FEATURE_FLAG = 'projectNeedsSecuring'
const PROJECT_HOME_PATHNAME = '/project/[ref]'
const ProjectNeedsSecuringGate = ({ children }: PropsWithChildren) => {
const router = useRouter()
const track = useTrack()
const { ref: projectRef } = useParams()
const { data: project } = useSelectedProjectQuery()
const [securityDismissedAt, setSecurityDismissedAt, { isLoading: isLoadingDismissedAt }] =
useLocalStorageQuery<string | null>(
projectRef
? LOCAL_STORAGE_KEYS.PROJECT_SECURITY_DISMISSED_AT(projectRef)
: 'project-security-dismissed-at-unknown',
null
)
const isProjectHomeRoute = router.pathname === PROJECT_HOME_PATHNAME
const { data: lints = [] } = useProjectLintsQuery(
{ projectRef },
{ enabled: isProjectHomeRoute && !!projectRef }
)
const rlsIssueKeys = useMemo(() => {
return new Set(
lints
.filter((lint) => lint.name === 'rls_disabled_in_public' && lint.level === 'ERROR')
.map((lint) => {
const schema = typeof lint.metadata?.schema === 'string' ? lint.metadata.schema : null
const name = typeof lint.metadata?.name === 'string' ? lint.metadata.name : null
return schema && name ? getTableKey({ schema, name }) : null
})
.filter((value): value is string => value !== null)
)
}, [lints])
const hasRlsIssues = rlsIssueKeys.size > 0
const shouldRenderGate =
isProjectHomeRoute &&
!!projectRef &&
!isLoadingDismissedAt &&
hasRlsIssues &&
securityDismissedAt === null
const {
data: tables,
error: tablesError,
isPending: isLoadingTables,
} = useTablesQuery(
{
projectRef,
connectionString: project?.connectionString,
includeColumns: false,
},
{ enabled: shouldRenderGate }
)
const handleTrackAction = (
type: ProjectSecurityActionType,
details?: ProjectSecurityActionDetails
) => {
track('project_security_cta_clicked', {
type,
...details,
})
}
const {
data: dbSchema,
error: postgrestConfigError,
isPending: isLoadingPostgrestConfig,
isSuccess: isSuccessPostgrestConfig,
} = useProjectPostgrestConfigQuery(
{ projectRef },
{
enabled: shouldRenderGate,
select: ({ db_schema }) => db_schema,
}
)
const exposedSchemas = getExposedSchemas(dbSchema)
const {
data: tablePrivileges,
error: tablePrivilegesError,
isPending: isLoadingTablePrivileges,
} = useTablePrivilegesQuery(
{ projectRef, connectionString: project?.connectionString, includedSchemas: exposedSchemas },
{ enabled: shouldRenderGate && isSuccessPostgrestConfig }
)
const tableRows = useMemo(() => {
if (!tables) return []
const dataApiAccessByTable = new Map<string, boolean>()
for (const entry of tablePrivileges ?? []) {
const key = getTableKey(entry)
const hasDataApiAccess = entry.privileges.some(
(privilege) =>
isApiAccessRole(privilege.grantee) && isApiPrivilegeType(privilege.privilege_type)
)
if (hasDataApiAccess) {
dataApiAccessByTable.set(key, true)
}
}
return sortTables(
tables
.filter((table) => !table.rls_enabled && rlsIssueKeys.has(getTableKey(table)))
.map((table) => {
const key = getTableKey(table)
return {
id: table.id,
name: table.name,
schema: table.schema,
rlsEnabled: table.rls_enabled,
dataApiAccessible: dataApiAccessByTable.get(key) === true,
hasRlsIssue: rlsIssueKeys.has(key),
}
})
)
}, [rlsIssueKeys, tablePrivileges, tables])
// Keep children in one stable position when not gating. Changing their wrapper
// once lints load used to remount the homepage and reload the charts.
if (!isProjectHomeRoute || !projectRef) {
return <>{children}</>
}
return (
<>
<AnimatePresence>
{shouldRenderGate && (
<motion.div
key="project-needs-securing"
className="flex flex-1 min-h-0 w-full"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2, ease: 'easeOut' }}
>
<ProjectNeedsSecuringView
projectRef={projectRef}
issueCount={rlsIssueKeys.size}
tables={tableRows}
isLoading={isLoadingTables || isLoadingPostgrestConfig || isLoadingTablePrivileges}
error={tablesError ?? postgrestConfigError ?? tablePrivilegesError}
onDismiss={() => setSecurityDismissedAt(new Date().toISOString())}
onTrackAction={handleTrackAction}
/>
</motion.div>
)}
</AnimatePresence>
{!shouldRenderGate && children}
</>
)
}
export const ProjectNeedsSecuring = ({ children }: PropsWithChildren) => {
const isEnabled = useFlag(PROJECT_SECURITY_FEATURE_FLAG)
if (!isEnabled) return <>{children}</>
return <ProjectNeedsSecuringGate>{children}</ProjectNeedsSecuringGate>
}