jhildenbiddle/docsify-tabs

No active tabs onload

0x111 opened this issue · 4 comments

0x111 commented

After the release of latest version, the first tab is not opened per default anymore.

To reproduce this, go to the docs.

I get this error in the console, see screenshot:
Screenshot 2020-05-11 at 14 04 19
This new change stems from the change introduced yesterday.

Now as far as I understand, the code expects an anchorID to be always present, which might not be the case all the time.

The issue comes from this line more specifically

const anchorID = (window.location.hash.match(/(?:id=)([^&]+)/) || [])[1];

If we find a match, okay, the return the name of the match, like for an url somethig/README?id=linux that would return linux.
But if this line does not find a match, then it does return an empty array, and you cant take the first element of an empty array [], since there is no first element.

Now all of the tabs are closed because this fails and anchorID returns undefined, to which you can't apply indexOf.

Tldr; if there is no match for an id in the url, then the tabs will be not opened because it fails with an error.

I've submitted a PR for this, please check if I am not breaking any functionality with this. It seems to be working fine with the changes applied.

Fixed in 1.4.2.

Thanks for creating the issue, @0x111!

When will 1.4.2 be pushed to the CDN for general availability? Im currently running into this issue and its cool that it was already fixed

0x111 commented

@dstarner This is already here: 1.4.2

Ah, im pulling in https://cdn.jsdelivr.net/npm/docsify-tabs@1 which is still on 1.4.1, thanks!