fix(deep-linking): ignore native anchors that are not deep links#10904
Open
yogeshwaran-c wants to merge 1 commit into
Open
fix(deep-linking): ignore native anchors that are not deep links#10904yogeshwaran-c wants to merge 1 commit into
yogeshwaran-c wants to merge 1 commit into
Conversation
Previously, any non-empty URL hash was treated as a deep link, even when it did not start with the required "/" prefix. As a result, navigating to an external anchor such as `#model-Category` was silently rewritten to `#/operations-tag/model-Category`, breaking native anchor scrolling on initial page load. The deep-link parser now bails out when the hash is not rooted at "/" (after the optional "!" shebang prefix is consumed), leaving the browser to handle native anchor navigation as expected. Fixes swagger-api#10527
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.
Description
Fixes the deep-linking plugin so that hash fragments which are not Swagger UI deep links (e.g.
#model-Category) are no longer rewritten on initial page load. The plugin now only treats a hash as a deep link when it is rooted at/(optionally after the legacy!shebang). Other hashes are left untouched, allowing the browser to perform native anchor scrolling.Motivation and Context
Fixes #10527.
When loading Swagger UI from an external link that includes an anchor such as
https://petstore.swagger.io/#model-Category, the deep-linking parser strips the leading#, observes no leading/, and falls through to treat the entire fragment (model-Category) as a tag name. It then callssetHash("/operations-tag/model-Category"), replacing the original anchor and breaking the native scroll-to-id behaviour the user expected.The "forgotten leading slash" coercion has been in place since 2018 (#4349), but it is undocumented and not part of the deep-linking URL convention, which always uses
#/...or#!/.... Bailing out instead is safer and lets native anchors (Model panels, custom layouts, etc.) work correctly.How Has This Been Tested?
test/unit/core/plugins/deep-linking/layout.jscovering both the deep-link expansion paths and the regression case (#model-Category).test/e2e-cypress/e2e/bugs/10527.cy.jsdriving the real UI with a small OpenAPI fixture containing aCategorymodel. Asserts the URL is preserved and the Model panel#model-Categoryis reachable.test/e2e-cypress/e2e/features/deep-linking.cy.jssuite (98 tests, 96 passing, 2 pre-existing.skip) to confirm no regression for existing deep-link flows including legacy!/shebangs, whitespace, underscores, and UTF-16 tags.npx eslint --max-warnings 0clean on changed files.Commands run
Screenshots
N/A - behavioural fix; observable via URL bar and native scroll position.
Checklist
#/deep-link convention.)