@@ -82,8 +82,13 @@ export type FormOptions<
8282 In extends Record < string , unknown > = T
8383> = Partial < {
8484 id : string ;
85- applyAction : boolean ;
86- invalidateAll : boolean | 'force' ;
85+ /**
86+ * If `false`, the form won't react to page state updates, except for page invalidations.
87+ * If `'never'`, not even page invalidations will affect the form.
88+ * @default true
89+ */
90+ applyAction : boolean | 'never' ;
91+ invalidateAll : boolean | 'force' | 'pessimistic' ;
8792 resetForm : boolean | ( ( ) => boolean ) ;
8893 scrollToError : 'auto' | 'smooth' | 'off' | boolean | ScrollIntoViewOptions ;
8994 autoFocusOnError : boolean | 'detect' ;
@@ -997,16 +1002,20 @@ export function superForm<
9971002 } ;
9981003 }
9991004
1000- async function Form_updateFromValidation ( form : SuperValidated < T , M , In > , successResult : boolean ) {
1001- if ( form . valid && successResult && Form_shouldReset ( form . valid , successResult ) ) {
1002- Form_reset ( { message : form . message , posted : true } ) ;
1005+ async function Form_updateFromValidation (
1006+ form2 : SuperValidated < T , M , In > ,
1007+ successResult : boolean
1008+ ) {
1009+ if ( form2 . valid && successResult && Form_shouldReset ( form2 . valid , successResult ) ) {
1010+ Form_reset ( { message : form2 . message , posted : true } ) ;
10031011 } else {
10041012 rebind ( {
1005- form,
1013+ form : form2 ,
10061014 untaint : successResult ,
10071015 keepFiles : true ,
10081016 // Check if the form data should be used for updating, or if the invalidateAll load function should be used:
1009- skipFormData : options . invalidateAll == 'force'
1017+ pessimisticUpdate :
1018+ options . invalidateAll == 'force' || options . invalidateAll == 'pessimistic'
10101019 } ) ;
10111020 }
10121021
@@ -1017,7 +1026,7 @@ export function superForm<
10171026
10181027 // But do not await on onUpdated itself, since we're already finished with the request
10191028 for ( const event of formEvents . onUpdated ) {
1020- event ( { form } ) ;
1029+ event ( { form : form2 } ) ;
10211030 }
10221031 }
10231032
@@ -1429,7 +1438,7 @@ export function superForm<
14291438 message ?: M ;
14301439 keepFiles ?: boolean ;
14311440 posted ?: boolean ;
1432- skipFormData ?: boolean ;
1441+ pessimisticUpdate ?: boolean ;
14331442 resetted ?: boolean ;
14341443 } ) {
14351444 //console.log('🚀 ~ file: superForm.ts:721 ~ rebind ~ form:', form.data); //debug
@@ -1444,7 +1453,7 @@ export function superForm<
14441453 // Prevents object errors from being revalidated after rebind.
14451454 // Check if form was invalidated (usually with options.invalidateAll) to prevent data from being
14461455 // overwritten by the load function data
1447- if ( opts . skipFormData !== true ) {
1456+ if ( ! opts . pessimisticUpdate ) {
14481457 Form_set ( form . data , {
14491458 taint : 'ignore' ,
14501459 keepFiles : opts . keepFiles
@@ -1518,7 +1527,11 @@ export function superForm<
15181527 initialForms . set ( newForm , newForm ) ;
15191528 await Form_updateFromValidation ( newForm as SuperValidated < T , M , In > , successResult ) ;
15201529 }
1521- } else if ( pageUpdate . data && typeof pageUpdate . data === 'object' ) {
1530+ } else if (
1531+ options . applyAction !== 'never' &&
1532+ pageUpdate . data &&
1533+ typeof pageUpdate . data === 'object'
1534+ ) {
15221535 // It's a page reload, redirect or error/failure,
15231536 // so don't trigger any events, just update the data.
15241537 for ( const newForm of Context_findValidationForms ( pageUpdate . data ) ) {
@@ -1528,7 +1541,7 @@ export function superForm<
15281541 continue ;
15291542 }
15301543
1531- if ( options . invalidateAll === 'force' ) {
1544+ if ( options . invalidateAll === 'force' || options . invalidateAll === 'pessimistic' ) {
15321545 initialForm . data = newForm . data as T ;
15331546 }
15341547
0 commit comments