Skip to content

Commit f4cf0d2

Browse files
refactor: restore hmr for lazy styles after refactor (#418)
1 parent 3824f83 commit f4cf0d2

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/index.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ if (module.hot) {
6666
var lastRefs = module.hot.data && module.hot.data.refs || 0;
6767
6868
if (lastRefs) {
69-
exports.ref();
69+
exports.use();
70+
7071
if (!content.locals) {
7172
refs = lastRefs;
7273
}
@@ -94,8 +95,13 @@ var options = ${JSON.stringify(options)};
9495
options.insert = ${insert};
9596
options.singleton = ${isSingleton};
9697
97-
if (typeof content === 'string') content = [[module.id, content, '']];
98-
if (content.locals) exports.locals = content.locals;
98+
if (typeof content === 'string') {
99+
content = [[module.id, content, '']];
100+
}
101+
102+
if (content.locals) {
103+
exports.locals = content.locals;
104+
}
99105
100106
exports.use = function() {
101107
if (!(refs++)) {
@@ -134,8 +140,9 @@ if (module.hot) {
134140
`!!${request}`
135141
)});
136142
137-
if (typeof newContent === 'string')
143+
if (typeof newContent === 'string') {
138144
newContent = [[module.id, newContent, '']];
145+
}
139146
140147
var locals = (function(a, b) {
141148
var key,
@@ -151,8 +158,9 @@ if (module.hot) {
151158
return idx === 0;
152159
}(content.locals, newContent.locals));
153160
154-
if (!locals)
161+
if (!locals) {
155162
throw new Error('Aborting CSS HMR due to changed css-modules locals.');
163+
}
156164
157165
update(newContent);
158166
}
@@ -169,9 +177,9 @@ if (module.hot) {
169177
`!!${request}`
170178
)});
171179
172-
if (typeof content === 'string') content = [[module.id, content, '']];
173-
174-
var insertInto;
180+
if (typeof content === 'string') {
181+
content = [[module.id, content, '']];
182+
}
175183
176184
var options = ${JSON.stringify(options)}
177185
@@ -183,7 +191,9 @@ var update = require(${loaderUtils.stringifyRequest(
183191
`!${path.join(__dirname, 'runtime/injectStylesIntoStyleTag.js')}`
184192
)})(content, options);
185193
186-
if (content.locals) module.exports = content.locals;
194+
if (content.locals) {
195+
module.exports = content.locals;
196+
}
187197
${hmrCode}`;
188198
}
189199
}

0 commit comments

Comments
 (0)