Skip to content

[TOOL-4831] SDK: Fix MediaRenderer not showing poster for 3d models #7387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/heavy-ghosts-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix `poster` not shown in `MediaRenderer` component for 3D models
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
mergeRefs,
} from "./MediaRenderer.js";

const three3dModelLink =
"https://i2.seadn.io/matic/0x2953399124f0cbb46d2cbacd8a89cf0599974963/bd1801876c5cf1302484e225c72959/49bd1801876c5cf1302484e225c72959.glb";
const imageLink =
"https://i.seadn.io/gae/r_b9GB0iYA39ichUlKdFLeG4UliK7YXi9SsM0Xdvm6pNDChYbN5E7Fxop1MdJCbmNvSlbER73YiA9WY1JbhEfkuIktoHfN9UlEZy4A?auto=format&dpr=1&w=1000";

describe("MediaRenderer", () => {
it("should render nothing if no src provided", () => {
render(<MediaRenderer client={TEST_CLIENT} />);
Expand All @@ -27,14 +32,9 @@ describe("MediaRenderer", () => {
}, 1000);
});

it("should render a plain image", () => {
render(
<MediaRenderer
client={TEST_CLIENT}
src="https://i.seadn.io/gae/r_b9GB0iYA39ichUlKdFLeG4UliK7YXi9SsM0Xdvm6pNDChYbN5E7Fxop1MdJCbmNvSlbER73YiA9WY1JbhEfkuIktoHfN9UlEZy4A?auto=format&dpr=1&w=1000"
/>,
);
waitFor(() => {
it("should render a plain image", async () => {
render(<MediaRenderer client={TEST_CLIENT} src={imageLink} />);
await waitFor(() => {
expect(screen.getByRole("img")).toBeInTheDocument();
});
});
Expand Down Expand Up @@ -222,4 +222,17 @@ describe("MediaRenderer", () => {
expect(iframe).toHaveAttribute("src", "https://example.com/video");
});
});

it("should render poster image for 3d models", async () => {
render(
<MediaRenderer
client={TEST_CLIENT}
src={three3dModelLink}
poster={imageLink}
/>,
);
await waitFor(() => {
expect(screen.getByRole("img")).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ export const MediaRenderer = /* @__PURE__ */ (() =>
console.error(
"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.",
);

// show poster
if (possiblePosterSrc.mimeType?.startsWith("image/")) {
return (
<ImageRenderer
style={mergedStyle}
src={possiblePosterSrc.url}
alt={alt}
ref={ref as unknown as React.ForwardedRef<HTMLImageElement>}
className={className}
height={height}
width={width}
/>
);
}
}

// video
Expand Down
Loading