@lovable.dev/vite-tanstack-config 2.17.0 → 2.17.1

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/dist/hmr-gate.cjs CHANGED
@@ -8,6 +8,24 @@ function requestPathname(req) {
8
8
  const queryStart = url.indexOf("?");
9
9
  return queryStart === -1 ? url : url.slice(0, queryStart);
10
10
  }
11
+ const nonNavigationPrefixes = [
12
+ "/@vite/",
13
+ "/@fs/",
14
+ "/@id/",
15
+ "/@react-refresh",
16
+ "/api/",
17
+ "/go-api/",
18
+ "/assets/",
19
+ "/src/",
20
+ "/_",
21
+ "/favicon"
22
+ ];
23
+ function isHtmlNavigationRequest(req) {
24
+ if (req.method !== "GET") return false;
25
+ const url = req.url;
26
+ if (!url || nonNavigationPrefixes.some((prefix) => url.startsWith(prefix))) return false;
27
+ return (req.headers.accept ?? "").includes("text/html");
28
+ }
11
29
  function gateStatusHeaders(req) {
12
30
  const origin = req.headers.origin;
13
31
  const headers = {
@@ -233,6 +251,7 @@ function hmrGatePlugin(options = {}) {
233
251
  lastUpdateKey = "";
234
252
  }
235
253
  let classicFailOpenTimer = null;
254
+ let errorServedSinceFlush = false;
236
255
  let transportMode = false;
237
256
  let swallowedUpdates = 0;
238
257
  let heldReload = false;
@@ -420,6 +439,12 @@ function hmrGatePlugin(options = {}) {
420
439
  });
421
440
  srv.middlewares.use((req, res, next) => {
422
441
  if (req.method !== "POST" || requestPathname(req) !== "/__hmr_flush") return next();
442
+ const flushOrigin = req.headers.origin;
443
+ if (typeof flushOrigin === "string" && !statusCorsOriginRe.test(flushOrigin)) {
444
+ res.writeHead(403, { "Content-Type": "application/json" });
445
+ res.end(JSON.stringify({ error: "origin not allowed" }));
446
+ return;
447
+ }
423
448
  const priorDrainUntil = drainUntil;
424
449
  const released = releaseParked();
425
450
  drainUntil = Date.now() + drainMs;
@@ -494,6 +519,23 @@ function hmrGatePlugin(options = {}) {
494
519
  });
495
520
  return;
496
521
  }
522
+ srv.middlewares.use((req, res, next) => {
523
+ const originalEnd = res.end.bind(res);
524
+ res.end = ((...args) => {
525
+ if (res.statusCode >= 500 && isHtmlNavigationRequest(req)) {
526
+ errorServedSinceFlush = true;
527
+ if (classicFailOpenTimer === null) {
528
+ classicFailOpenTimer = setTimeout(() => {
529
+ classicFailOpenTimer = null;
530
+ flushPending();
531
+ }, maxHoldMs);
532
+ classicFailOpenTimer.unref?.();
533
+ }
534
+ }
535
+ return originalEnd(...args);
536
+ });
537
+ next();
538
+ });
497
539
  const _emit = srv.watcher.emit.bind(srv.watcher);
498
540
  originalEmit = _emit;
499
541
  const flushPending = () => {
@@ -502,6 +544,9 @@ function hmrGatePlugin(options = {}) {
502
544
  classicFailOpenTimer = null;
503
545
  }
504
546
  if (pending.size > 0) noteUpdateFlush();
547
+ const errorServed = errorServedSinceFlush;
548
+ errorServedSinceFlush = false;
549
+ if (errorServed) srv.moduleGraph.invalidateAll();
505
550
  const entries = Array.from(pending.entries());
506
551
  pending.clear();
507
552
  for (const [f] of entries) srv.moduleGraph.onFileChange(f);
@@ -514,7 +559,11 @@ function hmrGatePlugin(options = {}) {
514
559
  }
515
560
  if (fullReload) srv.ws.send({ type: "full-reload" });
516
561
  }
517
- return entries;
562
+ if (errorServed && (entries.length === 0 || !fullReload)) srv.ws.send({ type: "full-reload" });
563
+ return {
564
+ entries,
565
+ errorRecovery: errorServed
566
+ };
518
567
  };
