Skip to content
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

fix broken mdx links #17080

Closed
wants to merge 2 commits into from
Closed

fix broken mdx links #17080

wants to merge 2 commits into from

Conversation

sag1v
Copy link

@sag1v sag1v commented Dec 27, 2021

Issue: #16918

What I did

chained the hash to the location.search instead of just passing it to navigate

I think this is a critical bug fix and should get released ASAP :)

@nx-cloud
Copy link

nx-cloud bot commented Dec 27, 2021

☁️ Nx Cloud Report

CI ran the following commands for commit 629f503. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@@ -49,8 +49,16 @@ export const CodeOrSourceMdx: FC<CodeOrSourceMdxProps> = ({ className, children,
);
};

function generateHrefWithHash(hash: string): string {
// eslint-disable-next-line no-undef
const location = window.parent ? window.parent.location : window.location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an illegal operation cross origin!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndelangen Got any suggestions to update the location?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, your link seems to point to a header called "gatsby-focus-wrapper" but i don't see it in the page

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the check should be Element instead of HTMLElement WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the issue is not the check but the fact that we're not passing the correct URL
We are passing only the hash and not appending it to the already existing URL or replacing it with existing hash in the URL.

Copy link
Author

@sag1v sag1v Jan 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we call addons.getChannel().emit(NAVIGATE_URL, url), where is the actual code that navigating? Maybe we will have access to the full URL there and we can change the logic there.

There's a getBase function in router.tsx

const getBase = () => `${document.location.pathname}?`;

What are the implications of document.location vs window.location?

BTW, the links in the side navigation are working perfectly, maybe we can re-use their logic?

@@ -49,8 +49,16 @@ export const CodeOrSourceMdx: FC<CodeOrSourceMdxProps> = ({ className, children,
);
};

function generateHrefWithHash(hash: string): string {
// eslint-disable-next-line no-undef
const location = window.parent ? window.parent.location : window.location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shilman
Copy link
Member

shilman commented Jan 5, 2022

Thanks @sag1v @ndelangen & apologies for the delay in getting to this

I bisected and confirmed that the code broke in 6.4.0-beta.20 which contains #16440 upgrading from reach-router to react-router

I believe the error is in this code: https://github.com/storybookjs/storybook/pull/16440/files#diff-f62af13e39612cc8ebcb82a37a3a55afa29dbea92a0bd94162404a5e7e52aca1R136-R144

And that there's a missing test case which corresponds to navigateTo('#some-hash'). Do you think you could fix the bug on that side of things?

@sag1v
Copy link
Author

sag1v commented Jan 5, 2022

@shilman I'm not sure i understand. I don't think we are even calling navigateTo in url.ts.
The only time i see we are calling this function is when we are switching from Docs tab to Canvas tab.

@shilman
Copy link
Member

shilman commented Jan 5, 2022

@sag1v You might be right. But it's definitely that PR that broke the behavior. Perhaps it's just how react-router handles navigation vs. reach-router. @ndelangen can you help out here?

@ndelangen
Copy link
Member

@shilman @yannbf and me looked at this together and came up with a solution so the hash-url is just handled correctly at the router's level.

I opened a PR #17134

Really really appreciate your help @sag1v

@sag1v
Copy link
Author

sag1v commented Jan 5, 2022

@ndelangen Thanks, i can't wait to test it in our project.

Just to add my 2 cent, i think this is where things started to break

@shilman
Copy link
Member

shilman commented Jan 5, 2022

closing this as it's superseded by #17134

@sag1v thanks so much for pushing on this 🙏

@shilman shilman closed this Jan 5, 2022
@sag1v
Copy link
Author

sag1v commented Jan 5, 2022

@shilman thank you!
Which version can I use to test it?

@shilman
Copy link
Member

shilman commented Jan 7, 2022

@sag1v 6.5.0-alpha.x

npx sb@next upgrade --prerelease

If you can confirm I'll patch it back and release it as part of 6.4.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants