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

Addons-links with MDX #10846

Closed
ok2ju opened this issue May 20, 2020 · 34 comments
Closed

Addons-links with MDX #10846

ok2ju opened this issue May 20, 2020 · 34 comments

Comments

@ok2ju
Copy link

ok2ju commented May 20, 2020

Hello, I tried to use addon-links with MDX (addon-docs) and I wondered why story property of LinkTo (from react package) is required? I have several doc pages without Story at all and I want to navigate such pages using LinkTo. Btw, it works but annoying error drops in the console.

Cannot read property 'toLowerCase' of null

The error comes from sanitize method of storybookjs/csf package. hrefTo method trying to generate url but fails when calling method toId

Expected behavior
There are no errors in the console.

Code snippets

<LinkTo kind="MyDoc" />
@shilman
Copy link
Member

shilman commented May 20, 2020

Parent issue #6700

@stale
Copy link

stale bot commented Jun 10, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@blaine-stripe
Copy link

I also ran into this while investigating #11590 - is there a workaround for now?

@ndelangen
Copy link
Member

edited a mdx story:
Screenshot 2020-07-24 at 17 53 27

but it's not showing up:
Screenshot 2020-07-24 at 17 53 46
Screenshot 2020-07-24 at 17 53 57
Screenshot 2020-07-24 at 17 54 16

@ndelangen
Copy link
Member

I'm not sure if this was ever intended to work..

@blaine-stripe
Copy link

@ndelangen Hmm, it works in the code I'm looking at. Maybe it is because you have text on the same line? Can you try it with the LinkTo on it's own line?

@elektronik2k5
Copy link

I didn't check what happens when LinkTo is on it's own line, but can definitely confirm the issue when it isn't, cause all of our links are inline and the bug is consistently reproducible.

@ndelangen
Copy link
Member

ndelangen commented Jul 28, 2020

This seems to work:

import LinkTo from '@storybook/addon-links/react';

<Meta title="About/Intro" />

# Official-storybook

Welcome to `official-storybook`, a collection of test cases and demos for `@storybook/react` and all its addons.

Should be a link here >>> <LinkTo kind="test" story="index">Go to index</LinkTo> <<< Should be a link here

@ndelangen ndelangen self-assigned this Jul 28, 2020
@blaine-stripe
Copy link

Yeah, but if you have a "kind" without a "story", the component throws because of some internals.

@ndelangen
Copy link
Member

aha

@ndelangen
Copy link
Member

This is fixed in 6.0.0

I verified using:

import LinkTo from '@storybook/addon-links/react';

<Meta title="About/Intro" />

# Official-storybook

Welcome to `official-storybook`, a collection of test cases and demos for `@storybook/react` and all its addons.

Should be a link here >>> <LinkTo kind="Core/Args">Go to index</LinkTo> <<< Should be a link here

@isellsoap
Copy link

I’m still getting the error. I’m on the freshly released 6.0.0 version.

@shilman shilman reopened this Aug 11, 2020
@shilman
Copy link
Member

shilman commented Aug 11, 2020

Do you have a repro?

@isellsoap
Copy link

isellsoap commented Aug 11, 2020

@shilman Thanks for the follow-up! I created a minimal reproduction case: https://github.com/isellsoap/storybook-issue-10846

Visiting the "Introduction" story triggers the error in the browser console.

@ndelangen
Copy link
Member

Thanks for the repro, hopefully we'll be able to take a look quickly!

@shilman shilman added the todo label Sep 7, 2020
@shilman shilman added P0 and removed P0 labels Sep 25, 2020
@shilman
Copy link
Member

shilman commented Sep 25, 2020

@isellsoap I think it should be <LinkTo kind="Example/Button">. Does that work?

@isellsoap
Copy link

isellsoap commented Sep 28, 2020

@shilman I just tried it, using "Example/Button" produces the same error in the console.

@unematiii
Copy link

I'm also getting the same error, however when I also specify story, the error vanishes.

<LinkTo kind="base/atoms/misc/Component">Component</LinkTo>, works, but produces error.
<LinkTo kind="base/atoms/misc/Component" story="as-a-tag">Component</LinkTo> or ,<LinkTo kind="base/atoms/misc/Component" story="As a tag">Component</LinkTo> works without errors.

