wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

Ascii Codes not Converted in Production Webpack Build #254

Open epihel opened 5 years ago

epihel commented 5 years ago

Using the form on http://wix.github.io/react-templates/, the HTML <p>We&#8217;re here.</p> gets converted to React.createElement('p', {}, 'We\u2019re here.') as expected.

Using webpack, react-templates, and react-templates-loader in development, the output is also as expected.

But in the webpack production build, it's converted to r.createElement("p",{},"We’re here."), which renders as <p>We’re here.</p> in Chrome.

My webpack config is { test: /\.rt$/, loader: 'react-templates-loader?modules=es6' } and I'm using the latest node (10.13.0), react (16.6.1), react-templates (0.6.3), react-templates-loader (0.6.5), and webpack (4.25.1).

nippur72 commented 5 years ago

It's strange because it should be the same... I can't see why production should be different from development.

Anyway I remember I had some problem parsing HTML entities (that's how they are called) I traced it back to the cheerio library (used by react-templates), but I didn't solve it completely because I later moved to a template engine of my own.

epihel commented 5 years ago

It definitely has different output. In development, it's React.createElement('p', {}, 'We\u2019re here.') and in the production build it's r.createElement("p",{},"We’re here.").

But it looks like I need to add the UTF-8 charset to my JS tags. I already had <meta charset="utf-8"> on my HTML page. When I added the charset to my JavaScript tag, as in <script charset="utf-8" type="text/javascript" src="minified.js"></script>, the characters are rendered correctly in Chrome, Firefox, and Safari.