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

Cannot anchor to headings in MDX documentation #18395

Closed
gyfchong opened this issue Jun 3, 2022 · 29 comments
Closed

Cannot anchor to headings in MDX documentation #18395

gyfchong opened this issue Jun 3, 2022 · 29 comments

Comments

@gyfchong
Copy link

gyfchong commented Jun 3, 2022

Describe the bug
When appending the ID of a heading to the URL ie. storybook.com#story-heading the page does not anchor down to the target heading.

Additionally, previously each heading had the ability to click an icon to create a link to the heading, this is now gone. Any manual links also do not work.

To Reproduce
Repo
Deploy

System
OS: macOS 12.4
CPU: (8) arm64 Apple M1 Pro
Binaries:
Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
Yarn: 3.2.1 - ~/.nvm/versions/node/v16.13.2/bin/yarn
npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
Browsers:
Chrome: 102.0.5005.61
Firefox: 100.0.2
Safari: 15.5
npmPackages:
@storybook/addon-actions: ^6.5.6 => 6.5.6
@storybook/addon-docs: ^6.5.6 => 6.5.6
@storybook/addon-essentials: ^6.5.6 => 6.5.6
@storybook/addon-interactions: ^6.5.6 => 6.5.6
@storybook/addon-links: ^6.5.6 => 6.5.6
@storybook/builder-webpack5: ^6.5.6 => 6.5.6
@storybook/manager-webpack5: ^6.5.6 => 6.5.6
@storybook/node-logger: ^6.5.6 => 6.5.6
@storybook/preset-create-react-app: ^4.1.2 => 4.1.2
@storybook/react: ^6.5.6 => 6.5.6
@storybook/testing-library: ^0.0.11 => 0.0.11

@luchn49
Copy link

luchn49 commented Jun 8, 2022

I've been running into the same issue. There's no longer an icon when trying to hover over the headers.

You can see it: https://storybookjs.netlify.app/official-storybook/?path=/story/addons-docs-markdown-docs--page.


Not sure if that issue is from storybook or MDX?

@gyfchong
Copy link
Author

gyfchong commented Jun 8, 2022

Not sure if that issue is from storybook or MDX?

Yeah not sure either, seems it only affects MDX type docs, and not the auto generated one from Storybook.

@hecspc
Copy link

hecspc commented Jun 8, 2022

Same here in v6.5.4. It looks the MDX render doesnt include the id in the heading elements.

This issue makes also plugins to include TOCs (like storybbok-docs-toc) unusable.

@javier-zabala-lenio
Copy link

Found the same issue in v6.5.7.

@shilman shilman added the mdx label Jun 9, 2022
@shilman shilman added this to the 6.5 stabilization milestone Jun 9, 2022
@sag1v
Copy link

sag1v commented Jul 11, 2022

Can confirm the issue is still there on v6.5.9.

As @gyfchong mentioned in this comment

... seems it only affects MDX type docs, and not the auto generated one from Storybook

I'm also experiencing the same behavior

@binh710
Copy link

binh710 commented Jul 13, 2022

Hey all, does anyone know which version of SB should I downgrade to to avoid this first? We need to release our SB to production this week.

@sag1v
Copy link

sag1v commented Jul 19, 2022

@shilman Is this being investigated by the team? I think its quite a critical issue because documentations without a way to share links is pretty poor experience.
A similar issue was resolved not so long ago BTW.

references
#17134
#17080

@binh710
Copy link

binh710 commented Jul 19, 2022

Hey all, does anyone know which version of SB should I downgrade to to avoid this first? We need to release our SB to production this week.

We have to downgrade SB back to 6.4.19 for now as our project rely heavily on mdx docs. Hopefully this get fix soon. :)

Cheers guys, thanks for maintaining SB! It's an awesome product <3

@yannbf
Copy link
Member

yannbf commented Jul 19, 2022

Hey everyone, sorry you're experiencing this issue! Took me some time but I finally found the culprit.
I'll discuss with the team and see what's the best way to bring a fix to this, so hang tight and we'll have something ready soon!

@shilman
Copy link
Member

shilman commented Jul 25, 2022

Yo-ho-ho!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-alpha.16 containing PR #18740 that references this issue. Upgrade today to the @future NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Jul 25, 2022
@sag1v
Copy link

sag1v commented Jul 25, 2022

