mitmweb: apply text options on blur or Enter, not per keystroke by Cassian433 · Pull Request #8476 · mitmproxy/mitmproxy · GitHub
Skip to content

mitmweb: apply text options on blur or Enter, not per keystroke - #8476

Open
Cassian433 wants to merge 1 commit into
mitmproxy:mainfrom
Cassian433:web-options-commit-on-blur
Open

Cassian433 wants to merge 1 commit into
mitmproxy:mainfrom
Cassian433:web-options-commit-on-blur

Conversation

@Cassian433

Copy link
Copy Markdown

Description

Fixes #7655.

The Options editor sends a PUT /options for every keystroke in a text or number field. update() in web/src/js/ducks/options.ts used to be throttled, but the throttle was commented out back in 2021 (46cd40f) and OptionInput.tsx dispatches straight from onChange. For most options that is just noise. For save_stream_file it is real damage: Save.configure opens the file on every update, so each prefix of the path ends up as an empty file on disk, which is exactly what the reporter saw.

I didn't bring the throttle back. It was a single throttle shared by every option, so of several updates to different options inside the same 500 ms window only the first and last got sent. It would also still write a partial file every half second while someone types. Instead the string, int and float inputs keep the typed text in local state and only call onChange on blur or Enter, and only if the text actually changed. The "sequence of str" textarea commits on blur (Enter has to stay a newline there) and now sizes itself from the local text, since value no longer changes while you type. Checkboxes and selects still apply immediately.

Tested with jest (web npm test: eslint, tsc, 347 tests pass). The new specs in OptionSpec.tsx fail on main: rendering OptionInput for save_stream_file and typing /tmp/flows.mitm makes 15 fetch calls there, 1 on this branch.

I also ran it end to end: mitmweb from this checkout on 127.0.0.1 with an empty working dir, the vite dev server, and headless Chrome typing flows.mitm into save_stream_file one key at a time over CDP, then Tab. On main that was 10 PUTs and 10 zero-byte files in the working dir (f, fl, flo ... flows.mitm). On the branch it was 1 PUT and only flows.mitm, and the field kept its value afterwards.

One behaviour change to be aware of: if you type into a field and close the modal with Escape before leaving the field, the edit is dropped. Clicking the close button or anywhere else still applies it, because the input blurs first.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 Bug Report: save_stream_file option in mitmweb UI (Edit Options) doesn't work properly

1 participant