@formepdf/hono 0.9.0 → 0.9.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.
Files changed (2) hide show
  1. package/dist/index.js +25 -1
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -22,6 +22,30 @@ async function getRenderDocument() {
22
22
  }
23
23
  return _renderDocument;
24
24
  }
25
+ // --- Render callback invocation (with React Compiler diagnostic) ---
26
+ // User-supplied render callbacks are called outside React's render cycle.
27
+ // If the callback was compiled by React Compiler, it will inject useMemoCache
28
+ // and throw a cryptic "Invalid hook call" error. Catch and rethrow with guidance.
29
+ function callRenderFn(fn, entryPoint) {
30
+ try {
31
+ return fn();
32
+ }
33
+ catch (err) {
34
+ if (err instanceof Error && /hook|useMemoCache|Invalid hook call/i.test(err.message)) {
35
+ const name = fn.displayName || fn.name || 'render callback';
36
+ throw new Error(`The function passed to ${entryPoint}() ("${name}") appears to be compiled by ` +
37
+ `React Compiler, which injects hooks that cannot run outside of React's render cycle.\n\n` +
38
+ `Fix: Add 'use no memo' at the top of the function to opt it out:\n\n` +
39
+ ` function ${name}() {\n` +
40
+ ` 'use no memo';\n` +
41
+ ` return <Document>...</Document>;\n` +
42
+ ` }\n\n` +
43
+ `Alternatively, wrap it in an inline arrow:\n\n` +
44
+ ` ${entryPoint}(() => <${name} />)`);
45
+ }
46
+ throw err;
47
+ }
48
+ }
25
49
  // --- Standalone pdfResponse (no middleware needed) ---
26
50
  export async function pdfResponse(templateOrRenderFn, dataOrOptions, maybeOptions) {
27
51
  let element;
@@ -40,7 +64,7 @@ export async function pdfResponse(templateOrRenderFn, dataOrOptions, maybeOption
40
64
  else {
41
65
  const renderFn = templateOrRenderFn;
42
66
  options = dataOrOptions || {};
43
- element = renderFn();
67
+ element = callRenderFn(renderFn, 'pdfResponse');
44
68
  options.filename = options.filename || 'document.pdf';
45
69
  }
46
70
  const renderDocument = await getRenderDocument();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formepdf/hono",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "PDF middleware and responses for Hono — works on Workers, Deno, Bun, Node",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,9 +13,9 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@formepdf/react": "0.9.0",
17
- "@formepdf/core": "0.9.0",
18
- "@formepdf/templates": "0.9.0"
16
+ "@formepdf/react": "0.9.1",
17
+ "@formepdf/core": "0.9.1",
18
+ "@formepdf/templates": "0.9.1"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "hono": ">=4.0.0"