Skip to content

Refactor webview contexts for explicit host ownership - #9047

Draft
Henning Dieterichs (hediet) wants to merge 6 commits into
mainfrom
hediet/webview-preparation
Draft

Henning Dieterichs (hediet) wants to merge 6 commits into
mainfrom
hediet/webview-preparation

Conversation

@hediet

@hediet Henning Dieterichs (hediet) commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Prepare the webviews for isolated, deterministic rendering without introducing Component Explorer tooling.

  • Inject a host that owns persisted state, request/reply messaging, command subscriptions, and one-way notifications.
  • Remove pull-request context singletons; production entry points and fixtures explicitly provide their contexts.
  • Production entry points use a shared owning provider: preserve the pair across rerenders, dispose context then host on unmount, and allocate a fresh pair on remount. Externally supplied contexts remain caller-owned.
  • Rebind Root subscriptions when the supplied context changes.
  • Send ready, scroll, debug, and create initialization as notifications without allocating pending reply callbacks.
  • Keep ordinary React context consumption, draft persistence, and instance-local timestamp formatting with production defaults.

Review feedback

All eight review comments were valid and are addressed by three focused fixes: owner cleanup, context replacement subscriptions, and one-way notifications. Regression tests cover all three production entry points, repeated mounts, context replacement, pending-request rejection on unmount, and notification retention/error behavior.

Validation

  • npm run test:webviews: 85 tests passed, with the normal typed webview build.
  • npm run compile:node: extension and webview builds passed.
  • npm run lint and npm run hygiene passed.
  • Existing quote-reply listener warning remains for Fix webview comment and stack action lifecycle #9049; existing duplicate GraphQL fragment warnings remain in the build.
  • No lockfile changes relative to main.

Stack and review scope

Current main was merged while preserving upstream issue previews, mergeability polling, checkout updates, and stack refresh behavior.

Inject hosts into pull request contexts, remove context singletons, and add instance-local timestamp and viewport inputs with regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Entry points retain host subscriptions after unmount, and context-switching effects remain bound to stale instances.

4 open findings
What changed in this PR

Refactors webviews to use explicitly owned hosts and contexts, enabling isolated rendering and deterministic fixtures.

Changes:

  • Introduces host-based messaging, persistence, subscriptions, and disposal.
  • Adds injectable timestamp formatting and viewport-width behavior.
  • Updates production entry points and tests for explicit context ownership.
File Description
src/​test/​webviews/​testHost.ts Adds managed test hosts.
webviews/​activityBarView/​app.tsx Injects an explicit PR context.
webviews/​common/​cache.ts Removes global state helpers.
webviews/​common/​context.tsx Makes PR context host-backed.
webviews/​common/​createContextNew.ts Makes create context host-backed.
webviews/​common/​hooks.ts Adds injectable viewport width.
webviews/​common/​host.ts Defines host and transport APIs.
webviews/​common/​message.ts Refactors request and reply handling.
webviews/​common/​test/​hooks.test.tsx Tests viewport isolation and cleanup.
webviews/​common/​test/​host.test.ts Tests host isolation and persistence.
webviews/​components/​sidebar.tsx Uses the shared viewport hook.
webviews/​components/​test/​timestamp.test.tsx Tests timestamp formatter isolation.
webviews/​components/​timestamp.tsx Adds injectable timestamp formatting.
webviews/​createPullRequestViewNew/​app.tsx Provides an explicit create context.
webviews/​createPullRequestViewNew/​test/​app.test.tsx Migrates create-view tests to test hosts.
webviews/​editorWebview/​app.tsx Provides an explicit PR context.
webviews/​editorWebview/​overview.tsx Uses the shared viewport hook.
webviews/​editorWebview/​test/​app.test.tsx Migrates root tests to test hosts.
webviews/​editorWebview/​test/​overview.test.tsx Migrates overview tests to test hosts.
webviews/​editorWebview/​test/​reviewSummary.test.tsx Migrates review tests to test hosts.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread webviews/activityBarView/app.tsx Outdated
Comment thread webviews/common/test/host.test.ts Outdated
Comment thread webviews/createPullRequestViewNew/app.tsx Outdated
Comment thread webviews/editorWebview/app.tsx Outdated
Preserve upstream issue previews, mergeability polling, and stack refresh behavior while adapting new tests to explicit hosts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use a Map for pending replies, delete entries before settling replies or after a send failure, and ignore late replies instead of dispatching them as commands.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the reply-map leak fix independently reviewable and adapt its regression tests to the injected host.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hediet
Henning Dieterichs (hediet) changed the base branch from main to hediet/message-handler-reply-cleanup October 9, 2026 17:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread webviews/activityBarView/app.tsx Outdated
Comment thread webviews/common/message.ts
Comment thread webviews/createPullRequestViewNew/app.tsx Outdated
Comment thread webviews/editorWebview/app.tsx Outdated
Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:05

@connor4312 Connor Peet (connor4312) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the complete diff and relevant host, context, entry-point, persistence, and lifecycle code. No actionable P1/P2 security or correctness issues found. No tests or builds were run.

Written by Connor's agent running GPT-6.1 Sol

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Restore production viewport code here so the hook, consumers, and regression tests are reviewed with the fixtures that require them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Base automatically changed from hediet/message-handler-reply-cleanup to main October 14, 2026 14:39
Dispose entry-point-owned hosts and contexts, rebind root subscriptions on context replacement, and send one-way messages without pending replies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hediet
Henning Dieterichs (hediet) marked this pull request as draft October 15, 2026 10:41
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.

5 participants