bimba-cli 0.5.7 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/serve.js +9 -10
package/package.json
CHANGED
package/serve.js
CHANGED
|
@@ -153,28 +153,27 @@ const hmrClient = `
|
|
|
153
153
|
|
|
154
154
|
// ── Style reaper ───────────────────────────────────────────────────────────
|
|
155
155
|
|
|
156
|
-
// imba_styles.register inserts <style id="
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
156
|
+
// imba_styles.register inserts <style data-id="<hash>"> blocks into <head>.
|
|
157
|
+
// Walk them, sample a few class selectors, and check whether any element
|
|
158
|
+
// in the document still uses one of those classnames. If not, the block
|
|
159
|
+
// is dead (its tag was hot-replaced with a new content hash and the old
|
|
160
|
+
// classnames are gone from the DOM) — remove it.
|
|
161
161
|
function _reapStyles() {
|
|
162
|
-
const styles = document.head.querySelectorAll('style[id
|
|
162
|
+
const styles = document.head.querySelectorAll('style[data-id]');
|
|
163
163
|
for (const style of styles) {
|
|
164
164
|
try {
|
|
165
165
|
const sheet = style.sheet;
|
|
166
|
-
if (!sheet) continue;
|
|
167
|
-
let used = false;
|
|
168
|
-
// Sample a few class selectors and check the document for them.
|
|
166
|
+
if (!sheet || !sheet.cssRules) continue;
|
|
169
167
|
const probes = [];
|
|
170
168
|
for (const rule of sheet.cssRules) {
|
|
171
169
|
if (probes.length >= 4) break;
|
|
172
170
|
const sel = rule.selectorText;
|
|
173
171
|
if (!sel) continue;
|
|
174
172
|
const m = sel.match(/\.(z[a-z0-9_-]+)/i);
|
|
175
|
-
if (m) probes.push(m[1]);
|
|
173
|
+
if (m && !probes.includes(m[1])) probes.push(m[1]);
|
|
176
174
|
}
|
|
177
175
|
if (!probes.length) continue;
|
|
176
|
+
let used = false;
|
|
178
177
|
for (const cls of probes) {
|
|
179
178
|
if (document.querySelector('.' + CSS.escape(cls))) { used = true; break; }
|
|
180
179
|
}
|