Skip to content

Do not add post form body to query params if form data is only set via event#1509

Open
lukasbableck wants to merge 1 commit intohotwired:mainfrom
lukasbableck:fix/post-data-in-query-params
Open

Do not add post form body to query params if form data is only set via event#1509
lukasbableck wants to merge 1 commit intohotwired:mainfrom
lukasbableck:fix/post-data-in-query-params

Conversation

@lukasbableck
Copy link
Copy Markdown

In a scenario where you have an empty form, so no inputs and no name attribute on the submitter, and you're setting the form data via the turbo:submit-start event (with event.detail.formSubmission.fetchRequest.body.append), you're actually adding the form data to the URL objects searchParams, as resource.searchParams is used for the body.
This causes the URL to contain all of the form data, which is especially problematic for larger amounts of data, as the webserver then might just close the connection because the URL is too long. In my case this happened after the URL reached about 7.5KB.
This PR fixes the issue, while also simplifying the logic a bit.

/cc @m-vo

Copy link
Copy Markdown
Contributor

@m-vo m-vo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixed bug is really subtle as most of the time you won't realize that you're working with the reference of the actual browser URL in a turbo:submit-start event. 👍

Thanks for the fix @lukasbableck - removing the case for when the body length is 0, also makes the code much easier to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants