{"record":{"id":"fa9045b98534142b","repo":"dotnet/aspnetcore","slug":"blazor-has-already-started-fa9045","errorCode":null,"errorMessage":"Blazor has already started.","messagePattern":"Blazor has already started\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Boot.WebAssembly.ts","lineNumber":21,"sourceCode":"\n/* eslint-disable array-element-newline */\nimport { Blazor } from './GlobalExports';\nimport { shouldAutoStart } from './BootCommon';\nimport { WebAssemblyStartOptions } from './Platform/WebAssemblyStartOptions';\nimport { setWebAssemblyOptions, startWebAssembly } from './Boot.WebAssembly.Common';\nimport { WebAssemblyComponentDescriptor, discoverComponents, discoverWebAssemblyOptions } from './Services/ComponentDescriptorDiscovery';\nimport { DotNet } from '@microsoft/dotnet-js-interop';\nimport { InitialRootComponentsList } from './Services/InitialRootComponentsList';\nimport { JSEventRegistry } from './Services/JSEventRegistry';\nimport { printErr } from './Platform/Mono/MonoPlatform';\n\ntype BlazorWebAssemblyStartOptions = Partial<WebAssemblyStartOptions> & { webAssembly?: Partial<WebAssemblyStartOptions> };\n\nlet started = false;\n\nasync function boot(options?: BlazorWebAssemblyStartOptions): Promise<void> {\n  if (started) {\n    throw new Error('Blazor has already started.');\n  }\n  started = true;\n\n  // Accept the `webAssembly` property from the blazor.web.js options format\n  const normalizedOptions = options?.webAssembly ?? options ?? {};\n  setWebAssemblyOptions(Promise.resolve(normalizedOptions));\n\n  JSEventRegistry.create(Blazor);\n  const webAssemblyComponents = discoverComponents(document, 'webassembly') as WebAssemblyComponentDescriptor[];\n  const webAssemblyOptions = discoverWebAssemblyOptions(document);\n\n  const components = new InitialRootComponentsList(webAssemblyComponents);\n  await startWebAssembly(components, webAssemblyOptions);\n}\n\nBlazor.start = boot;\nwindow['DotNet'] = DotNet;\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Web.JS/src/Boot.WebAssembly.ts#L3-L39","documentation":"Thrown by the local boot() in Boot.WebAssembly.ts (the blazor.webassembly.js entry) when its module-level 'started' flag is already true. The WebAssembly boot entry is single-shot: it normalizes options, configures them, discovers components, and starts the platform.","triggerScenarios":"Calling Blazor.start() a second time on a WebAssembly app, or autostart firing alongside a manual start.","commonSituations":"Page includes <script src=\"blazor.webassembly.js\" autostart> plus a manual Blazor.start(); HMR reloading the module; an iframe re-running the bundle; PWA service-worker serving a stale copy alongside the new one.","solutions":["Call Blazor.start() exactly once; remove autostart or the manual call so only one path runs.","Guard with a window-level flag before invoking.","Ensure the bundle is loaded once per page load and not re-imported."],"exampleFix":"// before\n<script src=\"blazor.webassembly.js\" autostart></script>\n<script>Blazor.start();</script> <!-- throws -->\n\n// after\n<script src=\"blazor.webassembly.js\"></script>\n<script>Blazor.start();</script>","handlingStrategy":"validation","validationCode":"function startWasmBlazorOnce(opts?: any) {\n  if ((window as any).__blazorWasmStarted) return Promise.resolve();\n  (window as any).__blazorWasmStarted = true;\n  return Blazor.start(opts);\n}","typeGuard":"function wasmBlazorStarted(): boolean {\n  return !!(window as any).__blazorWasmStarted;\n}","tryCatchPattern":"try {\n  await Blazor.start(opts);\n} catch (e) {\n  if (/already started/.test((e as Error).message)) return;\n  throw e;\n}","preventionTips":["Use autostart OR one manual start; not both.","Load blazor.webassembly.js once per page load.","Guard the manual start with a window flag.","Bust the service-worker cache on redeploy to avoid double-bundle scenarios."],"tags":["blazor-webassembly","startup","singleton","autostart"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}