Skip to content

Fix browser WebView refresh on workspace hide - #4388

Merged
austinywang merged 1 commit into
mainfrom
issue-4387-browser-refresh-regression
May 19, 2026
Merged

austinywang merged 1 commit into
mainfrom
issue-4387-browser-refresh-regression

Conversation

@austinywang

@austinywang austinywang commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • make Browser Memory Saver opt-in so normal workspace hide/show keeps the live WKWebView and DOM state
  • add a regression test for hiding past the discard delay without replacing the WKWebView
  • keep explicit memory-saver discard coverage by enabling the policy inside those tests

Fixes #4387

Verification

  • Not run locally per task instruction; CI will run the checks.

Note

Medium Risk
Changes the default browser tab lifecycle behavior by disabling hidden WebView discarding unless explicitly enabled, which could affect memory usage and tab restore behavior. Risk is mitigated by updated and new unit tests around discard/restore and workspace hide/show identity preservation.

Overview
Makes Browser Memory Saver opt-in by changing BrowserHiddenWebViewDiscardPolicy.defaultEnabled and the settings schema browser.discardHiddenWebViews default from true to false, so normal workspace hide/show keeps the same live WKWebView and DOM state.

Updates BrowserPanelWebViewLifecycleTests to manage discard-related UserDefaults per-test, skip appropriately when environment overrides make behavior unobservable, add a regression test asserting WebView identity is preserved when hidden past the discard delay with the policy disabled, and explicitly enable the policy in discard/restore tests to keep coverage.

Reviewed by Cursor Bugbot for commit 233dbe4. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Make Browser Memory Saver opt-in so hidden tabs no longer auto-discard. Keeps the live WKWebView and DOM when a workspace is hidden and re-shown, fixing the refresh regression (addresses #4387).

  • Bug Fixes
    • Default BrowserHiddenWebViewDiscardPolicy to disabled; update discardHiddenWebViews default in web/data/cmux.schema.json to false.
    • Preserve WKWebView identity across workspace hide/show to avoid reloads.
    • Add regression tests for the default-preserve behavior and for explicit memory-saver discard paths (with environment override handling).

Written for commit 233dbe4. Summary will update on new commits. Review in cubic

@vercel

vercel Bot commented May 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment May 19, 2026 9:57pm
cmux-staging Building Building Preview, Comment May 19, 2026 9:57pm

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@austinywang has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 96dadcf1-c233-4d24-a582-69dee52e1036

📥 Commits

Reviewing files that changed from the base of the PR and between 4d04459 and 233dbe4.

📒 Files selected for processing (3)
  • Sources/Panels/BrowserHiddenWebViewDiscardPolicy.swift
  • cmuxTests/GhosttyConfigTests.swift
  • web/data/cmux.schema.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-4387-browser-refresh-regression

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes Browser Memory Saver (WebView discard on workspace hide) opt-in by changing defaultEnabled from true to false in both the Swift policy enum and the JSON schema, fixing a regression where normal workspace hide/show was discarding and recreating the live WKWebView.

  • BrowserHiddenWebViewDiscardPolicy.defaultEnabled is flipped to false and cmux.schema.json is updated to match, so hidden-webview discard is now off unless the user explicitly enables it.
  • A new regression test (testDefaultWorkspaceVisibilityHidePreservesWebViewIdentityPastDiscardDelay) verifies that hiding a workspace past the discard delay with the default policy preserves the original WKWebView identity and DOM state.
  • Existing discard tests are wrapped with withHiddenWebViewDiscardDefaults(enabled: true) and appropriate skip guards so they continue to exercise the explicit opt-in path without being broken by the default change.

Confidence Score: 5/5

Safe to merge — the change is a one-line default flip in the policy enum, mirrored in the schema, with a targeted regression test and well-guarded updates to existing discard tests.

The default flip from opt-out to opt-in is minimal and correct. The new regression test directly exercises the fix path, and the skip guards and withHiddenWebViewDiscardDefaults wrapper keep existing coverage accurate. No production logic paths are altered beyond the default value.

No files require special attention.

Important Files Changed

Filename Overview
Sources/Panels/BrowserHiddenWebViewDiscardPolicy.swift Single-line change: flips defaultEnabled from true to false, making Browser Memory Saver opt-in instead of opt-out. Change is correct and consistent with the schema update.
cmuxTests/GhosttyConfigTests.swift Adds a new regression test verifying that workspace hide/show preserves WKWebView identity when the policy is disabled (the new default); wraps existing discard tests with withHiddenWebViewDiscardDefaults(enabled: true) and skip guards to keep them green after the default flip. RunLoop-spin wait helper is test-only scaffolding refactored from existing inline code.
web/data/cmux.schema.json Mirrors the Swift default change: discardHiddenWebViews default flipped from true to false. Schema description is developer-facing documentation; no i18n impact.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Workspace hides BrowserPanel] --> B{BrowserHiddenWebViewDiscardPolicy.isEnabled?}
    B -- "env var = '1'/'true'/..." --> C[Policy ENABLED]
    B -- "env var = '0'/'false'/..." --> D[Policy DISABLED]
    B -- "no env var" --> E{UserDefaults key set?}
    E -- "yes" --> F{UserDefaults value}
    F -- "true" --> C
    F -- "false" --> D
    E -- "no (key absent)" --> G["defaultEnabled = false (changed in this PR)"]
    G --> D
    C --> H{hiddenDelay elapsed?}
    H -- "yes" --> I[discardHiddenWebViewForMemory → replaces WKWebView]
    H -- "no" --> J[Keep live WKWebView in liveHidden state]
    D --> J
    J --> K[Workspace shown → same WKWebView rebinds, no reload]
    I --> L[Workspace shown → new WKWebView restores from history]
Loading

Reviews (1): Last reviewed commit: "fix: keep browser webviews alive by defa..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

This branch was successfully deployed

1 active deployment
Preview – cmux — 233dbe4b Deployed May 19, 2026 by vercel[bot]
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.

Browser panes occasionally refresh and lose state on workspace switch / new-workspace (regression of #1132)

1 participant