hazo_blog 2.27.3 → 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,14 +3,31 @@
|
|
|
3
3
|
All notable changes are documented here. This project follows
|
|
4
4
|
[Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
-
## 2.27.
|
|
7
|
-
|
|
8
|
-
**Bug fix:
|
|
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).
|
|
9
25
|
|
|
10
|
-
|
|
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.
|
|
26
|
+
## 2.27.3 — 2026-11-23
|
|
12
27
|
|
|
13
|
-
|
|
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.
|
|
14
31
|
|
|
15
32
|
## 2.27.1 — 2026-11-23
|
|
16
33
|
|
|
@@ -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;
|
|
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"}
|
|
@@ -6,24 +6,51 @@ 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
|
|
9
|
+
const mdxComponents = {
|
|
10
10
|
BlogImage,
|
|
11
11
|
YouTube,
|
|
12
12
|
Callout,
|
|
13
13
|
pre: CodeBlock,
|
|
14
14
|
code: InlineCode,
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
}
|
|
27
54
|
class MdxErrorBoundary extends Component {
|
|
28
55
|
constructor() {
|
|
29
56
|
super(...arguments);
|
|
@@ -45,7 +72,8 @@ export function BlogContentClient({ compiledSource }) {
|
|
|
45
72
|
const keys = Object.keys(scope);
|
|
46
73
|
const values = Object.values(scope);
|
|
47
74
|
try {
|
|
48
|
-
const
|
|
75
|
+
const safeSource = neutralizeUnknownComponents(compiledSource);
|
|
76
|
+
const hydrateFn = Reflect.construct(Function, keys.concat(safeSource));
|
|
49
77
|
return hydrateFn.apply(hydrateFn, values).default;
|
|
50
78
|
}
|
|
51
79
|
catch {
|
package/package.json
CHANGED