StarCitizenTools / mediawiki-extensions-TabberNeue

A MediaWiki extension that allows wiki to create tabs.
https://www.mediawiki.org/wiki/Extension:TabberNeue
GNU General Public License v3.0
10 stars 15 forks source link

`aria-selected` may be false for every tab header when `TabberEvent` is instantiated #141

Closed csalinezh closed 2 months ago

csalinezh commented 3 months ago

On current HEAD (https://github.com/StarCitizenTools/mediawiki-extensions-TabberNeue/commit/35ffe555c07fd06439db5c7e161cd1214a65d6c0) I noticed this issue when scrolling the tabber element quickly into viewport while the page is still loading. this.activeTab is null, hence the stack trace:

TypeError: Cannot read properties of null (reading 'getAttribute')
    at TabberEvent.getActiveTabpanel (<anonymous>:565:354)
    at TabberEvent.resume (<anonymous>:567:146)
    at TabberEvent.init (<anonymous>:567:646)
    at <anonymous>:570:55

Another exception follows it:

TypeError: Cannot read properties of null (reading 'getAttribute')
    at TabberEvent.getActiveTabpanel (<anonymous>:565:354)
    at TabberEvent.resume (<anonymous>:567:146)
    at <anonymous>:567:571
    at Array.forEach (<anonymous>)
    at IntersectionObserver.<anonymous> (<anonymous>:567:523)

The race condition happens because in TabberBuilder.init(), initializing aria-selected="true" happens during requestAnimationFrame via TabberAction.setActiveTab(). It is not guaranteed (?) to happen before the following new TabberEvent(). https://github.com/StarCitizenTools/mediawiki-extensions-TabberNeue/blob/35ffe555c07fd06439db5c7e161cd1214a65d6c0/modules/ext.tabberNeue/ext.tabberNeue.js#L605-L611

alistair3149 commented 2 months ago

Oops didn't see this. This is the same as #148 and should be fixed by 8a88a43.