Skip to content

Commit fe31046

Browse files
Guard media insert with handleInsert and add debug logs
Prevent errors when inserting images into the editor by checking that the handleInsert callback exists before calling it. The editor was failing to insert images because handleInsert could be undefined; adding conditional guards around double-click and insert-button code paths avoids runtime exceptions. Also add temporary console.log statements to help debug what assets and handleInsert look like during interactions.
1 parent ddeaed2 commit fe31046

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

apps/web/public/admin/media-library.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ const createGitHubMediaLibrary = () => {
650650
item.addEventListener("dblclick", () => {
651651
const type = item.dataset.type;
652652
const publicPath = item.dataset.public;
653-
if (type === "file" && publicPath) {
653+
if (type === "file" && publicPath && handleInsert) {
654+
console.log("Double-click inserting:", { path: publicPath, url: publicPath });
654655
handleInsert({ path: publicPath, url: publicPath });
655656
hide();
656657
}
@@ -696,7 +697,11 @@ const createGitHubMediaLibrary = () => {
696697
const publicPath = getPublicPath(path);
697698
return { path: publicPath, url: publicPath };
698699
});
699-
handleInsert(assets.length === 1 ? assets[0] : assets);
700+
console.log("Insert button clicked, assets:", assets);
701+
console.log("handleInsert function:", handleInsert);
702+
if (handleInsert) {
703+
handleInsert(assets.length === 1 ? assets[0] : assets);
704+
}
700705
hide();
701706
}
702707
});

0 commit comments

Comments
 (0)