Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): pre-empt React 19 regressions in tests + Support form (#45784)

Alaister Youngd676c832f30b
diff --git a/apps/studio/components/interfaces/Integrations/Vault/Secrets/__tests__/EditSecretModal.test.tsx b/apps/studio/components/interfaces/Integrations/Vault/Secrets/__tests__/EditSecretModal.test.tsx
index e21e9fabb6b..7c3c396fce7 100644
--- a/apps/studio/components/interfaces/Integrations/Vault/Secrets/__tests__/EditSecretModal.test.tsx
+++ b/apps/studio/components/interfaces/Integrations/Vault/Secrets/__tests__/EditSecretModal.test.tsx
@@ -79,7 +79,7 @@ describe(`EditSecretModal`, () => {
await screen.findByRole(`dialog`)
- const nameInput = screen.getByLabelText(`Name`)
+ const nameInput = await screen.findByLabelText(`Name`)
const descriptionInput = screen.getByLabelText(`Description`)
const valueInput = screen.getByLabelText(`Secret value`)
const togglePasswordButton = screen.getByRole(`button`, { name: `Show secret value` })
diff --git a/apps/studio/components/interfaces/Support/CategoryAndSeverityInfo.tsx b/apps/studio/components/interfaces/Support/CategoryAndSeverityInfo.tsx
index 46ea1ce1a59..878999fee14 100644
--- a/apps/studio/components/interfaces/Support/CategoryAndSeverityInfo.tsx
+++ b/apps/studio/components/interfaces/Support/CategoryAndSeverityInfo.tsx
@@ -74,13 +74,26 @@ function CategorySelector({ form }: CategorySelectorProps) {
control={form.control}
render={({ field }) => {
const { ref: _ref, ...fieldWithoutRef } = field
+ // Radix Select fires `onValueChange('')` when its controlled value
+ // transitions from `undefined` to a defined value whose matching
+ // SelectItem isn't mounted yet (the dropdown is closed, so
+ // SelectContent and the items it portals haven't registered). On
+ // React 19's stricter scheduling this races our `setValue` from
+ // useSupportForm and clobbers the prefilled category. No
+ // SelectItem can have value="" (Radix throws), so `v === ''` is
+ // always the spurious bubble — drop it. See
+ // radix-ui/primitives#3381.
+ const onValueChange = (v: string) => {
+ if (v === '' && field.value) return
+ field.onChange(v)
+ }
return (
<FormItemLayout hideMessage layout="vertical" label="What are you having issues with?">
<FormControl>
<Select_Shadcn_
{...fieldWithoutRef}
defaultValue={field.value}
- onValueChange={field.onChange}
+ onValueChange={onValueChange}
>
<SelectTrigger_Shadcn_ aria-label="Select an issue" className="w-full">
<SelectValue_Shadcn_ placeholder="Select an issue">
diff --git a/apps/studio/components/interfaces/Support/useSupportForm.ts b/apps/studio/components/interfaces/Support/useSupportForm.ts
index a821910b250..db4e654c803 100644
--- a/apps/studio/components/interfaces/Support/useSupportForm.ts
+++ b/apps/studio/components/interfaces/Support/useSupportForm.ts
@@ -52,7 +52,9 @@ export function useSupportForm(
const providedInitialParamsRef = useRef(initialParams)
const [initialError, setInitialError] = useState<string | null>(null)
- // Load initial values from URL params
+ // Load initial values from URL params after mount so SSR/SSG render with
+ // bare defaults (no `window` access) and the client hydrates against the
+ // same HTML. URL-derived values are applied here, post-hydration.
useEffect(() => {
const params =
providedInitialParamsRef.current !== undefined
diff --git a/apps/studio/hooks/misc/useStateTransition.ts b/apps/studio/hooks/misc/useStateTransition.ts
index 13a6b24c73b..e296a4fbd3c 100644
--- a/apps/studio/hooks/misc/useStateTransition.ts
+++ b/apps/studio/hooks/misc/useStateTransition.ts
@@ -6,10 +6,17 @@ export function useStateTransition<
NewType extends State['type'],
>(
state: State,
- prevTest: PrevType,
+ // Documentary only — the entry-detection logic below intentionally does not
+ // require `savedPrevState.type === prevTest`. React 18+ auto-batches
+ // dispatches across awaits (e.g. dispatch SUBMIT → await → mutation
+ // onError dispatch ERROR), which collapses `prevTest → newTest` into a
+ // single render where the intermediate `prevTest` state is never observed,
+ // so the previous state may be any variant other than `newTest`. `cb`'s
+ // first parameter is typed accordingly.
+ _prevTest: PrevType,
newTest: NewType,
cb: (
- prevState: Extract<State, { type: PrevType }>,
+ prevState: Exclude<State, { type: NewType }>,
currState: Extract<State, { type: NewType }>
) => void
): void {
@@ -18,13 +25,13 @@ export function useStateTransition<
useEffect(() => {
const savedPrevState = prevState.current
- if (savedPrevState.type === prevTest && state.type === newTest) {
+ if (savedPrevState.type !== newTest && state.type === newTest) {
cb(
- savedPrevState as Extract<State, { type: PrevType }>,
+ savedPrevState as Exclude<State, { type: NewType }>,
state as Extract<State, { type: NewType }>
)
}
prevState.current = state
- }, [cb, newTest, prevTest, state])
+ }, [cb, newTest, state])
}
diff --git a/apps/studio/tests/features/logs/LogsPreviewer.test.tsx b/apps/studio/tests/features/logs/LogsPreviewer.test.tsx
index 2abb61d049c..8fc1356ea5c 100644
--- a/apps/studio/tests/features/logs/LogsPreviewer.test.tsx
+++ b/apps/studio/tests/features/logs/LogsPreviewer.test.tsx
@@ -132,11 +132,12 @@ test('can click load older', async () => {
{ timeout: 10000 }
)
- loadOlder.onclick = vi.fn()
+ const handleClick = vi.fn()
+ loadOlder.addEventListener('click', handleClick)
await userEvent.click(loadOlder)
- expect(loadOlder.onclick).toHaveBeenCalled()
+ expect(handleClick).toHaveBeenCalled()
})
describe('calculateBarClickTimeRange', () => {