@@ -256,6 +256,9 @@ export type EnhancedForm<T extends AnyZodObject, M = any> = SuperForm<T, M>;
256256
257257const formIds = new WeakMap < Page , Set < string | undefined > > ( ) ;
258258
259+ // Track ActionData, so it won't be applied twice for componentized forms.
260+ const postedActionData = new WeakSet < object > ( ) ;
261+
259262function multipleFormIdError ( id : string | undefined ) {
260263 return (
261264 `Duplicate form id's found: "${ id } ". ` +
@@ -338,13 +341,20 @@ export function superForm<
338341 }
339342 }
340343
344+ // Need to clone the validation data, in case it's used to populate multiple forms.
345+ const initialForm = clone ( form ) ;
346+
341347 // Detect if a form is posted without JavaScript.
342348 const postedData = _currentPage . form ;
343- if ( postedData && typeof postedData === 'object' ) {
349+
350+ if ( ! browser && postedData && typeof postedData === 'object' ) {
344351 for ( const postedForm of Context_findValidationForms (
345352 postedData
346353 ) . reverse ( ) ) {
347- if ( postedForm . id === _formId ) {
354+ if ( postedForm . id === _formId && ! postedActionData . has ( postedForm ) ) {
355+ // Prevent multiple "posting" that can happen when components are recreated.
356+ postedActionData . add ( postedData ) ;
357+
348358 const pageDataForm = form as SuperValidated < T , M > ;
349359 form = postedForm as SuperValidated < T , M > ;
350360 // Reset the form if option set and form is valid.
@@ -363,13 +373,10 @@ export function superForm<
363373
364374 const form2 = form as SuperValidated < T , M > ;
365375
366- // Need to clone the validation data, in case it's used to populate multiple forms.
367- const initialForm = clone ( form2 ) ;
368-
369376 if ( typeof initialForm . valid !== 'boolean' ) {
370377 throw new SuperFormError (
371378 'A non-validation object was passed to superForm. ' +
372- "Check what's passed to its first parameter."
379+ 'It should be an object of type SuperValidated, usually returned from superValidate.'
373380 ) ;
374381 }
375382
@@ -818,13 +825,20 @@ export function superForm<
818825 const untaint = pageUpdate . status >= 200 && pageUpdate . status < 300 ;
819826
820827 if ( pageUpdate . form && typeof pageUpdate . form === 'object' ) {
828+ const actionData = pageUpdate . form ;
829+
821830 // Check if it is an error result, sent here from formEnhance
822- if ( pageUpdate . form . type == 'error' ) return ;
831+ if ( actionData . type == 'error' ) return ;
823832
824- const forms = Context_findValidationForms ( pageUpdate . form ) ;
833+ const forms = Context_findValidationForms ( actionData ) ;
825834 for ( const newForm of forms ) {
826835 //console.log('🚀~ ActionData ~ newForm:', newForm.id);
827- if ( newForm . id !== _formId ) continue ;
836+ if ( newForm . id !== _formId || postedActionData . has ( newForm ) ) {
837+ continue ;
838+ }
839+
840+ // Prevent multiple "posting" that can happen when components are recreated.
841+ postedActionData . add ( newForm ) ;
828842
829843 await Form_updateFromValidation (
830844 newForm as SuperValidated < T , M > ,
0 commit comments