formatReactElementNode: convert displayName to String#515
Open
ckknight wants to merge 1 commit intoalgolia:masterfrom
Open
formatReactElementNode: convert displayName to String#515ckknight wants to merge 1 commit intoalgolia:masterfrom
ckknight wants to merge 1 commit intoalgolia:masterfrom
Conversation
If the `displayName` for a component turns out to be a `symbol` for some reason, ECMAScript will fail early when trying to implicitly convert it to a string. This explicitly converts to a string so that at least execution isn't halted.
Collaborator
|
Hi @ckknight, Thanks for reporting this. I'm curious to understand in witch case the component |
Collaborator
|
I just see your PR https://github.com/storybookjs/storybook/issues/9568 I can reproduce the issue with a test: it('reactElementToJSXString(<Suspense fallback={() => "Loading..."}>Hello world</Suspense></script>)', () => {
expect(
reactElementToJSXString(
<Suspense fallback={() => 'Loading...'}>Hello world</Suspense>
)
).toEqual(
`<Suspense fallback={() => 'Loading...'}>Hello world</Suspense>` // I'm not sure we could have exactly this output
);
});
/*
TypeError: Cannot convert a Symbol value to a string
at String.concat (<anonymous>)
120 | } = options;
121 |
> 122 | let out = `<${displayName}`;
| ^
123 |
124 | let outInlineAttr = out;
125 | let outMultilineAttr = out;
at _default (src/formatter/formatReactElementNode.js:122:10)
at _default (src/formatter/formatTreeNode.js:50:12)
at _default (src/formatter/formatTree.js:8:3)
at reactElementToJsxString (src/index.js:40:10)
at Object.<anonymous> (src/index.spec.js:221:7)
*/ |
|
This is How React team gets component name. https://github.com/facebook/react/blob/master/packages/shared/getComponentNameFromType.js But, I'm not sure what the best solution for using this module. Copy files?? or other way?? |
csantos1113
approved these changes
Nov 29, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the
displayNamefor a component turns out to be asymbolfor some reason, ECMAScript will fail early when trying to implicitly convert it to a string. This explicitly converts to a string so that at least execution isn't halted.