Skip to content

fix(deep-linking): ignore native anchors that are not deep links#10904

Open
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/deep-linking-external-anchors
Open

fix(deep-linking): ignore native anchors that are not deep links#10904
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/deep-linking-external-anchors

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

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 calls setHash("/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?

  • New Jest unit suite test/unit/core/plugins/deep-linking/layout.js covering both the deep-link expansion paths and the regression case (#model-Category).
  • New Cypress spec test/e2e-cypress/e2e/bugs/10527.cy.js driving the real UI with a small OpenAPI fixture containing a Category model. Asserts the URL is preserved and the Model panel #model-Category is reachable.
  • Re-ran the full test/e2e-cypress/e2e/features/deep-linking.cy.js suite (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 0 clean on changed files.

Commands run

NODE_ENV=test BABEL_ENV=commonjs BROWSERSLIST_ENV=node-development \
  npx jest --config config/jest/jest.unit.config.js test/unit/core/plugins/deep-linking

npx cypress run --spec test/e2e-cypress/e2e/bugs/10527.cy.js
npx cypress run --spec test/e2e-cypress/e2e/features/deep-linking.cy.js

Screenshots

N/A - behavioural fix; observable via URL bar and native scroll position.

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation. (No public API or configuration changes; behaviour is now consistent with the documented #/ deep-link convention.)
  • I have updated the documentation accordingly. (Not applicable.)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

External links to swagger-ui anchors don't work

1 participant