fix(docs-infra): recover stale webcontainer counter after browser OOM crash#67219
Open
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
Open
fix(docs-infra): recover stale webcontainer counter after browser OOM crash#67219yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
beforeunloadevent is never fired, so the webcontainer instance counter stored inlocalStorageis 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.isNaNguard ingetStoredCountOfWebcontainerInstanceswas applied to the raw string fromlocalStoragerather 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:
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.Back-forward cache support: A
pageshowevent listener re-increments the counter when a page is restored from the bfcache (event.persisted === true), sincebeforeunloadwould have already decremented it when the page was initially frozen.Defensive counter guards: The counter is clamped to a minimum of
0in both the decrement handler and the getter, preventing negative values from corrupted or stalelocalStoragestate. TheNumber.isNaNcheck now operates on the parsed number.Additional context
beforeunloadhandler no longer callsvalidateRunningInstances()since the page is closing and showing a snackbar would have no visible effect.pageshowhandler only re-increments onpersisted === true(bfcache restore), so Safari OOM reloads (which are fresh loads) do not cause double-counting — they go throughinit()which handles the increment.AlertManagercovering: counter increment/decrement, negative value clamping, bfcache restoration, NaN handling, OOM snackbar display, and counter reset on snackbar dismissal.