Page MenuHomePhabricator

Handle error when saving favourite templates
Closed, ResolvedPublic3 Estimated Story Points

Description

While saving favourite templates using api.php?action=options an error might be returned.

  • User might already have the max number of templates (QA note: can be tested more easily with e.g. $wgTemplateDataMaxFavorites = 5).
  • Backend API might be down for some unspecified reason (e.g. $wgReadOnly).
  • The user might've been logged out.

Handle the error and inform the user via bubble notification similar to T377466: Show bubble notification after adding favourite

Event Timeline

Change #1124575 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/extensions/TemplateData@master] Handle errors when trying to save favourite templates

https://gerrit.wikimedia.org/r/1124575

Samwilson set the point value for this task to 3.Mar 5 2025, 6:53 AM

Change #1124575 merged by jenkins-bot:

[mediawiki/extensions/TemplateData@master] Handle errors when trying to save favourite templates

https://gerrit.wikimedia.org/r/1124575

KSiebert changed the task status from Open to Stalled.Mar 27 2025, 10:38 AM

@Samwilson I find that when the API returns an error when favouriting/unfavouriting, I get two notifications: one saying there was an error and one saying it succeeded. The icon is also filled in, even if the favouriting was not successful. Similar thing happens when unfavouriting.

In the below example, I have set $wgReadOnly = true. Also note that I first try to favourite "DZA" but nothing happens. I believe because the API returned the error in HTML format. I am not sure why it did this or whether this is a common problem.

Change #1138944 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/extensions/TemplateData@master] Fix rejected 'save' promise handling

https://gerrit.wikimedia.org/r/1138944

Samwilson changed the task status from Stalled to Open.Apr 25 2025, 12:58 AM

Thanks Dom! I've made a fix for this and T392558 in the same patch.

Change #1138944 merged by jenkins-bot:

[mediawiki/extensions/TemplateData@master] Fix rejected 'save' promise handling

https://gerrit.wikimedia.org/r/1138944

Testing on enwiki beta by logging out in another tab, I am seeing a couple more ways in which errors are not being handled gracefully:

  • After an error, the favourite icon still has a loading state. This occurs in the Favourite and Featured lists, when looking at the details of a template and in the search dropdown.
    error_loading_state.png (577×1 px, 71 KB)
  • If you click a filled in favourite icon twice it goes to the unfavourited state.
    error_unfavourite_twice.png (539×1 px, 51 KB)
  • After clicking the favourite icon in the search dropdown, if you close and reopen the dropdown the icon will have changed.
  • Each time you click a favourite icon it adds the new ID to the templatedata-favorite-templates variable in the action=options API request. It will even add any number of duplicate IDs to the variable if you keep clicking the same favourite icon. You can keep adding new IDs until you have reached your 50 limit and then you are told You have reached the maximum number...

Change #1176808 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/extensions/TemplateData@master] Pop pending state of favorite button on failure to set pref

https://gerrit.wikimedia.org/r/1176808

Change #1177584 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/extensions/TemplateData@master] Don't modify favorites array until after saving

https://gerrit.wikimedia.org/r/1177584

After an error, the favourite icon still has a loading state.

Patch for this: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/TemplateData/+/1176808

If you click a filled in favourite icon twice it goes to the unfavourited state.

That might be what we want; I'm not sure. If you click, and then it's in pending state, and you click again, should it ignore your click or reverse it? If you click three times should it fave-unfave-fave? Or should further clicks have no effect until the pending state has stopped?

After clicking the favourite icon in the search dropdown, if you close and reopen the dropdown the icon will have changed.

Oops! That's bad. Patch for review: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/TemplateData/+/1177584

Each time you click a favourite icon it adds the new ID to the templatedata-favorite-templates variable in the action=options API request.

Also fixed by the above patch.

Change #1177584 merged by jenkins-bot:

[mediawiki/extensions/TemplateData@master] Don't modify favorites array until after saving

https://gerrit.wikimedia.org/r/1177584

Change #1176808 merged by jenkins-bot:

[mediawiki/extensions/TemplateData@master] Pop pending state of favorite button on failure to set pref

https://gerrit.wikimedia.org/r/1176808

I can no longer reproduce the bugs in T377949#11067535 on enwiki beta.