hazo_blog 2.27.1 → 2.27.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.
package/CHANGE_LOG.md CHANGED
@@ -3,13 +3,40 @@
3
3
  All notable changes are documented here. This project follows
4
4
  [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## 2.27.4 — 2026-11-23
7
+
8
+ **Bug fix: Proxy approach from 2.27.3 didn't work — unknown MDX components
9
+ still crash.** MDX's compiled output spreads `props.components` into a local
10
+ `_components` object, then destructures custom component names from it. Object
11
+ spread uses `ownKeys`/`getOwnPropertyDescriptor`, **not** the Proxy `get` trap,
12
+ so the Proxy never fires for keys absent from the target. Unknown components
13
+ stayed `undefined` → `_missingMdxReference` still threw.
14
+
15
+ - **Fix (source transform)**: `neutralizeUnknownComponents()` patches the
16
+ compiled MDX string before `Function` construction:
17
+ 1. Adds `= "div"` defaults to all capitalized destructured names from
18
+ `_components`, so unknown JSX tags render as `<div>` instead of `undefined`.
19
+ 2. Replaces `_missingMdxReference` with a no-op (defense in depth).
20
+ - **Kept**: `MdxErrorBoundary` error boundary (last-resort catch).
21
+ - **Removed**: the Proxy wrapper on `mdxComponents` (inert after the spread; plain
22
+ object is clearer).
23
+
24
+ Bumps 2.27.3 -> 2.27.4 (patch — bug fix, no DDL, no breaking API change).
25
+
26
+ ## 2.27.3 — 2026-11-23
27
+
28
+ **Bug fix (incomplete): blog post pages crash when MDX content contains unknown
29
+ JSX components.** Attempted Proxy on `mdxComponents` + error boundary. The Proxy
30
+ approach was flawed — see 2.27.4.
31
+
6
32
  ## 2.27.1 — 2026-11-23
7
33
 
8
34
  **Bug fix: blog post pages crash with RSC serialization error on production builds.** `BlogContent` (the server component that renders MDX post bodies) used `MDXRemote` from `next-mdx-remote/rsc`, which compiled MDX and returned live React elements that had to pass through RSC serialization. On some production builds — where the bundled MDX compiler and its unified/remark ecosystem are resolved differently — these elements couldn't be serialized, producing `E{"digest":"…"}` in the RSC payload. The initial SSR HTML rendered fine (server saw the elements directly), but the client error boundary fired as soon as hydration read the broken RSC stream, replacing the content with "Something went wrong."
9
35
 
10
36
  - **Fix**: `BlogContent` now compiles MDX to a `function-body` string via `@mdx-js/mdx`'s `compile()` (server side), passes that plain string to a new `BlogContentClient` ("use client") component, which evaluates it at hydration time using the `react/jsx-runtime` and renders with the standard `mdxComponents` map (`BlogImage`, `YouTube`, `Callout`, `CodeBlock`, `InlineCode`). The compiled MDX is a plain string — trivially RSC-serializable.
11
37
  - **New file**: `src/next/blog-content-client.tsx` — minimal "use client" MDX renderer. No dependency on `next-mdx-remote`'s client bundle (avoids a dual-React SSR issue) — evaluates the compiled function-body directly with `Reflect.construct(Function, ...)` + `react/jsx-runtime`.
12
- - **Admin preview for draft posts**: `PostPreview` button now shows for any post with a slug (was gated on `status === "published"`). Preview URL appends `?preview=true` for non-published posts. `createBlogPostPage`'s `Page` and `generateMetadata` functions accept `searchParams` and pass `includeUnpublished: true` when `preview=true`.
38
+ - **Admin preview for draft posts**: `PostPreview` button now shows for any post with a slug (was gated on `status === "published"`). Preview URL appends `?preview=true` for non-published posts. `createBlogPostPage`'s `Page` and `generateMetadata` functions accept `searchParams` and pass `includeUnpublished: true` when `preview=true`. Preview is **auth-gated**: the page calls `config.authorize()` (the host's admin guard) with a synthetic `Request` built from `next/headers` — unauthenticated visitors adding `?preview=true` get the same 404 as without it.
39
+ - **New shim**: `next/headers` added to `src/next-shims.d.ts` for standalone type-checking.
13
40
 
