Guard tab auto-activation against a stale remembered tab id (#2922) - #3149
Open
wakqasahmed wants to merge 1 commit into
Open
wakqasahmed wants to merge 1 commit into
wakqasahmed wants to merge 1 commit into
Conversation
…ftware#2922) connect() reads the last-active tab id for the current pathname from localStorage and calls Tab.getOrCreateInstance(document.getElementById(activeId)).show() without checking that an element with that id still exists. If the stored id belongs to a tab that isn't present on this particular render of the screen (route reused for different content, tab markup changed since the id was saved, etc.), getElementById returns null and Bootstrap's Tab throws trying to read config off it, breaking tab auto-selection and any script that runs after it on page load. Only call Tab.getOrCreateInstance() when the remembered id actually resolves to an element.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2922
Proposed Changes
tabs_controller.jsremembers the last active tab id per pathname inlocalStorageand, onconnect(), replays it withTab.getOrCreateInstance(document.getElementById(activeId)).show(). If the stored id doesn't resolve to an element on this particular render of the screen (same pathname reused for different content, tab markup changed since the id was saved, etc.),document.getElementById()returnsnulland Bootstrap'sTabthrows trying to read config off it, breaking auto-activation and any other init code that runs after it.Tab.getOrCreateInstance()once the remembered id has actually resolved to an element.Same as the other JS controller fixes in this repo, there's no automated test harness to hook a regression test into, so this was verified by tracing through the controller's
connect()logic for both the case where the stored id matches an existing tab and the case where it's stale.