For each page in a TitleWidget result list (e.g. for a TitleInputWidget) is sorted according to the `index` value that's returned by the prefix-search API. This works fine for most search results, because each page has its own value, but for redirects it's different. Redirects have a separate section of the API response where the //from// and //to// titles are listed along with the `index` value of the //to// (target). This is the value that's not being used correctly in TitleWidget.
This is an example of the API response:
```lang=json
{
"query": {
"redirects":[
{"index":3,"from":"Redirect","to":"Redirect target"},
{"index":4,"from":"Redirect two","to":"Redirect target"}
],
"pages":{
"-1":{
"ns":0,"title":"Redirect target","missing":"","contentmodel":"wikitext",
"pagelanguage":"it","pagelanguagehtmlcode":"it","pagelanguagedir":"ltr"},
"133":{
"pageid":133,"ns":0,"title":"Redirect, not a","index":1,
"contentmodel":"wikitext","pagelanguage":"it","pagelanguagehtmlcode":"it","pagelanguagedir":"ltr",
"touched":"2021-10-05T09:34:41Z","lastrevid":334,"length":1,"new":""
}
"133":{"pageid":133,"ns":0,"title":"Redirect, not a","index":1,"contentmodel":"wikitext","pagelanguage":"it","pagelanguagehtmlcode":"it","pagelanguagedir":"ltr","touched":"2021-10-05T09:34:41Z","lastrevid":334,"length":1,"new":""}}}
}
}
```
And this is an example of the `pageData` variable that's built form it in [[https://gerrit.wikimedia.org/g/mediawiki/core/+/7bdcc36fc0e2ac280cf11ff3ac3901f97fd5f704/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js#279 | resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js]] is as follows:
```lang=json
"Redirect, not a": {
"known": false,
"missing": false,
"redirect": false,
"disambiguation": false,
"index": 1,
"originalData": { … }
},
"Redirect target": {
"known": false,
"missing": true,
"redirect": false,
"disambiguation": false,
"index": NaN,
"originalData": { …. }
},
"Redirect": {
"missing": false,
"known": true,
"redirect": true,
"disambiguation": false,
"description": "redirect to Redirect target",
"index": null,
"originalData": { … }
},
"Redirect two": {
"missing": false,
"known": true,
"redirect": true,
"disambiguation": false,
"description": "redirect to Redirect target",
"index": null,
"originalData": { … }
}
}
```
Note the non-integer values for `index` keys.