Skip to content
Source
Sign inSign up
TanStack/form

fix(vue-form): generate an SSR-safe default formId #2259

Mergedharshit-d3v(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/2259/headmerged by crutchcorn(GitHub profile, opens in a new tab)

Showing 4 changed files with 35 additions and 1 deletion (loading 1).

x
0 of 4 viewed, 4 left
7 additions and 0 deletions.changeset/lucky-donkeys-shout.mdAdded
View file
@@ -0,0 +1,7 @@
+---
+'@tanstack/vue-form': patch
+---
+​
+Generate the default `formId` with Vue's `useId` so it is SSR-safe, falling back to a random uuid on `vue@3.4` (where `useId` does not exist) and outside of a component instance.
+​
+Fixes #2254
4 additions and 1 deletionpackages/vue-form/src/useForm.tsxModified
View file
@@ -3,6 +3,7 @@
import { defineComponent, h, onMounted } from 'vue'
import { Field } from './useField'
import { FormGroup } from './useFormGroup'
+import { useFormId } from './useFormId'
import type {
FormAsyncValidateOrFn,
FormOptions,
@@ -268,6 +269,8 @@
TSubmitMeta
) {
+ const fallbackFormId = useFormId()
+​
const formApi = (() => {
const api = new FormApi<
TParentData,
@@ -282,7 +285,7 @@