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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/serve.js +9 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/bimba.git"
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="_<hash>"> blocks into <head>.
157
- // We can't intercept register directly (it's inside the imba runtime), so
158
- // we walk all <style> elements with imba-style ids and check whether any
159
- // element in the document still uses one of the classnames declared in
160
- // the stylesheet. If not, the block is dead and gets removed.
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
  }