skillhub/web/src/bootstrap.ts
Cheney e869a4d365 fix(web): restore compatibility with Chromium 83 (Debian 10)
Publish page dropdowns (namespace/visibility) failed to open on older
Chromium because Vite 6 defaults build target to chrome87 and some
bundled deps call runtime APIs absent in Chrome 83 (replaceAll, .at,
hasOwn). Lower esbuild/vite target to chrome83, add browserslist, drop
??= in bootstrap, and inject runtime polyfills before main loads.
2026-05-09 13:55:50 +08:00

42 lines
1.2 KiB
TypeScript

/**
* Bootstraps runtime configuration before the React bundle mounts.
*
* Deployments inject `/runtime-config.js` at startup, and this file guarantees the app sees either
* that config or a safe fallback object before importing the main entry.
*/
import './legacy-polyfills'
async function loadRuntimeConfig() {
await new Promise<void>((resolve, reject) => {
const script = document.createElement('script')
script.src = new URL('../runtime-config.js', import.meta.url).toString()
script.async = false
script.onload = () => resolve()
script.onerror = () => reject(new Error('Failed to load runtime config'))
document.head.appendChild(script)
})
}
function ensureRuntimeConfigFallback() {
if (!window.__SKILLHUB_RUNTIME_CONFIG__) {
window.__SKILLHUB_RUNTIME_CONFIG__ = {
apiBaseUrl: '',
appBaseUrl: '',
authDirectEnabled: 'false',
authDirectProvider: '',
authSessionBootstrapEnabled: 'false',
authSessionBootstrapProvider: '',
authSessionBootstrapAuto: 'false',
}
}
}
void (async () => {
try {
await loadRuntimeConfig()
} catch (error) {
console.error(error)
ensureRuntimeConfigFallback()
}
await import('./main')
})()