@shilman Thanks 😊
Does this fix only apply for the v7 alpha release? We have the same issue on v6 as well (not sure if it's related to the mdx2 feature)

@ggascoigne
Copy link

I know it's a big request, but is there any chance of getting this fix backported to v6, it looks like v7 is a bit of a ways away still so it's not clear that that is a viable solution right now.

@gyfchong
Copy link
Author

Bumped to v6.5.10 and added the span, but Storybook ToC still won't work, seems they scan the MDX title id's for their anchors.

Have tried manually adding the # to the URL to anchor down but also doesn't work. Not sure what else to try.

@yannbf
Copy link
Member

yannbf commented Aug 10, 2022

Hey @gyfchong thanks for the update. As mentioned in the comment which closed this issue, the fix was added to Storybook 7.0 alpha. I don't think it's been ported back to 6.5, which must be the reason it didn't work for you. @shilman do you think we can patch this back?

@gyfchong
Copy link
Author

Hey @gyfchong thanks for the update. As mentioned in the comment which closed this issue, the fix was added to Storybook 7.0 alpha. I don't think it's been ported back to 6.5, which must be the reason it didn't work for you. @shilman do you think we can patch this back?

Ah I misunderstood the merged branch, I thought that was for storybook, but it was someone else's repo! 😅

@lazysergey
Copy link

@yannbf could we have this patch in v6 as well? as 7.0.0 is not released yet

@binh710 could you advice on how to downgrade please?
I tried to change versions in package.json manually with yarn install --force
image
but seems I have to downgrade babel-loader as well? having this error:

WARN Force closed preview build
ERR! TypeError: (0 , _coreCommon.getStorybookBabelConfig) is not a function

also I've tried npx storybook@6.4.19 init and yarn storybook@6.4.19 --automigrate without luck

thanks in advance 👍

@DzmVasileusky
Copy link

I am also thinking that essential bug fixes should be included into current stable version not a future one

@sag1v
Copy link

sag1v commented Sep 28, 2022

I totally agree. Maybe @shilman can reconsider?

@shilman
Copy link
Member

shilman commented Sep 28, 2022

Yay!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.13-alpha.0 containing PR #18740 that references this issue. Upgrade today to the @prerelease NPM tag to try it out!

npx sb upgrade --prerelease

@sag1v
Copy link

sag1v commented Sep 29, 2022

Awesome @shilman thanks! 🙏 Do you want us to test this before you release the next official 6.x.x version?

Edit

I did test it with `@storybook/react@6.5.13-alpha.0` and unfortunately its still not working. When i hover over the headers i still don't see the anchor button and there is no `id` for the elements.

Edit2
Sorry for the mixup, but it turns out i forgot to upgrade ALL of storybook's deps to 6.5.13-alpha.0. Once i did that it seems to work fine. 💪 🙂

@lazysergey
Copy link

lazysergey commented Sep 30, 2022

@sag1v how do you upgrade it to exact version? npx sb upgrade --prerelease command actually installed 7.0.0-alpha.34 for me:

Screenshot 2022-09-30 at 10 37 32 PM

@sag1v
Copy link

sag1v commented Sep 30, 2022

@sag1v how do you upgrade it to exact version? npx sb upgrade --prerelease command actually installed 7.0.0-alpha.34 for me:

Screenshot 2022-09-30 at 10 37 32 PM

Yeah I know its a shame 😞 i had to manually upgrade each package. That's why it didn't work out at first because i forgot to upgrade some packages.

@lazysergey
Copy link

lazysergey commented Sep 30, 2022

@sag1v tyvm, resolved for me, hope this will go live soon 🤞

what I did:
I've changed version manually and did yarn install:
image

If for someone this version still doesn't work, I would check the following:

  1. confirm that preset.js has PR #18740 change:
    image

  2. Check which id do you get in mdx.js where storybook decides if it should render Header or HeaderWithOcticonAnchor:
    image

  3. For me it still gives id: undefined for mdx documents that import *.md, but it finally works fine for mdx 🎉 🎉 🎉
    image

That's how I debugged, hope this could help someone :)

@sag1v
Copy link

sag1v commented Oct 23, 2022

@shilman Hey 👋
When do we expect to see version 6.5.13 released?

@shilman
Copy link
Member

shilman commented Oct 23, 2022

@sag1v sorry this fell off my radar. I want to get one more thing patched back to 6.5 in the next day or two and then will release. Thanks for your patience!

@sag1v
Copy link

sag1v commented Oct 23, 2022

@shilman Thanks!
Just heads-up, it turns out that npx sb upgrade --prerelease is installing version 7.x and not 6.x. Is there away to pass a major version or is it a bug that needs to get fixed?

@shilman
Copy link
Member

shilman commented Oct 23, 2022

We're going to change upgrade to allow you to specify an npm tag. For now it's just the way it works:

  • upgrade = latest stable
  • upgrade --prerelease = latest prerelease

@shilman
Copy link
Member

shilman commented Oct 24, 2022

Olé!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.13 containing PR #18740 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb upgrade

@Christo44
Copy link

Does not work. Page does not move if clicking on same page anchors. https://storybookjs.netlify.app/official-storybook/?path=/story/addons-docs-markdown-docs--page
Storybook 6.5.16

😢

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

No branches or pull requests