hono 4.3.3 → 4.3.4

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.
@@ -446,7 +446,10 @@ const update = async (context, node) => {
446
446
  };
447
447
  const render = (jsxNode, container) => {
448
448
  const node = buildNode({ tag: "", props: { children: jsxNode } });
449
- build([], node, void 0);
449
+ const context = [];
450
+ context[4] = true;
451
+ build(context, node, void 0);
452
+ context[4] = false;
450
453
  const fragment = document.createDocumentFragment();
451
454
  apply(node, fragment);
452
455
  replaceContainer(node, fragment, container);
@@ -320,19 +320,26 @@ const useImperativeHandle = (ref, createHandle, deps) => {
320
320
  };
321
321
  }, deps);
322
322
  };
323
- let useSyncExternalStoreGetServerSnapshotNotified = false;
324
323
  const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
325
- const [state, setState] = useState(getSnapshot());
326
- useEffect(
327
- () => subscribe(() => {
328
- setState(getSnapshot());
329
- }),
330
- []
331
- );
332
- if (getServerSnapshot && !useSyncExternalStoreGetServerSnapshotNotified) {
333
- useSyncExternalStoreGetServerSnapshotNotified = true;
334
- console.info("`getServerSnapshot` is not supported yet.");
324
+ const buildData = import_render.buildDataStack.at(-1);
325
+ if (!buildData) {
326
+ if (!getServerSnapshot) {
327
+ throw new Error("getServerSnapshot is required for server side rendering");
328
+ }
329
+ return getServerSnapshot();
335
330
  }
331
+ const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
332
+ const [state, setState] = useState(
333
+ () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
334
+ );
335
+ useEffect(() => {
336
+ if (serverSnapshotIsUsed) {
337
+ setState(getSnapshot());
338
+ }
339
+ return subscribe(() => {
340
+ setState(getSnapshot());
341
+ });
342
+ }, []);
336
343
  return state;
337
344
  };
338
345
  // Annotate the CommonJS export names for ESM import in node:
@@ -30,7 +30,7 @@ const validator = (target, validationFunc) => {
30
30
  const contentType = c.req.header("Content-Type");
31
31
  switch (target) {
32
32
  case "json":
33
- if (!contentType || !contentType.startsWith("application/json")) {
33
+ if (!contentType || !/^application\/([a-z-]+\+)?json/.test(contentType)) {
34
34
  const message = `Invalid HTTP header: Content-Type=${contentType}`;
35
35
  throw new import_http_exception.HTTPException(400, { message });
36
36
  }
@@ -419,7 +419,10 @@ var update = async (context, node) => {
419
419
  };
420
420
  var render = (jsxNode, container) => {
421
421
  const node = buildNode({ tag: "", props: { children: jsxNode } });
422
- build([], node, void 0);
422
+ const context = [];
423
+ context[4] = true;
424
+ build(context, node, void 0);
425
+ context[4] = false;
423
426
  const fragment = document.createDocumentFragment();
424
427
  apply(node, fragment);
425
428
  replaceContainer(node, fragment, container);
@@ -279,19 +279,26 @@ var useImperativeHandle = (ref, createHandle, deps) => {
279
279
  };
280
280
  }, deps);
281
281
  };
282
- var useSyncExternalStoreGetServerSnapshotNotified = false;
283
282
  var useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
284
- const [state, setState] = useState(getSnapshot());
285
- useEffect(
286
- () => subscribe(() => {
287
- setState(getSnapshot());
288
- }),
289
- []
290
- );
291
- if (getServerSnapshot && !useSyncExternalStoreGetServerSnapshotNotified) {
292
- useSyncExternalStoreGetServerSnapshotNotified = true;
293
- console.info("`getServerSnapshot` is not supported yet.");
283
+ const buildData = buildDataStack.at(-1);
284
+ if (!buildData) {
285
+ if (!getServerSnapshot) {
286
+ throw new Error("getServerSnapshot is required for server side rendering");
287
+ }
288
+ return getServerSnapshot();
294
289
  }
290
+ const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
291
+ const [state, setState] = useState(
292
+ () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
293
+ );
294
+ useEffect(() => {
295
+ if (serverSnapshotIsUsed) {
296
+ setState(getSnapshot());
297
+ }
298
+ return subscribe(() => {
299
+ setState(getSnapshot());
300
+ });
301
+ }, []);
295
302
  return state;
296
303
  };
297
304
  export {
@@ -44,8 +44,9 @@ export type Context = [
44
44
  PendingType,
45
45
  boolean,
46
46
  UpdateHook,
47
+ boolean,
47
48
  boolean
48
- ] | [PendingType, boolean, UpdateHook] | [PendingType, boolean] | [PendingType] | [];
49
+ ] | [PendingType, boolean, UpdateHook, boolean] | [PendingType, boolean, UpdateHook] | [PendingType, boolean] | [PendingType] | [];
49
50
  export declare const buildDataStack: [Context, Node][];
50
51
  export declare const build: (context: Context, node: NodeObject, topLevelErrorHandlerNode: NodeObject | undefined, children?: Child[]) => void;
51
52
  export declare const update: (context: Context, node: NodeObject) => Promise<NodeObject | undefined>;
@@ -8,7 +8,7 @@ var validator = (target, validationFunc) => {
8
8
  const contentType = c.req.header("Content-Type");
9
9
  switch (target) {
10
10
  case "json":
11
- if (!contentType || !contentType.startsWith("application/json")) {
11
+ if (!contentType || !/^application\/([a-z-]+\+)?json/.test(contentType)) {
12
12
  const message = `Invalid HTTP header: Content-Type=${contentType}`;
13
13
  throw new HTTPException(400, { message });
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.3.3",
3
+ "version": "4.3.4",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",