question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'defaultText' of undefined when markdown is added

See original GitHub issue

Using storybook 5.1.1 and a few add-ons registered - @storybook/addon-info storybook-addon-jsx @storybook/addon-knobs and a CRA typescript cut out.

This doesn’t works.

import React from "react";
import { withInfo } from "@storybook/addon-info";
import Label from "./label";
import { stories } from '../storybook';
import { text, boolean } from '@storybook/addon-knobs/react';

stories.add(
    "Label",
    () => (
        <Label
            text={text('text', 'Sample label')}
            isActive={boolean('isActive', true)}
        />
    ),
    {
        info: {
            text: `
                description or documentation about my component, supports markdown
                ~~~js
                    <Label
                        text={text('text', 'Sample label')}
                        isActive={boolean('isActive', true)}
                    />
                ~~~
            `
        }
    }
);

But as soon as I remove the below code, it renders atleast

~~~js
<Label
    text={text('text', 'Sample label')}
    isActive={boolean('isActive', true)}
/>
~~~

Exact ERROR

TypeError: Cannot read property 'defaultText' of undefined
    at http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:11483:24
    at handleInterpolation (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:1864:24)
    at serializeStyles (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:1949:15)
    at http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:2396:100
    at updateContextConsumer (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:89332:19)
    at beginWork (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:89520:14)
    at performUnitOfWork (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:93160:12)
    at workLoop (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:93200:24)
    at renderRoot (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:93283:7)
    at performWorkOnRoot (http://localhost:9001/vendors~main.5f6f9e23f73905b9af8f.bundle.js:94190:7)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:34 (8 by maintainers)

github_iconTop GitHub Comments

10reactions
liamrosscommented, Jun 12, 2019

The issue is only present when you try to add code blocks to the markdown. For basic documentation it works fine, but as soon as you insert a code block into the markdown it attempts to use the syntaxhighlighter.

https://github.com/storybookjs/storybook/blob/7ee997698df4908ec716c5cfb6b59053469b04a9/lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx#L32-L46

It breaks at line 36 specifically, at color: theme.color.defaultText, (but it would break anyways later on, this is just the first time you are tunneling into theme)

This is because theme is coming through as {} so theme.color is undefined and thus it breaks at theme.color.defaultText. Not sure why the theme is an empty object in this case, I’m not too familiar with the code / emotion-js which I think the theming is using.

Here’s what it should be:

https://github.com/storybookjs/storybook/blob/b19e5bc5c36d6d51257ae6f1eb43872634013813/lib/theming/src/base.ts#L36

Here’s where it is added to the theme:

https://github.com/storybookjs/storybook/blob/b19e5bc5c36d6d51257ae6f1eb43872634013813/lib/theming/src/global.ts#L104

Note: This is the final bug preventing our team from implementing this for a TypeScript-based ui-kit. All other major bugs seemed to have been resolved, this is the final crashing bug

7reactions
JonathanSpeekcommented, Jun 7, 2019

I have this issue as well… With 50+ components, removing the JS markdown from each story isn’t very doable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Markdown Value rendered "Uncaught TypeError: Cannot read ...
I have some javascript code that gives this error when I added Simple Markdown Uncaught TypeError: Cannot read property 'value' of undefined ...
Read more >
Markdown Mode for Emacs - Jason Blevins
A major mode for GNU Emacs for editing Markdown-formatted text files. ... URL ) by selectively adding or removing properties via the interactive...
Read more >
InterSystems Partner Directory
Fix "Cannot read property 'toLowerCase' of undefined" error on startup (#693). Report problem if isfs workspace definition points to non-existent server ...
Read more >
How to get content from the editor and set content | TinyMCE
After the TinyMCE editor is added to the initial example, ... Like the (annoying) “Cannot read property 'setContent' of null” error.
Read more >
Error in render: "TypeError: Cannot read property 'length' of ...
... Error in render: "TypeError: Cannot read property 'length' of undefined ... form-white"> <h2 class="text-center default-text py-3">Quizzes</h2> <ul ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found