I'm not 100% sure it's a bug, but it seems a weird, counterintuitive behavior to me.
List of steps to reproduce:
- Open DevTools, switch to the Network tab, filter XHR requests.
- Go to https://ru.wikipedia.org/w/index.php?title=Test&diff=115302071&oldid=107672833&uselang=en while being logged on and having VisualEditor enabled.
What happens?:
An api.php request appears with payload like this:
What should have happened instead?:
No request should be made, unless the value of the diffmode query parameter differs from mw.user.options.get( 'visualeditor-diffmode-historical' ) (see below)?
What happens in the code?
See https://phabricator.wikimedia.org/diffusion/EVED/browse/master/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js:
On wikipage.diff hook fire, an item of this button select is selected according to the diffmode query parameter or the visualeditor-diffmode-historical user setting:
This triggers a select event, and the onReviewModeButtonSelectSelect callback runs. There, new mw.Api().saveOption( 'visualeditor-diffmode-historical', mode ); initiates an API request.
Conclusion
So, generally, in 99.99% of cases, an option value is retrieved from mw.user.options.get( 'visualeditor-diffmode-historical' ), and then that exact value is saved back to the server. This request seems useless.
When I tried to make sense of this logic, I thought that maybe this behavior makes a difference in cases where multiple diffs are opened in different tabs, and the mode setting of the last opened tab should end up in the user settings. (The API request is postponed until the tab is first focused.) But perhaps I'm overthinking this :-)