{"record":{"id":"711aa97b8c8e328c","repo":"OrchardCMS/OrchardCore","slug":"standalone-host-is-missing-a-div-id-media-gallery-mount","errorCode":null,"errorMessage":"Standalone host is missing a <div id=\"media-gallery\"> mount point.","messagePattern":"Standalone host is missing a <div id=\"media-gallery\"> mount point\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Media/Assets/media-gallery/src/standalone.ts","lineNumber":64,"sourceCode":"async function loadTranslations(apiBaseUrl: string): Promise<string> {\n  try {\n    // Default fetch caching: the endpoint serves Cache-Control/ETag, so repeat loads hit the\n    // browser cache or revalidate to a 304 instead of re-downloading the label set every boot.\n    const base = apiBaseUrl.endsWith(\"/\") ? apiBaseUrl : `${apiBaseUrl}/`;\n    const response = await fetch(`${base}api/media/localizations`);\n    if (response.ok) {\n      return JSON.stringify(await response.json());\n    }\n  } catch {\n    // Endpoint unreachable — fall back to empty (labels use their built-in fallbacks where present).\n  }\n  return \"{}\";\n}\n\nfunction mount(config: IMediaRuntimeConfig, translations: string, signalrEnabled: boolean): void {\n  const container = document.getElementById(\"media-gallery\");\n  if (!container) {\n    throw new Error('Standalone host is missing a <div id=\"media-gallery\"> mount point.');\n  }\n\n  const app = createApp({\n    name: \"media-standalone\",\n    render: () =>\n      h(AppComponent, {\n        // Inject the resolved two-origin config; App.vue uses it instead of resolving from attributes.\n        runtimeConfig: config,\n        // basePath is required by App.vue but unused for config when runtimeConfig is provided.\n        basePath: config.orchardBaseUrl,\n        translations,\n        uploadFilesUrl: `${config.apiBaseUrl}api/media/Upload`,\n        maxUploadChunkSize: 0,\n        allowMultipleSelection: true,\n        // Real-time updates need the SignalR CORS surface on the Orchard origin; opt in via config.\n        signalrEnabled: signalrEnabled ? \"true\" : \"false\",\n      }),\n  });","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Media/Assets/media-gallery/src/standalone.ts#L46-L82","documentation":"The mount() function of the standalone media gallery requires an element with id 'media-gallery' in the host document to attach the Vue app. If document.getElementById('media-gallery') returns null, it throws this Error before creating the app. This is a DOM contract between the host page and the bundle.","triggerScenarios":"Loading the standalone bundle on a page whose HTML lacks <div id=\"media-gallery\">, or loading the bundle before the DOM element exists (script executed in <head> without defer).","commonSituations":"Custom host pages forgetting the mount div; typos in the id; scripts bundled with wrong injection settings that execute before body renders; using the standalone bundle inside the admin page that uses a different container id.","solutions":["Add <div id=\"media-gallery\"></div> to the host page HTML.","Load the script with defer or at the end of <body> so the DOM exists when it runs.","Fix the id spelling/case to exactly 'media-gallery'.","Optionally create the container in JS if absent instead of throwing."],"exampleFix":"<!-- before -->\n<script src=\"/mediagallery/standalone.js\"></script>\n<!-- after -->\n<div id=\"media-gallery\"></div>\n<script defer src=\"/mediagallery/standalone.js\"></script>","handlingStrategy":"type-guard","validationCode":"// Ensure the mount point exists before loading the bundle\nif (!document.getElementById('media-gallery')) {\n  const div = document.createElement('div'); div.id = 'media-gallery'; document.body.appendChild(div);\n}","typeGuard":"function hasMountPoint(): boolean {\n  return document.getElementById('media-gallery') !== null;\n}","tryCatchPattern":"try { bootstrap(); }\ncatch (err) { if (String(err).includes('mount point')) { /* inject the div and retry, or show an error banner */ } throw err; }","preventionTips":["Include the mount div in every host page template that loads the bundle.","Load the script with defer/async placement after the DOM element.","Use the exact id 'media-gallery' — case-sensitive.","Add a smoke test that boots the standalone page and asserts no bootstrap errors."],"tags":["javascript","dom","vue","bootstrap"],"backgroundTag":"missing-dependency","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}