jskelet 0.1.6 → 0.1.7

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.
@@ -149,10 +149,13 @@ uğramadığı için kanal `listen` sonrası doğrudan sunucuya bağlanır
149
149
  sunucu→istemci metin çerçevesi yazmak ve istemcinin ping/close çerçevelerini
150
150
  yanıtlamak gerekiyor.
151
151
 
152
- Soket hiç açılamazsa (araya giren bir proxy WebSocket'i geçirmiyor olabilir)
153
- overlay eski yola düşer: `/events` SSE akışı + `/stats` yoklaması. Soket kurulup
154
- sonra düşerse — yani sunucu yeniden başlıyorsa — yarım saniyede bir yeniden
155
- bağlanır ve gösterge bu sırada "bağlantı yok" der.
152
+ Soket kurulup sonra düşerse — yani sunucu yeniden başlıyorsa — yarım saniyede
153
+ bir yeniden bağlanır ve gösterge bu sırada "bağlantı yok" der. Hiç açılamazsa
154
+ aralığı kademeli açarak dört kez denenir; sayfa, sunucunun yeniden başlama
155
+ penceresinde açılmış olabilir ve tek bir başarısızlık kanalın çalışmadığı
156
+ anlamına gelmez. Denemeler de tutmazsa (araya giren bir proxy WebSocket'i
157
+ geçirmiyor olabilir) overlay eski yola düşer: `/events` SSE akışı + `/stats`
158
+ yoklaması.
156
159
 
157
160
  ## Devtools overlay
158
161
 
@@ -152,11 +152,13 @@ the middleware chain, so the channel is attached straight to the server after
152
152
  `ws`: all it needs is to write server-to-client text frames and to answer the
153
153
  client's ping/close frames.
154
154
 
155
- If the socket cannot be opened at all (a proxy in between may not pass WebSocket
156
- through), the overlay falls back to the old path: the `/events` SSE stream plus
157
- polling `/stats`. If the socket opens and later drops — that is, the server is
158
- restarting — it reconnects every half second and the indicator reads
159
- "server restarting…" in the meantime.
155
+ If the socket opens and later drops — that is, the server is restarting — it
156
+ reconnects every half second and the indicator reads "server restarting…" in the
157
+ meantime. If it never opens, it is retried four times with a widening gap: the
158
+ page may have been loaded during the server's restart window, and a single
159
+ failure does not mean the channel is unavailable. If those attempts fail too (a
160
+ proxy in between may not pass WebSocket through), the overlay falls back to the
161
+ old path: the `/events` SSE stream plus polling `/stats`.
160
162
 
161
163
  ## Devtools overlay
162
164
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jskelet",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A framework that feels like no framework: Express 5 + EJS server rendering, vanilla JS islands, Tailwind v4 and an in-process HTML TTL cache.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -397,6 +397,15 @@ let restarts = 0;
397
397
  * yenileme yapılır; overlay durumu sekme belleğinde durduğu için panel açık
398
398
  * kalmaya devam eder.
399
399
  */
400
+ /**
401
+ * Hiç açılmadan üst üste bu kadar denemeden sonra kanal yerine yedek yola
402
+ * geçilir. Tek bir başarısızlık yetmiyor: sayfa, sunucunun yeniden başlama
403
+ * penceresinde açılmış olabilir ve o an soket kurulamaz.
404
+ */
405
+ const SOCKET_ATTEMPTS = 4;
406
+
407
+ let socketFailures = 0;
408
+
400
409
  function connectSocket() {
401
410
  let socket;
402
411
  try {
@@ -408,12 +417,11 @@ function connectSocket() {
408
417
  return;
409
418
  }
410
419
 
411
- // Soket hiç açılamazsa (proxy WebSocket'i geçirmiyor olabilir) eski
412
- // SSE + yoklama yoluna düşülür; dev akışı bir ara katman yüzünden körelmesin.
413
420
  let opened = false;
414
421
 
415
422
  socket.addEventListener("open", () => {
416
423
  opened = true;
424
+ socketFailures = 0;
417
425
  });
418
426
 
419
427
  socket.addEventListener("message", (event) => {
@@ -421,18 +429,31 @@ function connectSocket() {
421
429
  });
422
430
 
423
431
  socket.addEventListener("close", () => {
424
- if (!opened) {
425
- startFallback();
426
- return;
427
- }
428
-
429
- // Sunucu yeniden başlıyor: gösterge "bağlantı yok"a döner ve kısa aralıkla
432
+ // Sunucu yeniden başlıyor olabilir: gösterge "bağlantı yok"a döner ve
430
433
  // yeniden denenir. Açılışta gelen `hello` yeniden başlatmayı bildirir.
431
434
  if (!offline) {
432
435
  offline = true;
433
436
  render();
434
437
  }
435
- setTimeout(connectSocket, 500);
438
+
439
+ if (opened) {
440
+ socketFailures = 0;
441
+ setTimeout(connectSocket, 500);
442
+ return;
443
+ }
444
+
445
+ socketFailures += 1;
446
+
447
+ // Kanal hiç kurulamıyorsa araya giren bir katman WebSocket'i geçirmiyor
448
+ // demektir; dev akışı bunun yüzünden körelmesin diye eski yola düşülür.
449
+ if (socketFailures >= SOCKET_ATTEMPTS) {
450
+ startFallback();
451
+ return;
452
+ }
453
+
454
+ // Yeniden başlatma birkaç saniye sürebiliyor; aralık kademeli açılır ki
455
+ // tarayıcı konsolu başarısız bağlantı satırlarıyla dolmasın.
456
+ setTimeout(connectSocket, socketFailures * 700);
436
457
  });
437
458
  }
438
459