@hyperspan/framework 1.0.13 → 1.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperspan/framework",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Hyperspan Web Framework",
5
5
  "main": "src/server.ts",
6
6
  "types": "src/server.ts",
@@ -230,15 +230,15 @@ describe('createAction', () => {
230
230
  </form>
231
231
  `;
232
232
  }).post(async (c, { data }) => {
233
- return c.res.html(`
233
+ return html`
234
234
  <p>Hello, ${data?.name}!</p>
235
235
  <p>Your email is ${data?.email}.</p>
236
- `);
236
+ `;
237
237
  }).errorHandler(async (c, { data, error }) => {
238
- return c.res.html(`
238
+ return html`
239
239
  <p>Caught error in custom error handler: ${error?.message}</p>
240
240
  <p>Data: ${JSON.stringify(data)}</p>
241
- `);
241
+ `;
242
242
  });
243
243
 
244
244
  // Test fetch method with invalid data (missing name, invalid email)
@@ -257,7 +257,6 @@ describe('createAction', () => {
257
257
  const responseText = await response.text();
258
258
  // Should render the custom error handler
259
259
  expect(responseText).toContain('Invalid email address');
260
- expect(responseText).toContain('Data: {"email":"not-an-email"}');
261
260
  // Should NOT contain the success message from post handler
262
261
  expect(responseText).not.toContain('Hello,');
263
262
  });
@@ -62,5 +62,24 @@ function renderStreamChunk(chunk: { id: string }) {
62
62
  }
63
63
  }
64
64
 
65
- // @ts-ignore
66
- window._hscc = renderStreamChunk;
65
+ /**
66
+ * Define the _hsc property on the Window object for streaming content
67
+ * Render all current chunks in the _hsc array when the window is loaded
68
+ */
69
+ declare global {
70
+ interface Window {
71
+ _hsc: {
72
+ push: (e: { id: string }) => void;
73
+ forEach: (callback: (e: { id: string }) => void) => void;
74
+ };
75
+ }
76
+ }
77
+
78
+ window._hsc = window._hsc || [];
79
+ window._hsc.push = function (e: { id: string }) {
80
+ Array.prototype.push.call(window._hsc, e);
81
+ renderStreamChunk(e);
82
+ };
83
+ window._hsc.forEach((e: { id: string }) => {
84
+ renderStreamChunk(e);
85
+ });
package/src/layout.ts CHANGED
@@ -16,22 +16,13 @@ export function hyperspanScriptTags() {
16
16
  <script id="hyperspan-streaming-script">
17
17
  // [Hyperspan] Streaming - Load the client streaming JS module only when the first chunk is loaded
18
18
  window._hsc = window._hsc || [];
19
- var hscc = function(e) {
20
- if (window._hscc !== undefined) {
21
- window._hscc(e);
22
- }
23
- };
24
19
  window._hsc.push = function(e) {
25
20
  Array.prototype.push.call(window._hsc, e);
26
21
  if (window._hsc.length === 1) {
27
22
  const script = document.createElement('script');
28
23
  script.src = "${clientStreamingJS.publicPath}";
29
24
  document.body.appendChild(script);
30
- script.onload = function() {
31
- hscc(e);
32
- };
33
25
  }
34
- hscc(e);
35
26
  };
36
27
  </script>
37
28
  `;