Skip to content

Commit 70e024f

Browse files
committed
[TOOL-4831] SDK: Fix MediaRenderer not showing poster for 3d models (#7387)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on fixing the display of the `poster` in the `MediaRenderer` component for 3D models and adding tests to ensure expected behavior. ### Detailed summary - Updated the `MediaRenderer` component to show a `poster` image for 3D models. - Added a new test case to verify rendering of the `poster` image when a 3D model is provided. - Replaced hardcoded image URL with a constant `imageLink` for clarity in tests. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Fixed an issue where the poster image was not displayed when rendering 3D models in the MediaRenderer component. Now, if a poster image is available, it will be shown as a fallback for unsupported 3D models. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 4c29886 commit 70e024f

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

.changeset/heavy-ghosts-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix `poster` not shown in `MediaRenderer` component for 3D models

packages/thirdweb/src/react/web/ui/MediaRenderer/MediaRenderer.test.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import {
1414
mergeRefs,
1515
} from "./MediaRenderer.js";
1616

17+
const three3dModelLink =
18+
"https://i2.seadn.io/matic/0x2953399124f0cbb46d2cbacd8a89cf0599974963/bd1801876c5cf1302484e225c72959/49bd1801876c5cf1302484e225c72959.glb";
19+
const imageLink =
20+
"https://i.seadn.io/gae/r_b9GB0iYA39ichUlKdFLeG4UliK7YXi9SsM0Xdvm6pNDChYbN5E7Fxop1MdJCbmNvSlbER73YiA9WY1JbhEfkuIktoHfN9UlEZy4A?auto=format&dpr=1&w=1000";
21+
1722
describe("MediaRenderer", () => {
1823
it("should render nothing if no src provided", () => {
1924
render(<MediaRenderer client={TEST_CLIENT} />);
@@ -27,14 +32,9 @@ describe("MediaRenderer", () => {
2732
}, 1000);
2833
});
2934

30-
it("should render a plain image", () => {
31-
render(
32-
<MediaRenderer
33-
client={TEST_CLIENT}
34-
src="https://i.seadn.io/gae/r_b9GB0iYA39ichUlKdFLeG4UliK7YXi9SsM0Xdvm6pNDChYbN5E7Fxop1MdJCbmNvSlbER73YiA9WY1JbhEfkuIktoHfN9UlEZy4A?auto=format&dpr=1&w=1000"
35-
/>,
36-
);
37-
waitFor(() => {
35+
it("should render a plain image", async () => {
36+
render(<MediaRenderer client={TEST_CLIENT} src={imageLink} />);
37+
await waitFor(() => {
3838
expect(screen.getByRole("img")).toBeInTheDocument();
3939
});
4040
});
@@ -222,4 +222,17 @@ describe("MediaRenderer", () => {
222222
expect(iframe).toHaveAttribute("src", "https://example.com/video");
223223
});
224224
});
225+
226+
it("should render poster image for 3d models", async () => {
227+
render(
228+
<MediaRenderer
229+
client={TEST_CLIENT}
230+
src={three3dModelLink}
231+
poster={imageLink}
232+
/>,
233+
);
234+
await waitFor(() => {
235+
expect(screen.getByRole("img")).toBeInTheDocument();
236+
});
237+
});
225238
});

packages/thirdweb/src/react/web/ui/MediaRenderer/MediaRenderer.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ export const MediaRenderer = /* @__PURE__ */ (() =>
111111
console.error(
112112
"Encountered an unsupported media type. 3D model support was removed in v5.92.0. To add a 3D model to your app, use @google/model-viewer and use the ModelViewer component.",
113113
);
114+
115+
// show poster
116+
if (possiblePosterSrc.mimeType?.startsWith("image/")) {
117+
return (
118+
<ImageRenderer
119+
style={mergedStyle}
120+
src={possiblePosterSrc.url}
121+
alt={alt}
122+
ref={ref as unknown as React.ForwardedRef<HTMLImageElement>}
123+
className={className}
124+
height={height}
125+
width={width}
126+
/>
127+
);
128+
}
114129
}
115130

116131
// video

0 commit comments

Comments
 (0)