519
568
  srv.watcher.emit = ((event, ...args) => {
520
569
  if (typeof event === "string" && gatedEvents.has(event) && !isPassthrough(args[0])) {
@@ -523,7 +572,7 @@ function hmrGatePlugin(options = {}) {
523
572
  const hash = fileContentHash(filePath);
524
573
  if (hash !== null && hash === lastFlushedHashes.get(filePath)) {
525
574
  pending.delete(filePath);
526
- if (pending.size === 0 && classicFailOpenTimer !== null) {
575
+ if (pending.size === 0 && !errorServedSinceFlush && classicFailOpenTimer !== null) {
527
576
  clearTimeout(classicFailOpenTimer);
528
577
  classicFailOpenTimer = null;
529
578
  }
@@ -550,11 +599,18 @@ function hmrGatePlugin(options = {}) {
550
599
  });
551
600
  srv.middlewares.use((req, res, next) => {
552
601
  if (req.method !== "POST" || requestPathname(req) !== "/__hmr_flush") return next();
553
- const entries = flushPending();
602
+ const origin = req.headers.origin;
603
+ if (typeof origin === "string" && !statusCorsOriginRe.test(origin)) {
604
+ res.writeHead(403, { "Content-Type": "application/json" });
605
+ res.end(JSON.stringify({ error: "origin not allowed" }));
606
+ return;
607
+ }
608
+ const { entries, errorRecovery } = flushPending();
554
609
  const files = entries.map(([f]) => f);
555
610
  const body = JSON.stringify({
556
611
  flushed: files,
557
612
  count: entries.length,
613
+ errorRecovery,
558
614
  mode: fullReload ? "full-reload" : "granular"
559
615
  });
560
616
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -567,7 +623,8 @@ function hmrGatePlugin(options = {}) {
567
623
  const body = JSON.stringify({
568
624
  enabled: true,
569
625
  pending: serialized,
570
- count: pending.size,
626
+ count: pending.size + (errorServedSinceFlush ? 1 : 0),
627
+ errorRecovery: errorServedSinceFlush,
571
628
  mode: fullReload ? "full-reload" : "granular"
572
629
  });
573
630
  res.writeHead(200, gateStatusHeaders(req));
@@ -609,6 +666,7 @@ function hmrGatePlugin(options = {}) {
609
666
  drainUntil = 0;
610
667
  pending.clear();
611
668
  lastFlushedHashes.clear();
669
+ errorServedSinceFlush = false;
612
670
  server = null;
613
671
  originalEmit = null;
614
672
  }
package/dist/hmr-gate.js CHANGED
@@ -7,6 +7,24 @@ function requestPathname(req) {
7
7
  const queryStart = url.indexOf("?");
8
8
  return queryStart === -1 ? url : url.slice(0, queryStart);
9
9
  }
10
+ const nonNavigationPrefixes = [
11
+ "/@vite/",
12
+ "/@fs/",
13
+ "/@id/",
14
+ "/@react-refresh",
15
+ "/api/",
16
+ "/go-api/",
17
+ "/assets/",
18
+ "/src/",
19
+ "/_",
20
+ "/favicon"
21
+ ];
22
+ function isHtmlNavigationRequest(req) {
23
+ if (req.method !== "GET") return false;
24
+ const url = req.url;
25
+ if (!url || nonNavigationPrefixes.some((prefix) => url.startsWith(prefix))) return false;
26
+ return (req.headers.accept ?? "").includes("text/html");
27
+ }
10
28
  function gateStatusHeaders(req) {
11
29
  const origin = req.headers.origin;
12
30
  const headers = {
@@ -232,6 +250,7 @@ function hmrGatePlugin(options = {}) {
232
250
  lastUpdateKey = "";
233
251
  }
234
252
  let classicFailOpenTimer = null;
253
+ let errorServedSinceFlush = false;
235
254
  let transportMode = false;
236
255
  let swallowedUpdates = 0;
237
256
  let heldReload = false;
@@ -419,6 +438,12 @@ function hmrGatePlugin(options = {}) {
419
438
  });
420
439
  srv.middlewares.use((req, res, next) => {
421
440
  if (req.method !== "POST" || requestPathname(req) !== "/__hmr_flush") return next();
441
+ const flushOrigin = req.headers.origin;
442
+ if (typeof flushOrigin === "string" && !statusCorsOriginRe.test(flushOrigin)) {
443
+ res.writeHead(403, { "Content-Type": "application/json" });
444
+ res.end(JSON.stringify({ error: "origin not allowed" }));
445
+ return;
446
+ }
422
447
  const priorDrainUntil = drainUntil;
423
448
  const released = releaseParked();
424
449
  drainUntil = Date.now() + drainMs;
@@ -493,6 +518,23 @@ function hmrGatePlugin(options = {}) {
493
518
  });
494
519
  return;
495
520
  }
521
+ srv.middlewares.use((req, res, next) => {
522
+ const originalEnd = res.end.bind(res);
523
+ res.end = ((...args) => {
524
+ if (res.statusCode >= 500 && isHtmlNavigationRequest(req)) {
525
+ errorServedSinceFlush = true;
526
+ if (classicFailOpenTimer === null) {
527
+ classicFailOpenTimer = setTimeout(() => {
528
+ classicFailOpenTimer = null;
529
+ flushPending();
530
+ }, maxHoldMs);
531
+ classicFailOpenTimer.unref?.();
532
+ }
533
+ }
534
+ return originalEnd(...args);
535
+ });
536
+ next();
537
+ });
496
538
  const _emit = srv.watcher.emit.bind(srv.watcher);
497
539
  originalEmit = _emit;
498
540
  const flushPending = () => {
@@ -501,6 +543,9 @@ function hmrGatePlugin(options = {}) {
501
543
  classicFailOpenTimer = null;
502
544
  }
503
545
  if (pending.size > 0) noteUpdateFlush();
546
+ const errorServed = errorServedSinceFlush;
547
+ errorServedSinceFlush = false;
548
+ if (errorServed) srv.moduleGraph.invalidateAll();
504
549
  const entries = Array.from(pending.entries());
505
550
  pending.clear();
506
551
  for (const [f] of entries) srv.moduleGraph.onFileChange(f);
@@ -513,7 +558,11 @@ function hmrGatePlugin(options = {}) {
513
558
  }
514
559
  if (fullReload) srv.ws.send({ type: "full-reload" });
515
560
  }
516
- return entries;
561
+ if (errorServed && (entries.length === 0 || !fullReload)) srv.ws.send({ type: "full-reload" });
562
+ return {
563
+ entries,
564
+ errorRecovery: errorServed
565
+ };
517
566
  };
518
567
  srv.watcher.emit = ((event, ...args) => {
519
568
  if (typeof event === "string" && gatedEvents.has(event) && !isPassthrough(args[0])) {
@@ -522,7 +571,7 @@ function hmrGatePlugin(options = {}) {
522
571
  const hash = fileContentHash(filePath);
523
572
  if (hash !== null && hash === lastFlushedHashes.get(filePath)) {
524
573
  pending.delete(filePath);
525
- if (pending.size === 0 && classicFailOpenTimer !== null) {
574
+ if (pending.size === 0 && !errorServedSinceFlush && classicFailOpenTimer !== null) {
526
575
  clearTimeout(classicFailOpenTimer);
527
576
  classicFailOpenTimer = null;
528
577
  }
@@ -549,11 +598,18 @@ function hmrGatePlugin(options = {}) {
549
598
  });
550
599
  srv.middlewares.use((req, res, next) => {
551
600
  if (req.method !== "POST" || requestPathname(req) !== "/__hmr_flush") return next();
552
- const entries = flushPending();
601
+ const origin = req.headers.origin;
602
+ if (typeof origin === "string" && !statusCorsOriginRe.test(origin)) {
603
+ res.writeHead(403, { "Content-Type": "application/json" });
604
+ res.end(JSON.stringify({ error: "origin not allowed" }));
605
+ return;
606
+ }
607
+ const { entries, errorRecovery } = flushPending();
553
608
  const files = entries.map(([f]) => f);
554
609
  const body = JSON.stringify({
555
610
  flushed: files,
556
611
  count: entries.length,
612
+ errorRecovery,
557
613
  mode: fullReload ? "full-reload" : "granular"
558
614
  });
559
615
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -566,7 +622,8 @@ function hmrGatePlugin(options = {}) {
566
622
  const body = JSON.stringify({
567
623
  enabled: true,
568
624
  pending: serialized,
569
- count: pending.size,
625
+ count: pending.size + (errorServedSinceFlush ? 1 : 0),
626
+ errorRecovery: errorServedSinceFlush,
570
627
  mode: fullReload ? "full-reload" : "granular"
571
628
  });
572
629
  res.writeHead(200, gateStatusHeaders(req));
@@ -608,6 +665,7 @@ function hmrGatePlugin(options = {}) {
608
665
  drainUntil = 0;
609
666
  pending.clear();
610
667
  lastFlushedHashes.clear();
668
+ errorServedSinceFlush = false;
611
669
  server = null;
612
670
  originalEmit = null;
613
671
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/vite-tanstack-config",
3
- "version": "2.17.0",
3
+ "version": "2.17.1",
4
4
  "description": "Vite config wrapper for Lovable TanStack Start projects",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",