Skip to content

Commit d45eb1c

Browse files
committed
Always use the latest form data in submit event
1 parent 0493b67 commit d45eb1c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

plugins/speculation-rules/search-form.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const { actions } = store( 'speculationRules', {
5151
if ( ! formData.get( 's' ) ) {
5252
context.speculativeLoadUrl = null;
5353
} else {
54-
const url = new URL( form.action || location.href );
54+
const url = new URL( form.action );
5555
url.search = new URLSearchParams( formData ).toString();
5656
context.speculativeLoadUrl = url.href;
5757
}
@@ -63,11 +63,12 @@ const { actions } = store( 'speculationRules', {
6363
}
6464
},
6565
handleFormSubmit: ( event ) => {
66-
const context = getContext();
67-
if ( context.speculativeLoadUrl ) {
68-
event.preventDefault();
69-
location.href = context.speculativeLoadUrl;
70-
}
66+
event.preventDefault();
67+
const form = event.target;
68+
const formData = new FormData( form );
69+
const url = new URL( form.action );
70+
url.search = new URLSearchParams( formData ).toString();
71+
location.href = url.href;
7172
},
7273
},
7374
} );

0 commit comments

Comments
 (0)