Skip to content

fix(appinsights): explicitly import JS module to fix undefined blazorApplicationInsights - #2

Merged
kolatts merged 1 commit into
mainfrom
kolatts/fix-appinsights-explicit-module-load
Mar 21, 2026
Merged

fix(appinsights): explicitly import JS module to fix undefined blazorApplicationInsights#2
kolatts merged 1 commit into
mainfrom
kolatts/fix-appinsights-explicit-module-load

Conversation

@kolatts

@kolatts kolatts commented Mar 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • The previous fix (renaming .lib.module.js) was insufficient — the Web UI deployed successfully but the error persisted
  • Root cause: Blazor WASM's .lib.module.js auto-loading mechanism is not reliably triggered for NuGet-distributed RCLs, so window.blazorApplicationInsights was never defined at runtime
  • Fix: ApplicationInsightsInit.OnAfterRenderAsync now explicitly imports the JS module via IJSRuntime before making any interop calls, guaranteeing the global is defined

The import() call is idempotent — if the module was already loaded by the auto-loading mechanism, the browser returns the cached module with no extra cost.

Test plan

  • Deploy to prod, verify no blazorApplicationInsights was undefined error in browser console
  • Verify Application Insights receives telemetry with cloud role/instance tags

@kolatts
kolatts merged commit a565283 into main Mar 21, 2026
1 check passed
@kolatts
kolatts deleted the kolatts/fix-appinsights-explicit-module-load branch March 21, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant