htmx-router 1.0.13 → 1.0.15

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/event-source.js CHANGED
@@ -17,6 +17,7 @@ const headers = {
17
17
  */
18
18
  export class EventSource {
19
19
  #controller;
20
+ #signal;
20
21
  #timer;
21
22
  #state;
22
23
  response;
@@ -43,6 +44,7 @@ export class EventSource {
43
44
  // immediate prepare for abortion
44
45
  const cancel = () => { this.close(); };
45
46
  request.signal.addEventListener('abort', cancel);
47
+ this.#signal = request.signal;
46
48
  const start = (c) => { this.#controller = c; this.#state = EventSource.OPEN; };
47
49
  const stream = new ReadableStream({ start, cancel }, { highWaterMark: 0 });
48
50
  this.response = new Response(stream, { headers });
@@ -50,6 +52,14 @@ export class EventSource {
50
52
  register.add(this);
51
53
  }
52
54
  sendBytes(chunk, active) {
55
+ if (this.#state === EventSource.CLOSED) {
56
+ const err = new Error(`Warn: Attempted to send data on closed stream for: ${this.url}`);
57
+ console.warn(err);
58
+ }
59
+ if (this.#signal.aborted) {
60
+ this.close();
61
+ return false;
62
+ }
53
63
  if (!this.#controller)
54
64
  return false;
55
65
  try {
@@ -71,15 +81,9 @@ export class EventSource {
71
81
  return this.sendText("\n\n", false);
72
82
  }
73
83
  dispatch(type, data) {
74
- if (this.#state !== EventSource.CLOSED)
75
- console.warn(`Warn: Attempted to dispatch event "${type}" to a closed connection for: ${this.url}`);
76
84
  return this.sendText(`event: ${type}\ndata: ${data}\n\n`, true);
77
85
  }
78
86
  close(unlink = true) {
79
- if (this.#state === EventSource.CLOSED) {
80
- this.#controller = null;
81
- return false;
82
- }
83
87
  if (this.#controller) {
84
88
  try {
85
89
  this.#controller.close();
@@ -94,6 +98,9 @@ export class EventSource {
94
98
  clearInterval(this.#timer);
95
99
  if (unlink)
96
100
  register.delete(this);
101
+ // was already closed
102
+ if (this.#state === EventSource.CLOSED)
103
+ return false;
97
104
  // Mark closed
98
105
  this.#state = EventSource.CLOSED;
99
106
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmx-router",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "A lightweight SSR framework with server+client islands",
5
5
  "keywords": [
6
6
  "htmx",
package/status.d.ts CHANGED
@@ -64,7 +64,11 @@ declare const dictionary: {
64
64
  511: "Network Authentication Required";
65
65
  };
66
66
  type Definitions = typeof dictionary;
67
- export type Status = keyof Definitions;
68
- export type StatusText = Definitions[Status];
69
- export declare function MakeStatus(lookup: Status | StatusText, init?: ResponseInit | Headers): ResponseInit;
67
+ export type StatusCode = keyof Definitions;
68
+ export type StatusText = Definitions[StatusCode];
69
+ export declare function MakeStatus(lookup: StatusCode | StatusText, init?: ResponseInit | Headers): ResponseInit;
70
+ /**
71
+ * @deprecated
72
+ */
73
+ export type Status = StatusCode;
70
74
  export {};