5
11
Fork
You've already forked tomato
1

Prevent some unnecessary post requests #34

Merged
edwardloveall merged 3 commits from el-no-post into main 2025年10月20日 15:10:08 +02:00

A couple components took a method argument. It defaulted to get and because it was always supplied, Rails UJS kicked in and made a form to submit instead of just clicking the link. For whatever reason, the UJS form always uses the POST method.

github.com/rails/rails@c941680274/actionview/app/assets/javascripts/rails-ujs.js (L393)

We don't want POST requests always popping off in the app when a GET will do so this converts some existing links that need the extra method, and removes the method arg from the components.

A couple components took a `method` argument. It defaulted to `get` and because it was always supplied, Rails UJS kicked in and made a form to submit instead of just clicking the link. For whatever reason, the UJS form always uses the `POST` method. https://github.com/rails/rails/blob/c94168027490/actionview/app/assets/javascripts/rails-ujs.js#L393 We don't want `POST` requests always popping off in the app when a `GET` will do so this converts some existing links that need the extra method, and removes the `method` arg from the components.
This was adding a data-method attribute to the rendered tab bar links.
Even if the `data-method` was set to `get` it would create a POST
request. This seems to be some quirk of rails ujs:
c941680274/actionview/app/assets/javascripts/rails-ujs.js (L393)
It's unclear to me if we were using rails ujs wrong, or it's a bug, or
something else. Regardless, we were only ever using GET so removing it
should have no difference.
The link_button component took a `method` argument. It defaulted to
`get` and because it was always supplied, rails ujs kicked in and made
a form to submit instead of just clicking the link. For whatever
reason, this form always uses the `POST` method.
c941680274/actionview/app/assets/javascripts/rails-ujs.js (L393)
We don't want `POST` requests always popping off in the app when a
`GET` will do so this converts the two links we had to be stand-alone
links, and removes the `method` arg from the link_button component.
Remove logout link from org edit page
All checks were successful
Setup Successful
Jest Successful
Static Analysis Successful
RSpec Successful
42fcaa761a
Not sure why this was there. It's a logout button on one page, but
there's the usual logout button in the settings menu.
thetizzo left a comment
Copy link

That's a weird one but the UJS stuff has always been mysterious 😄

That's a weird one but the UJS stuff has always been mysterious 😄
Author
Owner
Copy link

That's a weird one but the UJS stuff has always been mysterious 😄

Yeah, I gave it some more thought and it seems like ujs == form submission, because they only expect you to use it for not-get requests. Odd choice, and maybe something to report or contribute.

> That's a weird one but the UJS stuff has always been mysterious :smile: Yeah, I gave it some more thought and it seems like ujs == form submission, because they only expect you to use it for not-get requests. Odd choice, and maybe something to report or contribute.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rootable/tomato!34
Reference in a new issue
rootable/tomato
No description provided.
Delete branch "el-no-post"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?