Docz: <Playground /> doesn't like '$'

Created on 8 Aug 2018  路  4Comments  路  Source: doczjs/docz

Bug Report

Describe the bug

Source:

<Playground>
  Playground is fine with the $ character by itself
</Playground>

Result:

screen shot 2018-08-08 at 2 30 55 pm


Source:

<Playground>
  Playground does not like the '$' character in single quotes
</Playground>

Result:

screen shot 2018-08-08 at 2 31 04 pm

Expected behavior

I expect that the playground result for the $ in single quotes will render properly, but it does not.

My guess is there's some regex magic going on and the source isn't being properly escaped.

bug

Most helpful comment

Hi @kentcdodds, this happens because we inject the children as a code prop for Playground via AST to show the code without any parsing. If you inspect the webpack code generated on devtools you will see something like that:

<Playground __position={1} __code={`This is a some ${1 + 1} content`}>
  This is a some ${1 + 1} content
</Playground>

So, if you wanna try to put '$' javascript will break because syntax error.

In the beginning, I tried to use jsx-to-string to make this works, but it has some bugs when you use render props, so I need to use this approach. I think that is not the best one, but was the only way that came to my mind 馃槙

All 4 comments

This also happens with backticks.

<Playground>
`This doesnt work`
 <MyComponent didMount={()=>{
    alert(`This also doesnt work`)
 }} />
</Playground>

Looks like the issue is here

I'm working on a fix, should have a PR soon 馃槃

Hi @kentcdodds, this happens because we inject the children as a code prop for Playground via AST to show the code without any parsing. If you inspect the webpack code generated on devtools you will see something like that:

<Playground __position={1} __code={`This is a some ${1 + 1} content`}>
  This is a some ${1 + 1} content
</Playground>

So, if you wanna try to put '$' javascript will break because syntax error.

In the beginning, I tried to use jsx-to-string to make this works, but it has some bugs when you use render props, so I need to use this approach. I think that is not the best one, but was the only way that came to my mind 馃槙

Fixed on the new v0.10.0 馃殌

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

koddr picture koddr  路  3Comments

ssylvia picture ssylvia  路  3Comments

mquandalle picture mquandalle  路  3Comments

hayk94 picture hayk94  路  3Comments

fenbka picture fenbka  路  3Comments