@ape-egg/vibe 1.8.0 → 1.9.0

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.
@@ -134,6 +134,14 @@ const detectHyperspeed = async () => {
134
134
  if (hyperspeedDetectionAttempted) return hyperspeedData;
135
135
  hyperspeedDetectionAttempted = true;
136
136
 
137
+ // Runtime-mode pages still have [vibe-fouc] / .vibe-fouc on their vibe root
138
+ // at this point — the compiler strips it at build time, and the runtime only
139
+ // clears it after hydration (PHASE_READY). Vibe can latch to any element, so
140
+ // search the whole document. If any fouc marker is still here, we're in
141
+ // runtime mode and no hyperspeed manifest will exist — skip the network
142
+ // fetches and avoid the 404 devtools noise.
143
+ const skipNetwork = !!document.querySelector("[vibe-fouc], .vibe-fouc");
144
+
137
145
  try {
138
146
  let pagePath = window.location.pathname;
139
147
 
@@ -185,21 +193,38 @@ const detectHyperspeed = async () => {
185
193
  );
186
194
  }
187
195
 
188
- // Try each possible path
189
- for (const manifestPath of possiblePaths) {
190
- try {
191
- const module = await import(manifestPath);
192
- hyperspeedData = {
193
- manifest: module.default,
194
- path: manifestPath,
195
- };
196
- return hyperspeedData;
197
- } catch (e) {
198
- // Try next path
199
- continue;
196
+ if (!skipNetwork) {
197
+ // Fully-runtime dynamic import. Hidden behind `new Function` so any
198
+ // bundler's static-analysis can't read into it — there's nothing we
199
+ // could or should tell it about these manifest paths, which are decided
200
+ // at runtime by searching a list.
201
+ const dynamicImport = new Function('p', 'return import(p)');
202
+ // Try each possible path
203
+ for (const manifestPath of possiblePaths) {
204
+ try {
205
+ const module = await dynamicImport(manifestPath);
206
+ hyperspeedData = {
207
+ manifest: module.default,
208
+ path: manifestPath,
209
+ };
210
+ return hyperspeedData;
211
+ } catch (e) {
212
+ // Try next path
213
+ continue;
214
+ }
200
215
  }
201
216
  }
202
217
 
218
+ // When skipping network, yield a macrotask so module-graph timing matches
219
+ // the old behavior where `await import()` on a missing manifest resolved
220
+ // via a network 404 (macrotask), not a microtask. Without this yield, the
221
+ // vibe module-graph resolves too fast and the post-boot microtask fires
222
+ // before sibling `<script type="module">` tags (e.g. component scripts)
223
+ // have had a chance to register their state.
224
+ if (skipNetwork) {
225
+ await new Promise((resolve) => setTimeout(resolve, 0));
226
+ }
227
+
203
228
  // No manifest found
204
229
  return null;
205
230
  } catch {
@@ -468,7 +493,7 @@ export const restoreMarkersFromManifest = (
468
493
  if (text.startsWith("if")) {
469
494
  if (!startComment) {
470
495
  const expression = childTree.meta?.expression;
471
- const expectedText = expression ? 'if ' + expression : null;
496
+ const expectedText = expression ? "if " + expression : null;
472
497
  if (expectedText && text === expectedText) {
473
498
  startComment = comment;
474
499
  conditionalDepth = 1;