{"record":{"id":"e2525e2b0c61cb9a","repo":"dotnet/aspnetcore","slug":"blazor-has-already-started","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.Server.ts","lineNumber":19,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nimport { Blazor } from './GlobalExports';\nimport { shouldAutoStart } from './BootCommon';\nimport { CircuitStartOptions, resolveOptions } from './Platform/Circuits/CircuitStartOptions';\nimport { setCircuitOptions, startServer } from './Boot.Server.Common';\nimport { ServerComponentDescriptor, discoverComponents } from './Services/ComponentDescriptorDiscovery';\nimport { DotNet } from '@microsoft/dotnet-js-interop';\nimport { InitialRootComponentsList } from './Services/InitialRootComponentsList';\nimport { JSEventRegistry } from './Services/JSEventRegistry';\n\ntype BlazorServerStartOptions = Partial<CircuitStartOptions> & { circuit?: Partial<CircuitStartOptions> };\n\nlet started = false;\n\nfunction boot(userOptions?: BlazorServerStartOptions): Promise<void> {\n  if (started) {\n    throw new Error('Blazor has already started.');\n  }\n  started = true;\n\n  // Accept the `circuit` property from the blazor.web.js options format\n  const normalizedOptions = userOptions?.circuit ?? userOptions;\n  const configuredOptions = resolveOptions(normalizedOptions);\n  setCircuitOptions(Promise.resolve(configuredOptions || {}));\n\n  const serverComponents = discoverComponents(document, 'server') as ServerComponentDescriptor[];\n  const components = new InitialRootComponentsList(serverComponents);\n  return startServer(components, JSEventRegistry.create(Blazor));\n}\n\nBlazor.start = boot;\nwindow['DotNet'] = DotNet;\n\nif (shouldAutoStart()) {\n  boot();","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Web.JS/src/Boot.Server.ts#L1-L37","documentation":"Thrown by the local boot() in Boot.Server.ts (the blazor.server.js entry) when its module-level 'started' flag is already true. The Server boot entry is single-shot: it configures circuit options, discovers server components, and starts the server in one pass; a second invocation is treated as a programmer error.","triggerScenarios":"Calling Blazor.start() a second time after the Server bundle has already booted, or auto-start firing alongside a manual start().","commonSituations":"Page includes <script src=\"blazor.server.js\" autostart> and a script also calls Blazor.start(); SPA framework re-importing the bundle; HMR reloading the module without resetting the flag.","solutions":["Call Blazor.start() exactly once; remove the manual call if autostart is enabled, or disable autostart if you start manually.","Guard with a window-level flag (e.g. window.__blazorStarted) before invoking start.","Ensure the bundle is loaded once and not re-evaluated (avoid dynamic import() loops that re-import blazor.server.js)."],"exampleFix":"// before\n<script src=\"blazor.server.js\" autostart></script>\n<script>Blazor.start({ ... });</script> <!-- throws -->\n\n// after: pick one\n<script src=\"blazor.server.js\"></script>\n<script>Blazor.start({ ... });</script>","handlingStrategy":"validation","validationCode":"function startServerBlazorOnce(opts?: any) {\n  if ((window as any).__blazorServerStarted) return Promise.resolve();\n  (window as any).__blazorServerStarted = true;\n  return Blazor.start(opts);\n}","typeGuard":"function isServerBlazorStarted(): boolean {\n  return !!(window as any).__blazorServerStarted;\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":["Choose autostart OR a single manual Blazor.start(); never both.","Track a window-level started flag in your boot script.","Avoid dynamically re-importing blazor.server.js.","Reset the flag only on full page navigation."],"tags":["blazor-server","startup","singleton","autostart"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}