Skip to content

Commit 1d98542

Browse files
committed
修复 vercel#589 css content unicode render error
1 parent 263d52b commit 1d98542

File tree

9 files changed

+52
-45
lines changed

9 files changed

+52
-45
lines changed

CHANGELOG.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
### `2020.05.18`
2-
- **`feat`**: `optional style tag`,eg:
3-
```javascript
4-
{ bool && <style jsx></style> }
5-
```
6-
- **`fix`**: 修复多个dynamic导致属性设置出错bug
7-
```javascript
8-
<style jsx>{`
9-
.a { color: ${this.state.color} }
10-
`}</style>
1+
- ## version: **`4.2.3`**
2+
*2020.05.24*
3+
- **`fix`**: [#589 CSS content property no longer renders encoded characters](https://github.com/zeit/styled-jsx/issues/589)
114

12-
<style jsx>{`
13-
.b { font-size: ${this.state.fontSize} }
14-
`}</style>
15-
```
5+
- ## version: **`4.2.2`**
6+
*2020.05.18*
7+
- **`feat`**: `optional style tag`,eg:
8+
```javascript
9+
{ bool && <style jsx></style> }
10+
```
11+
- **`fix`**: 修复多个dynamic导致属性设置出错bug
12+
```javascript
13+
<style jsx>{`
14+
.a { color: ${this.state.color} }
15+
`}</style>
16+
17+
<style jsx>{`
18+
.b { font-size: ${this.state.fontSize} }
19+
`}</style>
20+
```

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ciiri/styled-jsx",
3-
"version": "4.2.2",
3+
"version": "4.2.3",
44
"license": "MIT",
55
"repository": "https://github.com/singleparty/styled-jsx",
66
"description": "Full CSS support for JSX without compromises",

readme.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# @ciiri/styled-jsx
22

3-
### fork 自 [`styled-jsx`](https://github.com/zeit/styled-jsx)目的在于修复某些 bug,`api` 可参考原来的库,其中改动点如下:
3+
### fork 自 [`styled-jsx`](https://github.com/zeit/styled-jsx)`api` 可参考原来的库。改动点如下:
44

5-
- `scopeId` 插入到属性而不是 `class`
5+
- `scopeId` 插入到属性而不是原本的 `class`
66

77
```javascript
88
<div class="orange" jsx-302262132 jsx-175175684 />
99
```
1010

11-
- 修改底层 css 编译库 `stylis``@vue/component-compiler-utils`修复 bug [-webkit-keyframes add unexpect scope id](https://github.com/thysultan/stylis.js/issues/200)
11+
- 修改底层 css 编译库 `stylis``@vue/component-compiler-utils`fix bug [-webkit-keyframes add unexpect scope id](https://github.com/thysultan/stylis.js/issues/200)
1212

13-
- 修复 `import style from 'xxx.module.scss` 语法无法兼容 `css-loader` 问题(这个不算 bug,只是找到一个解决方案 [`extract-loader`](https://github.com/peerigon/extract-loader)
13+
- 解决 `import style from 'xxx.module.scss` 语法无法兼容 `css-loader` 问题(方案:[`extract-loader`](https://github.com/peerigon/extract-loader)
1414

1515
- `css` 语法与vue保持一致(因为换了编译库),如果用scss的话,简单使用如下:
1616
```css
@@ -32,7 +32,7 @@
3232
}
3333
```
3434

35-
- *`2020.05.18`* 新增 `optional style tag` 用法
35+
- **`version 4.2.2`** 新增 `optional style tag` 用法
3636
```javascript
3737
{ this.state.optional && <style jsx>{`
3838
.optional {
@@ -42,6 +42,8 @@
4242
`}</style> }
4343
```
4444

45+
- 以后`README`只同步新特性,bug相关修复同步在`CHANGELOG`
46+
4547

4648
### 已有项目如何接入
4749

src/_utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ export const getJSXStyleInfo = (expr, scope) => {
308308
// Simple template literal without expressions
309309
if (node.expressions.length === 0) {
310310
return {
311-
hash: hashString(node.quasis[0].value.raw),
312-
css: node.quasis[0].value.raw,
311+
hash: hashString(node.quasis[0].value.cooked),
312+
css: node.quasis[0].value.cooked,
313313
expressions: [],
314314
dynamic: false,
315315
location
@@ -334,7 +334,7 @@ export const getJSXStyleInfo = (expr, scope) => {
334334
const dynamic = scope ? isDynamic(expr, scope) : false
335335
const css = quasis.reduce(
336336
(css, quasi, index) =>
337-
`${css}${quasi.value.raw}${
337+
`${css}${quasi.value.cooked}${
338338
quasis.length === index + 1 ? '' : `%%styled-jsx-placeholder-${index}%%`
339339
}`,
340340
''

test/fixtures/expressions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,13 @@ export default ({ display }) => (
8484
content: '\`';
8585
}
8686
`}</style>
87+
<style jsx>{`
88+
.green:before {
89+
content: '\\590d\\6d3b\\000d\\000a';
90+
}
91+
.green:after {
92+
content: ${'"\\590d\\6d3b\\000d\\000a"'};
93+
}
94+
`}</style>
8795
</div>
8896
)

test/fixtures/transform2.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.green:after {
2+
content: "\590d\6d3b\000d\000a";
3+
}
4+
.green:before {
5+
content: "`";
6+
}
7+
.App::v-deep .orange {
8+
animation: scaleIn 3s ease-in forwards;
9+
}

test/fixtures/webpack-loader-transform-css.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/webpack.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import test from 'ava'
22
import sinon from 'sinon'
33
import loaderUtils from 'loader-utils'
44
import webpack from '../src/webpack'
5-
import { normal } from './fixtures/webpack-loader-transform-css'
5+
import read from './_read'
66

7-
test('webpack loader 编译 css - default', t => {
7+
test('webpack loader 编译 css - default', async t => {
88
const content = {
99
resourcePath: '/src/App.module.scss',
1010
addDependency: () => {},
1111
callback: sinon.spy()
1212
}
13+
const css = await read('./fixtures/transform2.css')
1314
const double = [
1415
sinon.stub(loaderUtils, 'getOptions').callsFake(() => null),
1516
sinon.stub(loaderUtils, 'parseQuery').callsFake(() => ({}))
1617
]
17-
webpack.call(content, normal)
18+
webpack.call(content, css)
1819
double.forEach(stub => stub.restore())
1920
const args = content.callback.args[0]
2021
t.snapshot(args)

0 commit comments

Comments
 (0)