Skip to content

fix(webview): show modes skeleton until view state loads (vps2 F7) - #1567

Draft
easonLiangWorldedtech wants to merge 12 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2/f7-viewstate-loaded
Draft

fix(webview): show modes skeleton until view state loads (vps2 F7)#1567
easonLiangWorldedtech wants to merge 12 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2/f7-viewstate-loaded

Conversation

@easonLiangWorldedtech

Copy link
Copy Markdown
Contributor

Tracking: easonLiangWorldedtech#41 (vps2 series ledger). Upstream issue: #1566 (this series' gap record; the original upstream bug is #915). Port source: upstream PR #928 (fix(webview): add loading skeleton for view state initialization) — closed/superseded; the #41 ledger names #928 as the F7 port source (webview-ui sections only).

Scope

6 files, 96 insertions, 5 deletions (measured vs stack base f42c571); all under webview-ui/:

  • webview-ui/src/context/ExtensionStateContext.tsx (6+/0-) — the viewStateLoaded plumbing: interface field + setViewStateLoaded, the useState (initial false), setViewStateLoaded(true) right after setDidHydrateState(true) in the state-message handler, and both on the context value.
  • webview-ui/src/components/modes/ModesView.tsx (12+/0-) — the loading skeleton (data-testid modes-view-loading-skeleton, aria-busy) returned while viewStateLoaded === false, before the main return.
  • webview-ui/src/components/modes/tests/ModesView.spec.tsx (15+/0-) — the mock fields (viewStateLoaded, setViewStateLoaded) + the new "shows a loading skeleton while view-local state is initializing" test (skeleton testid present, mode-select-trigger absent, stale mode/profile text absent).
  • webview-ui/src/context/tests/ExtensionStateContext.spec.tsx (62+/2-) — the TestComponent wiring (view-state-loaded testid + set-view-state-loaded button) + 3 new tests: initializes false; true after the first state message; setViewStateLoaded callable.
  • webview-ui/src/App.tsx (0+/3-) — the folded fix(webview): add loading skeleton for view state initialization #928 hunk: the bare webviewDidLaunch useEffect (comment + 2 lines) deleted; the payload-carrying webviewDidLaunch post already lives in ExtensionStateContext.tsx (F1c) and is untouched. This hunk was planned for F1c but shipped without it; it is functionally part of the [UX] Flash of incorrect mode/apiConfig when opening new editor tab #915 flash fix.
  • webview-ui/src/tests/App.spec.tsx (1+/0-) — the getViewStateId mock field in the vscode mock factory (absent at the base — F1c shipped without it — so it was added in this unit).

Budget

  • a+d 101 vs the 400-soft / 1000-hard budget: comfortably under both caps.
  • Stryker-diff gate (vs f42c571, final head c00ffc3): exit 0 on an independent coordinator re-run — webview package: 16 changed executable lines (within the 500 cap), 7 raw mutants (within the 400 cap), 7 killed, 0 survived / 0 no-coverage / 0 timeout (ModesView.tsx L617 the viewStateLoaded === false condition: 5 mutants; ExtensionStateContext.tsx L294 the useState(false) initial value and L351 the setViewStateLoaded(true) flip: 2 mutants); thresholds high=low=100. Non-vacuous — ExtensionStateContext/ModesView executable lines change; survivors killed by tests, never suppressed.
  • vitest (webview-ui, 3 spec files): 56 passed — per file: ModesView.spec 11, ExtensionStateContext.spec 27, App.spec 18; F1c's webviewDidLaunch payload tests (ExtensionStateContext.spec) remain green as the regression sentinel.
  • check-types (webview-ui tsc --noEmit), eslint (--prune-suppressions, max-warnings 0; suppression counts flat-or-down), prettier (--end-of-line=auto): all pass — check-types exit 0 (webview-ui tsc --noEmit; the pre-push turbo hook also ran 11-package check-types, all successful); eslint exit 0 with 0 problems (first run caught one zoo/no-raw-provider-identifiers error in a new test — fixed in the new code by using providerIdentifiers.anthropic, import already present; no lint suppressed; src/eslint-suppressions.json 346 entries with identical per-file counts HEAD vs worktree — the file is unmodified); prettier clean.

Port fidelity (coordinator-verified)

