-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon-docs: Support absolute anchors when deployed at non-root #11403
Conversation
// If storybook is hosted at a non-root path (e.g. `/storybook/`), | ||
// the base url needs to be prefixed to storybook paths. | ||
let storybookBaseUrl = | ||
typeof window !== 'undefined' ? window.parent.document.location.pathname : '/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This access should be safe, even if the content is rendered outside of an iframe.
From MDN:
If a window does not have a parent, its parent property is a reference to itself.
I'm not sure why some tests failed. Are they related to my change? Can you help me with them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @amannn!
Were you able to test it on your dev machine somehow? How about:
yarn bootstrap --core
cd examples/official-storybook
yarn build-storybook
npx http-server
open localhost:9011/storybook-static
@shilman Thanks for the review and your snippet! I've tested it previously in a project of mine by editing I've added:
to
(note that The anchor is rendered correctly and the link takes you to the color palette 🙂 . I wasn't sure if there's any reasonable place in the code base where such an anchor would make sense, so we have a story to test this behaviour? |
@shilman is there anything I can do to get this merged? |
Issue: #11404
What I did
When Storybook is deployed at an URL like
https://example.com/storybook/component-library/v48.3.2/
, the anchors within docs content will remove the base url.E.g. when you're on
https://example.com/storybook/component-library/v48.3.2/?path=/docs/components-icon--default
and you have a link to/docs/components-button--default
in the documentation, the resulting link will point tohttps://example.com/?path=/docs/components-button--default
.How to test
If your answer is yes to any of these, please make sure to include it in your PR.
Not sure if there's a good way to add a test for this, as it depends on a special kind of deployment?