@storybookjs storybookjs deleted a comment from stale bot Sep 30, 2020
@isellsoap
Copy link

isellsoap commented Oct 7, 2020

@unematiii True, the errors don’t appear with story="as-a-tag". But the links themselves don’t work after applying the attribute. Do the links take you to the destination when clicking on them?

@unematiii
Copy link

@isellsoap Yeah, it works for me.

package.json:

"@storybook/addon-links": ">=6.0.25",

SomeComponent.stories.mdx:

import LinkTo from '@storybook/addon-links/react';

Uses <LinkTo kind="base/atoms/misc/Component" story="as-a-tag">Component</LinkTo> to provide corresponding slots.

base/atoms/misc/Component/Component.stories.mdx:

## As `a` tag

<Story name="As `a` tag">{Template.bind({})}</Story>

@empressmoon
Copy link

hi, I'm having the same issue:
I need to add links between docs in storybook, like so:

<LinkTo kind="Docs/Getting started">Getting started</LinkTo>

Links work fine, but I'm still getting the console error:

Zrzut ekranu 2020-10-14 o 12 58 04

Anyone can help?

@unematiii
Copy link

unematiii commented Oct 14, 2020

I think this needs to have name argument as optional. But then again, I'm not entirely sure if this makes sense for CSF.

Edit: This project would really benefit having strictNullChecks turned on for TS. I'm looking at the LinkTo impl. and while Props define both kind and story as string, defaultProps have both set to null.

@empressmoon
Copy link

thanks @unematiii :) Looking at this I got rid of the problem by adding story="page" to the LinkTo:

<LinkTo kind="Docs/Getting started" story="page">Getting started</LinkTo>

It's maybe a bit hacky but it works for now.

@unematiii
Copy link

@empressmoon Hmm, well it works without errors if you add a story, bot produces an error without this. If you don't have a story named page, the link doesn't work at all. Not sure if this is a workaround.

@tklives
Copy link

tklives commented May 18, 2021

Hello y'all!

I'm still running into this on v6.2.7 and am wondering if there is any timeline on resolution for allowing you to only supply a kind to a <LinkTo>, or if I shouldn't wait for that and instead just go add the story attribute to all of my links to sidestep those errors?

Thanks!

@shilman shilman removed this from the 6.2 docs milestone Jun 8, 2021
@devintyler
Copy link

This is still an issue on 6.3.4.

(As mentioned above) without a story prop an error is thrown in the console. The main issue is the sanitizing function, which expects a string to be passed in. If story was optional and the sanitize function wasn't called when it doesn't exist this would go away.

@shilman
Copy link
Member

shilman commented Aug 31, 2021

@devintyler any chance you can create a PR with those changes?

@unematiii
Copy link

@shilman The routine in question is part of CSF. I've submitted a PR quite some time ago.

@shilman
Copy link
Member

shilman commented Aug 31, 2021

@unematiii thanks for bringing it to my attention! Will discuss with @tmeasday and figure out the right way forward. 🙏

@blowsie
Copy link

blowsie commented Aug 23, 2022

Is there a solution for Vue + MDX?

@blowsie
Copy link

blowsie commented Aug 23, 2022

Is there a solution for Vue + MDX?

Importing the react component worked just fine

@TheColorRed
Copy link

TheColorRed commented Nov 22, 2022

I still cannot get this working in MDX addon-links v6.5.12 so I just created my own component with the linkTo function.

import { linkTo } from '@storybook/addon-links';
import React from 'react';

export class Link extends React.Component {
  constructor(props) {
    super(props);
    this.title = props.title;
    this.story = props.story;
    this.children = props.children;
  }

  render() {
    let style = { color: 'rgb(30, 167, 253)', textDecoration: 'none', cursor: 'pointer' };
    return (
      <a style={style} onClick={linkTo(this.title, this.story)}>
        {this.children}
      </a>
    );
  }
}

Usage in MDX:

import { Link } from './mdx';

<Link title="Story Title" story="Story">Go to Story</Link>

@ndelangen
Copy link
Member

I'm fairly sure this is no longer a problem in Storybook 7.0 beta. If someone could verify this, and report if it's still an issue?
A reproduction would be useful. 🙏

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