Series mechanics

  • Base of record: upstream/main @ 0d937c0; PR base is main; the branch is stacked on the F6 head f42c571 (the F1-series, F2, F3, F4, F5, F6 heads merge below it in the series merge order).
  • Draft PR per unit; merge order F1a to F1b to F1c to F2 to F3 to F4 to F5 to F6 to F7 (this unit is the final one).
  • CS not-ported register (for consistency): (1) kimi-code OAuth try/catch + routerModels.spec.ts +29; (2) ApiConfigManager.tsx min-w-0 shrink to grow; (3) ApiConfigManager.visual.tsx deletion + 2 PNG baselines; (4) mojibake comment; (5) unused defaultModeSlug import — resolved by F3; (6) providers/, .coderabbit.yaml, .github/, CONTRIBUTING.md, .gitignore churn.
  • Merge check against upstream main 4c7474d (merge-base = base of record 0d937c0), via git merge-tree on the full F0-to-F7 stack: tree 5d501258151125460412c8852e96588a84057c98; auto-merges Task.ts, Task.spec.ts, ClineProvider.ts, ClineProvider.spec.ts; the sole conflict is src/eslint-suppressions.json (stage blobs base 0706dbe6fb5c / upstream 381cf0c1e03f / F7 73323b9f3c43 — identical profile to the F5/F6 merge checks; F7 touches no src/ file; resolved by mechanical prune at merge time)

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • coderabbit-review-active

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 6b0a7fa7-d52e-4692-bf78-0b65fe5b6686

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Wait for required CI checks; awaiting-maintainer requires CI and automated review completion.

Review-state labels are managed by this workflow; do not edit them manually.

…States

Each ClineProvider instance now owns a unique viewId (renderContext plus a
monotonic counter) and registers a stable viewStateId for durable persistence.

- Per-view state buffer (viewLocalState) holds mode / currentApiConfigName /
  apiConfiguration overrides in memory; saveViewState persists the non-secret
  subset durably under the active view id, rekeyed to the stable id on
  registration.
- viewStates is stored as a map pruned to the newest 50 entries; writes go
  through a serialized queue so concurrent provider instances merge without
  lost updates.
- setViewStateId sanitizes ids and rejects "__proto__" so a per-view entry can
  never be keyed through the Object.prototype setter.
- postMessageToWebview no longer awaits the webview ack: a remounted or
  disposed page never acknowledges, and awaiting would wedge task-critical
  callers.
- History restore falls back to the default mode view-locally instead of
  writing the shared global mode.
- GlobalState gains the "viewStates" key and GLOBAL_STATE_KEYS tracks it.

Adds F1a coverage in ClineProvider.spec.ts (viewId uniqueness, saveViewState
persistence semantics, loadViewState fallback and failure, pruning, the
__proto__ guard) and adapts the two history-restore tests in
ClineProvider.sticky-mode.spec.ts to the view-local restore. getState()
merging of hydrated per-view values and the remaining view-state suites land
in the follow-up (F1b).
…overrides

Fold ClineProvider viewLocalState on top of ContextProxy values in getState() (mode, apiConfiguration, and all per-view fields) so each webview reports its own selections while falling back to shared global state for everything else. Ports the getState-merging and local-state-isolation spec coverage from the superseded vps2 source.

Also pins the full default surface of the merged read path, including the apiConfiguration provider fill-in when provider settings sanitize the raw value away (mutation-diff gate).
… state

WMH webviewDidLaunch persists the webview view-state id via provider.setViewStateId and re-pins the view-local currentApiConfigName through provider.saveViewState when the view-local profile is missing but the shared global selection is still valid. updateSettings is routed through provider.setValue so view-local buffer and pin sync stay consistent with the other mutation paths. The webview VSCodeAPIWrapper gains a stable getViewStateId persisted via setState (with an in-memory fallback) and the launch effect posts the id with the webviewDidLaunch message.
Port vps2 F3 (mode/profile writes) from upstream 978, hunk-by-hunk against
the F1c..CS residual:

- ClineProvider: add repointPersistedViewStates() to re-point
  currentApiConfigName across per-view entries when a profile is renamed
  or replaced, and prune orphaned entries; validate handleModeSwitch slugs
  against the custom-modes manager and no-op with a log on unknown modes;
  drop the as-any cast in delegateParentAndOpenChild.
- Task: route mode switches through provider.handleModeSwitch(task) and
  keep the submitted message on failure instead of setMode().
- SwitchModeTool and specs: durable per-view mode writes.
- webviewMessageHandler: no change vs base - the kimi-code OAuth hunk in
  the residual is CS-only divergence (not-ported register item 1), not
  part of Zoo-Code-Org#978/Zoo-Code-Org#979.
- webviewMessageHandler.spec: ported only Zoo-Code-Org#979's 4 mock fields +
  defaultModeSlug import; the stack-side legacy-repair test, Key-aware
  getValue mock and em-dash comment are retained (register item 4).
  Zoo-Code-Org#979's mode-routing WMH.spec describe ("routes mode messages through
  handleModeSwitch instead of writing ContextProxy directly") exists in
  neither CS nor the stack and is ported by no unit (open question,
  logged).
- Tests: H3/H4 durable handleModeSwitch writes in ClineProvider.spec.ts;
  profile-mutation, profile-activation and handleModeSwitch-integration
  describes (incl. A4 non-focused-target regression and new
  mutation-killing tests) in ClineProvider.parallelMode.spec.ts;
  sticky-mode and webviewMessageHandler spec updates; retain the
  setViewStateId __proto__ guard + spec test - shipped F1a hardening;
  the residual's guard removal is lineage divergence, not F3 content.