14
41
  Bumps 2.27.0 -> 2.27.1 (patch — bug fix + preview UX improvement, no DDL, no breaking API change).
15
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"blog-content-client.d.ts","sourceRoot":"","sources":["../../src/next/blog-content-client.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAc7C,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,iBAAiB,CAAC,EAAE,cAAc,EAAE,EAAE,sBAAsB,uBA6B3E"}
1
+ {"version":3,"file":"blog-content-client.d.ts","sourceRoot":"","sources":["../../src/next/blog-content-client.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AA8D7C,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;CACxB;AAoBD,wBAAgB,iBAAiB,CAAC,EAAE,cAAc,EAAE,EAAE,sBAAsB,uBA6B3E"}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useMemo } from "react";
3
+ import { Component, useMemo } from "react";
4
4
  import * as runtime from "react/jsx-runtime";
5
5
  import { BlogImage } from "../components/mdx/blog-image.js";
6
6
  import { YouTube } from "../components/mdx/youtube.js";
@@ -13,13 +13,67 @@ const mdxComponents = {
13
13
  pre: CodeBlock,
14
14
  code: InlineCode,
15
15
  };
16
+ /**
17
+ * MDX's compiled output destructures custom components from a spread of
18
+ * `props.components`:
19
+ *
20
+ * const _components = { p: "p", ...props.components }, {ToolEmbed} = _components;
21
+ * if (!ToolEmbed) _missingMdxReference("ToolEmbed", true);
22
+ *
23
+ * Unknown components (not in mdxComponents) end up `undefined` after the
24
+ * spread, then `_missingMdxReference` throws, crashing SSR.
25
+ *
26
+ * A Proxy on the components map does NOT help: spread uses ownKeys/
27
+ * getOwnPropertyDescriptor, not the `get` trap, so the Proxy never fires
28
+ * for keys that don't exist on the target.
29
+ *
30
+ * Fix: patch the compiled source string before constructing the Function:
31
+ * 1. Add `= "div"` defaults to capitalized destructured names from _components
32
+ * so unknown JSX tags render as harmless <div>s instead of undefined.
33
+ * 2. Replace _missingMdxReference with a no-op (defense in depth).
34
+ */
35
+ function neutralizeUnknownComponents(source) {
36
+ let s = source;
37
+ // 1. Add default = "div" to capitalized destructured names from _components.
38
+ // Matches: {Foo, Bar} = _components → {Foo = "div", Bar = "div"} = _components
39
+ // Leaves lowercase names (p, h1, pre, ...) untouched — they're standard HTML.
40
+ s = s.replace(/\{([^}]+)\}\s*=\s*_components/g, (_match, inner) => {
41
+ const patched = inner
42
+ .split(",")
43
+ .map((name) => {
44
+ const n = name.trim();
45
+ return /^[A-Z]/.test(n) && !n.includes("=") ? `${n} = "div"` : n;
46
+ })
47
+ .join(", ");
48
+ return `{${patched}} = _components`;
49
+ });
50
+ // 2. Replace _missingMdxReference with a no-op.
51
+ s = s.replace(/function _missingMdxReference\([^)]*\)\s*\{[^}]*\}/, "function _missingMdxReference() {}");
52
+ return s;
53
+ }
54
+ class MdxErrorBoundary extends Component {
55
+ constructor() {
56
+ super(...arguments);
57
+ this.state = { hasError: false };
58
+ }
59
+ static getDerivedStateFromError() {
60
+ return { hasError: true };
61
+ }
62
+ render() {
63
+ if (this.state.hasError) {
64
+ return (_jsx("p", { className: "text-muted-foreground", children: "Content could not be rendered." }));
65
+ }
66
+ return this.props.children;
67
+ }
68
+ }
16
69
  export function BlogContentClient({ compiledSource }) {
17
70
  const Content = useMemo(() => {
18
71
  const scope = { opts: runtime };
19
72
  const keys = Object.keys(scope);
20
73
  const values = Object.values(scope);
21
74
  try {
22
- const hydrateFn = Reflect.construct(Function, keys.concat(compiledSource));
75
+ const safeSource = neutralizeUnknownComponents(compiledSource);
76
+ const hydrateFn = Reflect.construct(Function, keys.concat(safeSource));
23
77
  return hydrateFn.apply(hydrateFn, values).default;
24
78
  }
25
79
  catch {
@@ -29,5 +83,5 @@ export function BlogContentClient({ compiledSource }) {
29
83
  if (!Content) {
30
84
  return (_jsx("div", { className: "prose prose-zinc max-w-none dark:prose-invert", children: _jsx("p", { className: "text-muted-foreground", children: "Content could not be rendered." }) }));
31
85
  }
32
- return (_jsx("div", { className: "prose prose-zinc max-w-none dark:prose-invert", children: _jsx(Content, { components: mdxComponents }) }));
86
+ return (_jsx("div", { className: "prose prose-zinc max-w-none dark:prose-invert", children: _jsx(MdxErrorBoundary, { children: _jsx(Content, { components: mdxComponents }) }) }));
33
87
  }
@@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,SAAS,EAAE,UAAU;2BAOxD;QACD,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,GAAG;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KACtD;EAwBF"}
@@ -10,6 +10,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
10
  // export const { default, generateMetadata, generateStaticParams,
11
11
  // revalidate, dynamicParams } = createBlogPostPage(blogConfig);
12
12
  import { notFound } from "next/navigation";
13
+ import { headers } from "next/headers";
13
14
  import Link from "next/link";
14
15
  import { createBlogService, resolveConfig } from "../service/index.js";
15
16
  import { AdminFormClient } from "./admin-client.js";
@@ -52,6 +53,18 @@ export function createBlogPostPage(rawConfig) {
52
53
  const slugs = await service.getAllSlugs(false);
53
54
  return slugs.map((s) => ({ slug: s.slug, locale: s.locale ?? defaultLocale }));
54
55
  }
56
+ async function canPreview(sp) {
57
+ if (sp.preview !== "true")
58
+ return false;
59
+ try {
60
+ const h = await headers();
61
+ const req = new Request("http://localhost/preview", { headers: h });
62
+ return !!(await config.authorize(req));
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ }
55
68
  async function generateMetadata({ params, searchParams, }) {
56
69
  const { slug, locale } = params instanceof Promise ? await params : params;
57
70
  const sp = searchParams
@@ -59,7 +72,7 @@ export function createBlogPostPage(rawConfig) {
59
72
  ? await searchParams
60
73
  : searchParams
61
74
  : {};
62
- const isPreview = sp.preview === "true";
75
+ const isPreview = await canPreview(sp);
63
76
  const post = await service.getPost(slug, {
64
77
  ...(locale ? { locale } : {}),
65
78
  ...(isPreview ? { includeUnpublished: true } : {}),
@@ -103,7 +116,7 @@ export function createBlogPostPage(rawConfig) {
103
116
  ? await searchParams
104
117
  : searchParams
105
118
  : {};
106
- const isPreview = sp.preview === "true";
119
+ const isPreview = await canPreview(sp);
107
120
  const post = await service.getPost(slug, {
108
121
  ...(locale ? { locale } : {}),
109
122
  ...(isPreview ? { includeUnpublished: true } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_blog",
3
- "version": "2.27.1",
3
+ "version": "2.27.4",
4
4
  "description": "SEO-optimized blogging package: posts, categories, tags, MDX content, and GA4/GSC/Bing-ready SEO.",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -110,11 +110,11 @@
110
110
  "@types/node": "^22.10.0",
111
111
  "@types/react": "^19.0.0",
112
112
  "@types/react-dom": "^19.0.0",
113
- "hazo_api": "^2.10.0",
114
- "hazo_connect": "^4.3.5",
113
+ "hazo_api": "^2.12.0",
114
+ "hazo_connect": "^4.6.1",
115
115
  "hazo_core": "^2.5.0",
116
116
  "hazo_files": "^3.7.0",
117
- "hazo_ui": "^6.21.0",
117
+ "hazo_ui": "^6.24.0",
118
118
  "jest": "^30.2.0",
119
119
  "jest-environment-node": "^30.2.0",
120
120
  "next": "^16.0.10",