mnfst 0.5.322 → 0.5.324

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.
@@ -740,12 +740,20 @@ class TailwindCompiler {
740
740
 
741
741
  // Ensure #manifest-styles is last in head so our responsive/variant rules win over Tailwind and any later-injected styles
742
742
  TailwindCompiler.prototype.ensureUtilityStylesLast = function () {
743
- if (this.styleElement && this.styleElement.parentNode && document.head.lastElementChild !== this.styleElement) {
744
- document.head.appendChild(this.styleElement);
745
- if (this.resyncUtilitiesText) this.resyncUtilitiesText();
746
- }
743
+ if (!this.styleElement || !this.styleElement.parentNode) return;
744
+ // Only a stylesheet after ours can out-order it (scripts and meta tags cannot)
745
+ let later = this.styleElement.nextElementSibling;
746
+ while (later && !isStylesheetNode(later)) later = later.nextElementSibling;
747
+ if (!later && this.styleElement.parentNode === document.head) return;
748
+ document.head.appendChild(this.styleElement);
749
+ if (this.resyncUtilitiesText) this.resyncUtilitiesText();
747
750
  };
748
751
 
752
+ // Any <link> counts: a preload can become a stylesheet after insertion
753
+ function isStylesheetNode(node) {
754
+ return node.localName === 'style' || node.localName === 'link';
755
+ }
756
+
749
757
  // When any element is added to head after ours, move #manifest-styles to end. Handles CDN load order (e.g. Tailwind injecting after we run).
750
758
  TailwindCompiler.prototype.setupUtilityStylesOrderObserver = function () {
751
759
  if (!document.head || !this.styleElement) return;
@@ -755,6 +763,7 @@ TailwindCompiler.prototype.setupUtilityStylesOrderObserver = function () {
755
763
  if (mutation.type !== 'childList' || !mutation.addedNodes.length) continue;
756
764
  for (const node of mutation.addedNodes) {
757
765
  if (node.nodeType !== Node.ELEMENT_NODE || node === self.styleElement) continue;
766
+ if (!isStylesheetNode(node)) continue;
758
767
  self.ensureUtilityStylesLast();
759
768
  break;
760
769
  }
@@ -859,7 +868,10 @@ TailwindCompiler.prototype.scanStaticClasses = async function () {
859
868
 
860
869
  const componentUrls = [];
861
870
 
862
- if (registry && registry.manifest) {
871
+ // A complete shipped sheet was baked from these same files: nothing to learn by fetching them
872
+ const baked = !!document.querySelector('[data-mnfst-utilities][data-mnfst-utilities-complete]');
873
+
874
+ if (!baked && registry && registry.manifest) {
863
875
  // Get all component paths from manifest
864
876
  const allComponents = [
865
877
  ...(registry.manifest.preloadedComponents || []),
@@ -1073,6 +1085,12 @@ TailwindCompiler.prototype.getUsedClasses = function () {
1073
1085
  }
1074
1086
  };
1075
1087
 
1088
+ function isDevHostname(host) {
1089
+ const h = String(host || '').toLowerCase();
1090
+ return !h || h === 'localhost' || h === '127.0.0.1' || h === '[::1]' || h === '::1' || h === '0.0.0.0' ||
1091
+ h.endsWith('.localhost') || h.endsWith('.local') || h.endsWith('.test');
1092
+ }
1093
+
1076
1094
  // Fetch theme content from CSS files
1077
1095
  TailwindCompiler.prototype.fetchThemeContent = async function () {
1078
1096
  const themeContents = new Set();
@@ -1116,25 +1134,33 @@ TailwindCompiler.prototype.fetchThemeContent = async function () {
1116
1134
  cacheTime = this.hasScannedStatic ? 5000 : 30000;
1117
1135
  }
1118
1136
 
1119
- if (cached && (now - cached.timestamp) < cacheTime) {
1137
+ // Off a dev host a stylesheet never changes under a loaded page: fetch once, from the HTTP cache
1138
+ const dev = isDevHostname(location.hostname);
1139
+ if (cached && (!dev || (now - cached.timestamp) < cacheTime)) {
1120
1140
  content = cached.content;
1121
1141
  needsFetch = false;
1122
1142
  }
1123
1143
 
1124
1144
  if (needsFetch) {
1125
- // Add timestamp for development cache busting, but keep it minimal
1126
- const timestamp = Math.floor(now / 1000); // Only changes every second
1127
- const url = `${source}${source.includes('?') ? '&' : '?'}t=${timestamp}`;
1128
-
1129
- const response = await fetch(url);
1145
+ // Dev: cache-bust so an edited stylesheet is re-read
1146
+ const url = dev ? `${source}${source.includes('?') ? '&' : '?'}t=${Math.floor(now / 1000)}` : source;
1147
+
1148
+ // Overlapping compiles share one request
1149
+ const inflight = this._cssInflight || (this._cssInflight = new Map());
1150
+ let pending = inflight.get(url);
1151
+ if (!pending) {
1152
+ pending = fetch(url).then(response => (response.ok ? response.text() : null));
1153
+ inflight.set(url, pending);
1154
+ const done = () => inflight.delete(url);
1155
+ pending.then(done, done);
1156
+ }
1157
+ content = await pending;
1130
1158
 
1131
- if (!response.ok) {
1159
+ if (content === null) {
1132
1160
  console.warn('Failed to fetch stylesheet:', url);
1133
1161
  return;
1134
1162
  }
1135
1163
 
1136
- content = await response.text();
1137
-
1138
1164
  // Cache the content with timestamp
1139
1165
  this.cssContentCache.set(cacheKey, {
1140
1166
  content: content,
@@ -2794,6 +2820,9 @@ TailwindCompiler.prototype.compileDelta = function (themeCss) {
2794
2820
  const applied = this._applied;
2795
2821
  const candidates = [];
2796
2822
  for (const cls of this.dynamicClassCache) if (!applied.classes.has(cls)) candidates.push(cls);
2823
+ // A shipped at-rule variant arriving beside our own rules may need re-emitting after a bare partner: full regen decides
2824
+ if (this.staticUtilitiesCoveredClasses && applied.entries.length &&
2825
+ candidates.some(c => this.isAtRuleVariantClass(c) && this.isClassCovered(c))) return false;
2797
2826
  const classes = this.filterStaticallyCoveredClasses(candidates);
2798
2827
  // Tailwind display classes at a breakpoint join the display block, which only a full regen emits
2799
2828
  if (tailwindResponsiveDisplay(classes).length) return false;
@@ -2936,6 +2965,28 @@ TailwindCompiler.prototype.clearStaleUtilityPatches = function () {
2936
2965
  }
2937
2966
  };
2938
2967
 
2968
+ // Boot-time guesses are unlayered and beat every layered variant: drop them once real rules cover the page
2969
+ TailwindCompiler.prototype.dropCriticalStyles = function () {
2970
+ if (!this.criticalStyleElement) return;
2971
+ requestAnimationFrame(() => requestAnimationFrame(() => {
2972
+ if (this.criticalStyleElement && this.criticalStyleElement.parentNode) {
2973
+ this.criticalStyleElement.parentNode.removeChild(this.criticalStyleElement);
2974
+ this.criticalStyleElement = null;
2975
+ }
2976
+ this.ensureUtilityStylesLast();
2977
+ }));
2978
+ };
2979
+
2980
+ // Nothing to generate yet: arm delta on an empty layer so later classes insert, not regenerate
2981
+ TailwindCompiler.prototype.armEmptyDelta = function (themeCss, classes) {
2982
+ if (!this.styleElement) return;
2983
+ // A replayed cache sheet stays until the next full write replaces it
2984
+ if (!this.staticUtilitiesCoveredClasses && this.styleElement.textContent.trim()) return;
2985
+ this._applied = null;
2986
+ this.styleElement.textContent = '@layer utilities {\n}';
2987
+ this.recordAppliedUtilities([], themeCss, classes);
2988
+ };
2989
+
2939
2990
  // Main compilation method
2940
2991
  TailwindCompiler.prototype.compile = async function () {
2941
2992
  if (this.usesStaticPrerenderUtilities) {
@@ -3014,11 +3065,13 @@ TailwindCompiler.prototype.compile = async function () {
3014
3065
  }
3015
3066
  }
3016
3067
 
3017
- const allUtilities = this.orderedUtilitiesCss(this.generateOrderedUtilities(themeCss, staticUsedData));
3068
+ const staticEntries = this.generateOrderedUtilities(themeCss, staticUsedData);
3069
+ const allUtilities = this.orderedUtilitiesCss(staticEntries);
3018
3070
 
3019
3071
  if (allUtilities) {
3020
3072
  const finalCss = `@layer utilities {\n${allUtilities}\n}`;
3021
3073
 
3074
+ this._applied = null; // a move below must not write the previous delta state back
3022
3075
  this.styleElement.textContent = finalCss;
3023
3076
  this.ensureUtilityStylesLast();
3024
3077
  this.scheduleEnsureUtilityStylesLast();
@@ -3036,6 +3089,7 @@ TailwindCompiler.prototype.compile = async function () {
3036
3089
  });
3037
3090
  });
3038
3091
  this.lastClassesHash = staticUsedData.classes.sort().join(',');
3092
+ this.recordAppliedUtilities(staticEntries, themeCss, []);
3039
3093
 
3040
3094
  // Save to cache for next page load
3041
3095
  const themeHash = this.generateThemeHash(themeCss);
@@ -3048,6 +3102,7 @@ TailwindCompiler.prototype.compile = async function () {
3048
3102
  this.savePersistentCache();
3049
3103
  } else {
3050
3104
  this.clearStaleUtilityPatches();
3105
+ this.armEmptyDelta(themeCss, []);
3051
3106
  }
3052
3107
  }
3053
3108
 
@@ -3060,7 +3115,10 @@ TailwindCompiler.prototype.compile = async function () {
3060
3115
  let prefetchedTheme = null;
3061
3116
  if (this.canCompileDelta()) {
3062
3117
  prefetchedTheme = await this.fetchThemeContent();
3063
- if (prefetchedTheme && this.lastThemeKey === this._applied.themeKey && this.compileDelta(this._applied.themeCss)) return;
3118
+ if (prefetchedTheme && this.lastThemeKey === this._applied.themeKey && this.compileDelta(this._applied.themeCss)) {
3119
+ this.dropCriticalStyles();
3120
+ return;
3121
+ }
3064
3122
  }
3065
3123
 
3066
3124
  // For subsequent compilations, check for new dynamic classes
@@ -3105,6 +3163,7 @@ TailwindCompiler.prototype.compile = async function () {
3105
3163
  if (allUtilities) {
3106
3164
  const finalCss = `@layer utilities {\n${allUtilities}\n}`;
3107
3165
 
3166
+ this._applied = null; // a move below must not write the previous delta state back
3108
3167
  this.styleElement.textContent = finalCss;
3109
3168
  this.ensureUtilityStylesLast();
3110
3169
  this.scheduleEnsureUtilityStylesLast();
@@ -3137,6 +3196,8 @@ TailwindCompiler.prototype.compile = async function () {
3137
3196
  this.savePersistentCache();
3138
3197
  } else {
3139
3198
  this.clearStaleUtilityPatches();
3199
+ this.lastClassesHash = dynamicClassesHash;
3200
+ this.armEmptyDelta(themeCss, dynamicClasses);
3140
3201
  }
3141
3202
  } else {
3142
3203
  this._applied = null; // theme text moved: order keys are stale until the next full write
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst",
3
- "version": "0.5.322",
3
+ "version": "0.5.324",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",
@@ -65,6 +65,7 @@
65
65
  "test:e2e:hidden-responsive": "node tests/e2e/utilities-hidden-responsive.e2e.mjs",
66
66
  "test:e2e:breakpoint-range": "node tests/e2e/utilities-breakpoint-range.e2e.mjs",
67
67
  "test:e2e:responsive-order": "node tests/e2e/utilities-responsive-order.e2e.mjs",
68
+ "test:e2e:delta-arming": "node tests/e2e/utilities-delta-arming.e2e.mjs",
68
69
  "test:e2e:tailwind-dark": "node tests/e2e/tailwind-dark-variant.e2e.mjs",
69
70
  "test:e2e:inline-style-variants": "node tests/e2e/utilities-inline-style-variants.e2e.mjs",
70
71
  "test:e2e:presence-tabs": "node tests/e2e/presence-tabs.e2e.mjs",