- eslint-suppressions.json: no-explicit-any counts decrease for
  core/webview/ClineProvider.ts (12 -> 11) and
  core/webview/__tests__/ClineProvider.sticky-mode.spec.ts (36 -> 33).

Upstream: Zoo-Code-Org#978 (vps2 F3) - issue Zoo-Code-Org#978; content ported
hunk-by-hunk from the F1c..CS residual, cross-checked against upstream PR
…s import

- ClineProvider: new broadcastResetToAllInstances() clears each live instance's
  view-local cache and issues the single global contextProxy setValue("viewStates", undefined)
  write (single write-queue clear; no secrets involved, no prune-cap regression).
- resetState: awaits broadcastResetToAllInstances() before the final postStateToWebview
  so parallel tabs do not keep stale durable/in-memory per-view state.
- importExport: ImportWithProviderOptions.provider gains optional
  broadcastResetToAllInstances?(); importSettingsWithFeedback calls it in a guarded
  try/catch (log-only) after a successful import, so a failing broadcast never fails the import.
- importExport spec: 3 new tests (broadcast called when available / skipped when missing /
  import result preserved when broadcast throws, console.warn asserted; the skip test also
  asserts the broadcast-failure warn is NOT reached). Provider identifiers use
  providerIdentifiers.* per the zoo/no-raw-provider-identifiers rule (lint-required
  adaptation from Zoo-Code-Org#981's raw-string casts; no semantic change).
- parallelMode spec: appends the CS source-of-record describes (multi-instance isolation,
  _clearViewLocalState) — 5 new tests.
- ClineProvider spec: forward fix of the F3 resetState sentinel (F4's global viewStates
  clear removes the key; the F3-era toEqual({}) expectation is replaced by toBeUndefined())
  plus a new cross-instance resetState test pinning the multi-instance broadcast path
  (sibling view-local cache cleared; sibling and caller each post state exactly once).
- webviewMessageHandler.ts was NOT edited: the importSettings case already passes the full
  ClineProvider, which structurally satisfies the extended provider type and reaches the real
  broadcast method — Zoo-Code-Org#981's structural wrapper hunk is redundant in this stack.

Upstream: Zoo-Code-Org#980 / PR Zoo-Code-Org#981 (vps2 F4)
Ports the vps2 CS API wiring onto the F4 head 80c147f:

- startNewTask(newTab, preserveOpenTabs): skips editor revert/close-all
  when preserveOpenTabs is set
- task ask registry: approveTaskAsk + selectTaskFollowupSuggestion
  (per-provider mode validation; a failed mode switch does not swallow
  the follow-up answer; a stale instance's teardown cannot evict its
  replacement)
- setConfiguration routes through ClineProvider.setValues so the
  view-local subset stays in sync with the sidebar view's state
- getConfiguration flattens the nested view-local apiConfiguration and
  strips secrets before returning
- getGlobalState read surface (test-only)
- docs: setConfiguration JSDoc now states writes target the
  extension-host (sidebar) view (parked A4 major, documented
  limitation); @PARAM note added for preserveOpenTabs
- specs: api-task-control (12 tests), api-set-configuration (1),
  api-configuration getConfiguration flatten/strip-secrets (1)

Upstream: Zoo-Code-Org#982 (vps2 F5)
Port source: CS e9a44b2 apps/vscode-e2e (A5 Zoo-Code-Org#929 re-review series) — 3 files byte-identical, 2 suite tests
F6-authored: sidebar webview reload/rehydration test (A5 minor 2) — the durable per-view mode survives a sidebar hide/show cycle
- ExtensionStateContext: viewStateLoaded plumbing (context field, initial
  state, setViewStateLoaded; flipped to true on the first state message)
- ModesView: renders a loading skeleton while view-local state is
  initializing, so stale mode/profile values never flash
- App.tsx: remove the bare webviewDidLaunch postMessage useEffect
  (F1c-owned hunk from Zoo-Code-Org#928, folded in here because F1c landed without
  it); the payload-carrying post now lives only in ExtensionStateContext
- Tests: skeleton regression test (ModesView), viewStateLoaded lifecycle
  tests (ExtensionStateContext), getViewStateId in the App vscode mock

Upstream: Zoo-Code-Org#915 / PR Zoo-Code-Org#928 (vps2 F7)
@github-actions github-actions Bot removed the has-conflicts PR has merge conflicts with the base branch label Sep 7, 2026
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.60000% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/webview/ClineProvider.ts 98.38% 0 Missing and 4 partials ⚠️
webview-ui/src/utils/vscode.ts 86.36% 1 Missing and 2 partials ⚠️
src/extension/api.ts 94.28% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants