Skip to content

Commit 45f4463

Browse files
committed
Revert 87952b4 because of #1565
1 parent 3ff801f commit 45f4463

23 files changed

Lines changed: 87 additions & 699 deletions

File tree

docs/jss-api.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,12 @@ const sheet2 = jss.createStyleSheet({}, {index: 1, meta: 'sheet-2'}).attach()
196196

197197
## Add a rule to an existing Style Sheet
198198

199-
`sheet.addRule(nameOrSelector, style, [options])`
199+
`sheet.addRule([name], style, [options])`
200200

201201
This function will use [insertRule](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule) API if your Style Sheet is already attached to the DOM. In this case **you will not see this CSS Rule in the "Elements" view of the dev tools**. You can always verify correct rendering by using the selector on some DOM Node and watch styles applied as well as in the "Styles" inspector.
202202

203203
If you use `addRule()` before you call `attach()`, styles will be rendered in one batch using `textContent` API which will not have the above-described side effect.
204204

205-
## Replace a rule in an existing Style Sheet
206-
207-
`sheet.replaceRule(nameOrSelector, style, [options])`
208-
209-
Same as `sheet.addRule(...)` but replaces a rule with the same name if found.
210-
211205
### Options
212206

213207
- `index` - index where the rule should be added, by default, rules get pushed at the end.

