Skip to content

Comments

fix(docs-infra): recover stale webcontainer counter after browser OOM crash#67219

Open
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
yogeshwaran-c:fix/webcontainer-counter-recovery
Open

fix(docs-infra): recover stale webcontainer counter after browser OOM crash#67219
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
yogeshwaran-c:fix/webcontainer-counter-recovery

Conversation

@yogeshwaran-c
Copy link

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

When a browser tab crashes due to an out-of-memory (OOM) error — particularly common on Safari — the beforeunload event is never fired, so the webcontainer instance counter stored in localStorage is not decremented. This causes the counter to become permanently inflated, leading to false OOM warnings on subsequent page loads even when the user has fewer tabs open than the recommended maximum.

Additionally, the Number.isNaN guard in getStoredCountOfWebcontainerInstances was applied to the raw string from localStorage rather than the parsed number, making it ineffective at detecting corrupted values.

Closes #52647

What is the new behavior?

Three complementary fixes address the stale counter problem:

  1. Reset on snackbar dismissal: When the user dismisses the OOM warning by clicking "I understand", the counter is reset to 1 (the current tab). This provides a direct user-driven recovery mechanism for stale counters from crashed tabs.

  2. Back-forward cache support: A pageshow event listener re-increments the counter when a page is restored from the bfcache (event.persisted === true), since beforeunload would have already decremented it when the page was initially frozen.

  3. Defensive counter guards: The counter is clamped to a minimum of 0 in both the decrement handler and the getter, preventing negative values from corrupted or stale localStorage state. The Number.isNaN check now operates on the parsed number.

Additional context

  • The beforeunload handler no longer calls validateRunningInstances() since the page is closing and showing a snackbar would have no visible effect.
  • The pageshow handler only re-increments on persisted === true (bfcache restore), so Safari OOM reloads (which are fresh loads) do not cause double-counting — they go through init() which handles the increment.
  • Added comprehensive tests for AlertManager covering: counter increment/decrement, negative value clamping, bfcache restoration, NaN handling, OOM snackbar display, and counter reset on snackbar dismissal.

… crash

When a browser tab crashes due to an out-of-memory error (particularly on
Safari), the `beforeunload` event is never fired, so the webcontainer instance
counter in localStorage is not decremented. This leads to a permanently
inflated counter that falsely triggers the OOM warning on subsequent page loads.

This commit introduces three complementary fixes:

1. **Reset on snackbar dismissal**: When the user dismisses the OOM warning by
   clicking "I understand", the counter is reset to 1 (the current tab). This
   provides a direct recovery mechanism for stale counters.

2. **Back-forward cache support**: A `pageshow` event listener re-increments
   the counter when a page is restored from the bfcache (`persisted === true`),
   since `beforeunload` would have already decremented it.

3. **Defensive counter guards**: The counter is clamped to a minimum of 0 in
   both the decrement handler and the getter, preventing negative values from
   corrupted or stale localStorage state. The `Number.isNaN` check is also
   fixed to operate on the parsed number rather than the raw string.

Closes angular#52647
@pullapprove pullapprove bot requested a review from devversion February 23, 2026 18:33
@angular-robot angular-robot bot added the area: docs-infra Angular.dev application and infrastructure label Feb 23, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 23, 2026
@devversion devversion requested review from JeanMeche and removed request for devversion February 23, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs-infra Angular.dev application and infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: counter of running webcontainer is not decreased when browser crashed due to OOM

1 participant