Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

<Playground /> doesn't like '$' #201

Closed
kentcdodds opened this issue Aug 8, 2018 · 4 comments
Closed

<Playground /> doesn't like '$' #201

kentcdodds opened this issue Aug 8, 2018 · 4 comments
Labels
bug Something isn't working

Comments

@kentcdodds
Copy link
Contributor

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.

@kentcdodds kentcdodds changed the title <Playground /> doesn't like $ <Playground /> doesn't like '$' Aug 8, 2018
@rakannimer
Copy link
Contributor

rakannimer commented Aug 9, 2018

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 😄

@pedronauck
Copy link
Member

pedronauck commented Aug 9, 2018

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 😕

@pedronauck
Copy link
Member

Fixed on the new v0.10.0 🚀

@kentcdodds
Copy link
Contributor Author

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants