@ai-matrx/media 0.4.0 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @ai-matrx/media
2
2
 
3
+ ## 0.4.1 — 2026-08-30
4
+
5
+ **Fixes a crash class in 0.4.0's `/viewers` dispatch. Every 0.4.0 consumer must
6
+ move to 0.4.1** — the bug is invisible until a real engine is registered, which
7
+ is what every host does.
8
+
9
+ ### Consumer action (C28)
10
+
11
+ - Upgrade. No API change; nothing to rewrite.
12
+
13
+ ### The defect
14
+
15
+ `MediaFileViewer` CALLED the registered viewer as a plain function
16
+ (`viewer(props)`), and `CodeViewer` did the same with the registered
17
+ highlighter. Every real engine adapter uses hooks — it resolves a display URL,
18
+ reads the host theme, joins a playback session — so those hooks landed in the
19
+ DISPATCHER's hook list instead of the body's own. A single body renders fine;
20
+ the moment the file kind changes (image → code, code → PDF) the hook count
21
+ changes and React throws "Rendered fewer hooks than expected", taking the whole
22
+ preview surface down. Both now mount through `createElement`, so each body gets
23
+ its own component instance and its own hook list.
24
+
25
+ Found while adopting 0.4.0 in matrx-frontend, before the host swap shipped.
26
+ Guarded by a new test that mounts hook-using bodies and then switches kinds
27
+ three times — the exact sequence that used to crash.
28
+
3
29
  ## 0.4.0 — 2026-08-30
4
30
 
5
31
  **The package renders FILES now, not just media elements** — and it knows what
package/dist/viewers.cjs CHANGED
@@ -46,6 +46,9 @@ __export(viewers_exports, {
46
46
  });
47
47
  module.exports = __toCommonJS(viewers_exports);
48
48
 
49
+ // src/viewers/media-file-viewer.tsx
50
+ var import_react12 = require("react");
51
+
49
52
  // src/viewers/registry.ts
50
53
  var VIEWER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.media.viewer-registry");
51
54
  var HIGHLIGHTER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.media.code-highlighter");
@@ -794,7 +797,15 @@ function CodeViewer({
794
797
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerCopyButton, { text })
795
798
  ] })
796
799
  ] }),
797
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "min-h-0 flex-1 overflow-auto", children: highlighter ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: highlighter({ code: text, language }) }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("pre", { className: "m-0 flex p-3 font-mono text-xs leading-5", children: [
800
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "min-h-0 flex-1 overflow-auto", children: highlighter ? (
801
+ // Mounted as an element, never called — a real highlighter reads the
802
+ // host's theme with a hook, and calling it would put that hook in
803
+ // THIS component's list (see the note in media-file-viewer.tsx).
804
+ (0, import_react7.createElement)(
805
+ highlighter,
806
+ { code: text, language }
807
+ )
808
+ ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("pre", { className: "m-0 flex p-3 font-mono text-xs leading-5", children: [
798
809
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
799
810
  "code",
800
811
  {
@@ -1738,10 +1749,8 @@ function MediaFileViewer({
1738
1749
  ...props
1739
1750
  }) {
1740
1751
  const kind = previewKind ?? getPreviewKind(props.fileName, props.mimeType ?? null);
1741
- const registered = getMediaViewer(kind);
1742
- if (registered) return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: registered(props) });
1743
- const builtIn = BUILT_IN[kind];
1744
- if (builtIn) return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: builtIn(props) });
1752
+ const viewer = getMediaViewer(kind) ?? BUILT_IN[kind];
1753
+ if (viewer) return (0, import_react12.createElement)(viewer, props);
1745
1754
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MediaViewerUnavailable, { ...props, kind });
1746
1755
  }
1747
1756
  //# sourceMappingURL=viewers.cjs.map