Skip to content

Commit

Permalink
Always use the latest form data in submit event
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jun 11, 2024
1 parent 0493b67 commit d45eb1c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions plugins/speculation-rules/search-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const { actions } = store( 'speculationRules', {
if ( ! formData.get( 's' ) ) {
context.speculativeLoadUrl = null;
} else {
const url = new URL( form.action || location.href );
const url = new URL( form.action );
url.search = new URLSearchParams( formData ).toString();
context.speculativeLoadUrl = url.href;
}
Expand All @@ -63,11 +63,12 @@ const { actions } = store( 'speculationRules', {
}
},
handleFormSubmit: ( event ) => {
const context = getContext();
if ( context.speculativeLoadUrl ) {
event.preventDefault();
location.href = context.speculativeLoadUrl;
}
event.preventDefault();
const form = event.target;
const formData = new FormData( form );
const url = new URL( form.action );
url.search = new URLSearchParams( formData ).toString();
location.href = url.href;
},
},
} );

0 comments on commit d45eb1c

Please sign in to comment.