hazo_blog 2.27.1 → 2.27.3

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,23 @@
3
3
  All notable changes are documented here. This project follows
4
4
  [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## 2.27.3 — 2026-11-23
7
+
8
+ **Bug fix: blog post pages crash when MDX content contains unknown JSX components.** `BlogContentClient`'s MDX renderer threw `"Expected component 'X' to be defined"` at render time when the compiled MDX contained JSX tags (e.g. `<Tip>`, `<Note>`) not registered in the `mdxComponents` map. Because the error fired inside React's render cycle (outside the existing `useMemo` try/catch that only guarded Function construction), it escaped into the RSC stream as `E{"digest":"…"}`, triggering the host's error boundary — "Something went wrong" on the entire page.
9
+
10
+ - **Fix (Proxy)**: `mdxComponents` is now a `Proxy` that returns the lowercase string tag name for any unknown component lookup, so `<Tip>` renders as `<tip>` (a valid HTML element) instead of crashing.
11
+ - **Fix (error boundary)**: `<Content>` render is wrapped in a new `MdxErrorBoundary` class component that catches any remaining render errors and shows "Content could not be rendered." instead of crashing the page.
12
+
13
+ Bumps 2.27.2 -> 2.27.3 (patch — bug fix, no DDL, no breaking API change).
14
+
6
15
  ## 2.27.1 — 2026-11-23
7
16
 
8
17
  **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
18
 
10
19
  - **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
20
  - **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`.
21
+ - **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.
22
+ - **New shim**: `next/headers` added to `src/next-shims.d.ts` for standalone type-checking.
13
23
 
14
24
  Bumps 2.27.0 -> 2.27.1 (patch — bug fix + preview UX improvement, no DDL, no breaking API change).
15
25
 
@@ -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;AAwB7C,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,MAAM,CAAC;CACxB;AAoBD,wBAAgB,iBAAiB,CAAC,EAAE,cAAc,EAAE,EAAE,sBAAsB,uBA+B3E"}
@@ -1,18 +1,44 @@
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";
7
7
  import { Callout } from "../components/mdx/callout.js";
8
8
  import { CodeBlock, InlineCode } from "../components/mdx/code-block.js";
9
- const mdxComponents = {
9
+ const knownComponents = {
10
10
  BlogImage,
11
11
  YouTube,
12
12
  Callout,
13
13
  pre: CodeBlock,
14
14
  code: InlineCode,
15
15
  };
16
+ // Proxy returns a passthrough <div> for any JSX tag not in knownComponents,
17
+ // preventing the "Expected component `X` to be defined" MDX runtime error.
18
+ const mdxComponents = new Proxy(knownComponents, {
19
+ get(target, prop) {
20
+ if (typeof prop === "string" && prop in target)
21
+ return target[prop];
22
+ if (typeof prop === "string")
23
+ return prop;
24
+ return undefined;
25
+ },
26
+ });
27
+ class MdxErrorBoundary extends Component {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.state = { hasError: false };
31
+ }
32
+ static getDerivedStateFromError() {
33
+ return { hasError: true };
34
+ }
35
+ render() {
36
+ if (this.state.hasError) {
37
+ return (_jsx("p", { className: "text-muted-foreground", children: "Content could not be rendered." }));
38
+ }
39
+ return this.props.children;
40
+ }
41
+ }
16
42
  export function BlogContentClient({ compiledSource }) {
17
43
  const Content = useMemo(() => {
18
44
  const scope = { opts: runtime };
@@ -29,5 +55,5 @@ export function BlogContentClient({ compiledSource }) {
29
55
  if (!Content) {
30
56
  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
57
  }
32
- return (_jsx("div", { className: "prose prose-zinc max-w-none dark:prose-invert", children: _jsx(Content, { components: mdxComponents }) }));
58
+ return (_jsx("div", { className: "prose prose-zinc max-w-none dark:prose-invert", children: _jsx(MdxErrorBoundary, { children: _jsx(Content, { components: mdxComponents }) }) }));
33
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/next/pages.tsx"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,UAAU,EAAyB,MAAM,mBAAmB,CAAC;AAI3E,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAexC,qCAAqC;AACrC,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,UAAU;yCAqEnD;QACD,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACvF,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACzE;kDArDE;QACD,MAAM,EAAE,OAAO,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACvF,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACzE,KAAG,OAAO,CAAC,QAAQ,CAAC;;;;;;;EA6FtB;AAED,+BAA+B;AAC/B,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,UAAU;iCAepD;QACD,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC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S,EAAE,UAAU;;EA0E5D;AAED,mEAAmE;AACnE,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,UAAU;;EAqB3D;AAED,uEAAuE;AACvE,wBAAgB,uBAAuB,CAAC,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.3",
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",