Skip to content

fix(browser): make shared capture synchronous - #4675

Draft
dustinbyrne wants to merge 1 commit into
mainfrom
fix/browser-next-sync-capture
Draft

fix(browser): make shared capture synchronous#4675
dustinbyrne wants to merge 1 commit into
mainfrom
fix/browser-next-sync-capture

Conversation

@dustinbyrne

Copy link
Copy Markdown
Contributor

Problem

Browser extension clients and the private experimental @posthog/browser client exposed capture() as Promise<void>, even though capture only performs synchronous queue admission. The promise implied an asynchronous completion or delivery guarantee that did not exist and added an allocation on every capture.

Changes

  • Change the shared Client.capture() contract from Promise<void> to void.
  • Make browser-next, the legacy browser adapter, and the shared test client return synchronously after admission.
  • Keep flush() as the asynchronous delivery barrier.
  • Update extension guidance, browser-next examples, fixtures, scripts, and tests to describe and enforce the synchronous contract.
  • Add conformance coverage for immediate event publication and an undefined return value.

Compatibility and release impact

This intentionally changes the pre-1.0 @posthog/browser-common capture return type. Existing await client.capture(...) calls continue to work, but promise chaining on capture() is no longer supported. A minor @posthog/browser-common changeset records the contract change; posthog-js receives the matching adapter implementation and its dependency-driven patch bump. The private @posthog/browser package remains unpublished.

The change reduces the measured browser-next bundles by approximately 36–42 minified bytes depending on the entrypoint.

Validation

  • pnpm turbo --filter=@posthog/browser-common build
  • pnpm --dir packages/browser-common lint
  • pnpm --dir packages/browser-common test:unit — 92 tests
  • pnpm --dir packages/browser-next lint
  • pnpm --dir packages/browser-next check-types
  • pnpm --dir packages/browser-next test:unit — 343 tests, build/declarations, and mixed-module delivery
  • pnpm --dir packages/browser-next test:browser — 18 tests across Chromium, Firefox, and WebKit
  • Focused legacy browser adapter tests — 27 tests
  • Browser-v1 differential suite — 14 scenarios
  • pnpm --dir packages/browser-next bundle-size
  • Independent read-only review found no concrete issues.

Release info Sub-libraries affected

Libraries affected

  • All of them
  • posthog-js (web)
  • posthog-js-lite (web lite)
  • posthog-node
  • posthog-react-native
  • @posthog/react-native-plugin
  • @posthog/react
  • @posthog/ai
  • @posthog/convex
  • @posthog/next
  • @posthog/nextjs-config
  • @posthog/nuxt
  • @posthog/openfeature-node-provider
  • @posthog/openfeature-web-provider
  • @posthog/rollup-plugin
  • @posthog/webpack-plugin
  • @posthog/types
  • @posthog/browser-common

Checklist

  • Tests for new code
  • Accounted for the impact of any changes across different platforms
  • Accounted for backwards compatibility of any changes (no breaking changes!)
  • Took care not to unnecessarily increase the bundle size

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

The human identified that capture admission should be synchronous and selected capture(): void with flush(): Promise<void> as the explicit delivery boundary. Pi's coding agent implemented and validated the change in a local session without a public transcript link. A fresh-context built-in reviewer independently inspected the resulting diff and found no concrete issues.

@dustinbyrne dustinbyrne self-assigned this Aug 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Changeset Bump Does Not Match PR Title

This PR title uses the fix Conventional Commit type, but it contains a minor changeset:

  • .changeset/sync-browser-capture.md

Why is this blocked?

A fix: PR should generally release a patch version. A minor changeset suggests new functionality, so the PR title should usually start with feat: instead.

What should you do?

  • If this is a bug fix, change the changeset bump from minor to patch
  • If this intentionally adds new functionality, change the PR title from fix(browser): make shared capture synchronous to a feat: title

@github-actions

Copy link
Copy Markdown
Contributor
⚠️ Possible changeset mismatch — 2 undeclared

This is informational — the PR is not blocked. Click the triangle above to collapse, or push a fix and this comment will auto-delete.

Modified in this PR but not in any changeset:

  • @posthog/browser
  • posthog-js

If this package should ship the change, add it to the changeset frontmatter:

---
"@posthog/browser": patch
"posthog-js": patch
---

Changesets in this PR:

  • @posthog/browser-common — minor

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.

1 participant