packages/css-jss/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"css-jss.js": {
3-
"bundled": 60043,
4-
"minified": 21979,
5-
"gzipped": 7382
3+
"bundled": 59688,
4+
"minified": 21828,
5+
"gzipped": 7357
66
},
77
"css-jss.min.js": {
8-
"bundled": 58968,
9-
"minified": 21356,
10-
"gzipped": 7102
8+
"bundled": 58613,
9+
"minified": 21205,
10+
"gzipped": 7078
1111
},
1212
"css-jss.cjs.js": {
1313
"bundled": 2949,

packages/jss-plugin-global/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"jss-plugin-global.js": {
3-
"bundled": 5294,
4-
"minified": 2313,
5-
"gzipped": 940
3+
"bundled": 4988,
4+
"minified": 2184,
5+
"gzipped": 919
66
},
77
"jss-plugin-global.min.js": {
8-
"bundled": 5294,
9-
"minified": 2313,
10-
"gzipped": 940
8+
"bundled": 4988,
9+
"minified": 2184,
10+
"gzipped": 919
1111
},
1212
"jss-plugin-global.cjs.js": {
13-
"bundled": 4551,
14-
"minified": 2439,
15-
"gzipped": 911
13+
"bundled": 4263,
14+
"minified": 2310,
15+
"gzipped": 892
1616
},
1717
"jss-plugin-global.esm.js": {
18-
"bundled": 4205,
19-
"minified": 2165,
20-
"gzipped": 806,
18+
"bundled": 3917,
19+
"minified": 2036,
20+
"gzipped": 788,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 55,

packages/jss-plugin-global/src/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ class GlobalContainerRule {
4141
return rule
4242
}
4343

44-
/**
45-
* Replace rule, run plugins.
46-
*/
47-
replaceRule(name, style, options) {
48-
const newRule = this.rules.replace(name, style, options)
49-
if (newRule) this.options.jss.plugins.onProcessRule(newRule)
50-
return newRule
51-
}
52-
5344
/**
5445
* Get index of a rule.
5546
*/
@@ -155,7 +146,7 @@ export default function jssGlobal() {
155146
}
156147
}
157148

158-
if (!options.selector && options.scoped === false) {
149+
if (options.scoped === false) {
159150
options.selector = name
160151
}
161152

packages/jss-plugin-global/src/index.test.js

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -37,94 +37,6 @@ describe('jss-plugin-global', () => {
3737
it('should generate correct CSS', () => {
3838
expect(sheet.toString()).to.be('a {\n color: red;\n}\nbody {\n color: green;\n}')
3939
})
40-
41-
describe('addRule', () => {
42-
let globalRule
43-
beforeEach(() => {
44-
globalRule = sheet.getRule('@global')
45-
globalRule.addRule('button', {margin: 0})
46-
globalRule.addRule('li', {float: 'left'})
47-
})
48-
49-
it('should add rule', () => {
50-
expect(globalRule.getRule('button')).to.not.be(undefined)
51-
expect(globalRule.getRule('li')).to.not.be(undefined)
52-
})
53-
54-
it('should generate correct CSS', () => {
55-
expect(sheet.toString()).to.be(stripIndent`
56-
a {
57-
color: red;
58-
}
59-
body {
60-
color: green;
61-
}
62-
button {
63-
margin: 0;
64-
}
65-
li {
66-
float: left;
67-
}
68-
`)
69-
})
70-
})
71-
72-
describe('replaceRule', () => {
73-
let globalRule
74-
let previousA
75-
beforeEach(() => {
76-
globalRule = sheet.getRule('@global')
77-
previousA = globalRule.getRule('a')
78-
globalRule.replaceRule('a', {color: 'yellow'})
79-
globalRule.replaceRule('li', {float: 'left'})
80-
})
81-
82-
it('should replace and add rule', () => {
83-
expect(globalRule.getRule('a')).to.not.be(previousA)
84-
expect(globalRule.getRule('li')).to.not.be(undefined)
85-
})
86-
87-
it('should generate correct CSS', () => {
88-
expect(sheet.toString()).to.be(stripIndent`
89-
a {
90-
color: yellow;
91-
}
92-
body {
93-
color: green;
94-
}
95-
li {
96-
float: left;
97-
}
98-
`)
99-
})
100-
})
101-
102-
describe('addRule / replaceRule with selector', () => {
103-
let globalRule
104-
beforeEach(() => {
105-
globalRule = sheet.getRule('@global')
106-
globalRule.addRule('arbitrary-name-1', {color: 'red'}, {selector: 'span'})
107-
globalRule.replaceRule('arbitrary-name-2', {float: 'left'}, {selector: 'ul'})
108-
globalRule.replaceRule('a', {display: 'block'}, {selector: 'div'})
109-
})
110-
111-
it('should generate correct CSS', () => {
112-
expect(sheet.toString()).to.be(stripIndent`
113-
div {
114-
display: block;
115-
}
116-
body {
117-
color: green;
118-
}
119-
span {
120-
color: red;
121-
}
122-
ul {
123-
float: left;
124-
}
125-
`)
126-
})
127-
})
12840
})
12941

13042
describe('@global linked', () => {

packages/jss-plugin-nested/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"jss-plugin-nested.js": {
3-
"bundled": 4505,
4-
"minified": 1640,
5-
"gzipped": 894
3+
"bundled": 4456,
4+
"minified": 1618,
5+
"gzipped": 881
66
},
77
"jss-plugin-nested.min.js": {
8-
"bundled": 4065,
9-
"minified": 1424,
10-
"gzipped": 768
8+
"bundled": 4016,
9+
"minified": 1402,
10+
"gzipped": 754
1111
},
1212
"jss-plugin-nested.cjs.js": {
13-
"bundled": 3776,
14-
"minified": 1600,
15-
"gzipped": 822
13+
"bundled": 3729,
14+
"minified": 1578,
15+
"gzipped": 808
1616
},
1717
"jss-plugin-nested.esm.js": {
18-
"bundled": 3357,
19-
"minified": 1277,
20-
"gzipped": 705,
18+
"bundled": 3310,
19+
"minified": 1255,
20+
"gzipped": 693,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 64,

packages/jss-plugin-nested/src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ export default function jssNested() {
8888
// Replace all $refs.
8989
selector = selector.replace(refRegExp, replaceRef)
9090

91-
const name = `${styleRule.key}-${prop}`
92-
container.replaceRule(name, style[prop], {...options, selector})
91+
container.addRule(selector, style[prop], {...options, selector})
9392
} else if (isNestedConditional) {
9493
// Place conditional right after the parent rule to ensure right ordering.
9594
container

packages/jss-plugin-nested/src/index.test.js

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -127,85 +127,6 @@ describe('jss-plugin-nested', () => {
127127
})
128128
})
129129

130-
describe('identical nest', () => {
131-
describe('single nest', () => {
132-
let sheet
133-
134-
beforeEach(() => {
135-
sheet = jss.createStyleSheet({
136-
a: {
137-
float: 'left',
138-
'&': {color: 'blue'}
139-
}
140-
})
141-
})
142-
143-
it('should add rule', () => {
144-
expect(sheet.getRule('a')).to.not.be(undefined)
145-
})
146-
147-
it('should generate correct CSS', () => {
148-
expect(sheet.toString()).to.be(stripIndent`
149-
.a-id {
150-
float: left;
151-
}
152-
.a-id {
153-
color: blue;
154-
}
155-
`)
156-
})
157-
})
158-
159-
describe('deep nest', () => {
160-
let sheet
161-
162-
beforeEach(() => {
163-
sheet = jss.createStyleSheet({
164-
a: {
165-
float: 'left',
166-
'&': {
167-
color: 'blue',
168-
'&': {
169-
width: 0,
170-
'&.b': {
171-
'z-index': 1,
172-
'&': {
173-
top: 0
174-
}
175-
}
176-
}
177-
}
178-
}
179-
})
180-
})
181-
182-
it('should add rules', () => {
183-
expect(sheet.getRule('a')).to.not.be(undefined)
184-
expect(sheet.getRule('.a-id.b')).to.not.be(undefined)
185-
})
186-
187-
it('should generate correct CSS', () => {
188-
expect(sheet.toString()).to.be(stripIndent`
189-
.a-id {
190-
float: left;
191-
}
192-
.a-id {
193-
color: blue;
194-
}
195-
.a-id {
196-
width: 0;
197-
}
198-
.a-id.b {
199-
z-index: 1;
200-
}
201-
.a-id.b {
202-
top: 0;
203-
}
204-
`)
205-
})
206-
})
207-
})
208-
209130
describe('.addRules()', () => {
210131
let sheet
211132

0 commit comments

Comments
 (0)