strothj / react-docgen-typescript-loader

Webpack loader to generate docgen information from Typescript React components.
Other
360 stars 47 forks source link

Text children of components get removed #7

Closed eramdam closed 6 years ago

eramdam commented 6 years ago

If one of the components importer has text children, those get removed when imported into Storybook.

See the screenshots below

Removed children
Children being kept

You can see that a workaround is to put whatever text into a variable and then pass that variable as the child of the elements but that's not very ideal obviously 😅

Interestingly, I managed to reproduce the same issue in the example configuration available in the repo by applying this diff

diff --git i/example/src/components/ColorButton.stories.tsx w/example/src/components/ColorButton.stories.tsx
index 46d2b05..d59c3d5 100644
--- i/example/src/components/ColorButton.stories.tsx
+++ w/example/src/components/ColorButton.stories.tsx
@@ -2,11 +2,14 @@ import * as React from "react";
 import { storiesOf } from "@storybook/react";
 import { withInfo } from "@storybook/addon-info";
 // import ColorButton from "./ColorButton";
-import { ColorButton } from "./ColorButton";
+import { ColorButton, Dummy } from "./ColorButton";

 storiesOf("Components", module).add(
   "ColorButton",
   withInfo({ inline: true })(() => (
-    <ColorButton color="blue">Color Button</ColorButton>
+    <div>
+      <Dummy />
+      <ColorButton color="blue">Color Button</ColorButton>
+    </div>
   )),
 );
diff --git i/example/src/components/ColorButton.tsx w/example/src/components/ColorButton.tsx
index 1b9bd95..e46bdb8 100644
--- i/example/src/components/ColorButton.tsx
+++ w/example/src/components/ColorButton.tsx
@@ -28,4 +28,8 @@ export const ColorButton: React.SFC<ColorButtonProps> = props => (
   </button>
 );

+export const Dummy: React.SFC = () => <div>
+  Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates, beatae? Voluptas vero, blanditiis, maiores atque provident iste eveniet corrupti officia placeat quae pariatur aspernatur dolore dolores quia! Eos, omnis aperiam.
+</div>
+
 export default ColorButton;
strothj commented 6 years ago

Thanks for the report. I'm taking a look now.

strothj commented 6 years ago

I managed to reproduce the issue. The issue appears to be present when this loader is disabled.

It appears to be an issue with the Storybook addon itself. Can you confirm?

eramdam commented 6 years ago

I don't. I removed the withInfo call from the stories files entirely and I can still see my text being removed with the loader is present in the webpack config :/

I uploaded the example folder below in case that helps example.zip

strothj commented 6 years ago

Thank you for the reproduction, I see what you mean. I'm having a look now.

strothj commented 6 years ago

@eramdam Can you try version 2.0.2 ? I believe this is resolved now.

eramdam commented 6 years ago

@strothj Seems like it! Thanks for the quick fix! :)