Skip to content

refactor: move browser utils to browser-common#3897

Draft
dustinbyrne wants to merge 8 commits into
PostHog:mainfrom
dustinbyrne:move-browser-utils-to-browser-common
Draft

refactor: move browser utils to browser-common#3897
dustinbyrne wants to merge 8 commits into
PostHog:mainfrom
dustinbyrne:move-browser-utils-to-browser-common

Conversation

@dustinbyrne

@dustinbyrne dustinbyrne commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

@posthog/browser-common is intended to host shared browser SDK code for both v1 and v2. The v1 browser package still owned the utility layer locally, which would make moving extensions over harder and duplicate common runtime helpers.

Changes

  • Moved the packages/browser/src/utils implementation into packages/browser-common/src/utils and exported those modules from @posthog/browser-common.
  • Added a small browser-common runtime configuration shim so v1 can provide its mutable SDK config, cookie store, and local store to the shared utilities.
  • Updated packages/browser source and tests to import utilities from @posthog/browser-common.
  • Kept the old survey ActionMatcher path as a compatibility re-export while the extensions themselves remain in packages/browser.
  • Updated Jest/Rollup resolution so browser tests and bundles can consume browser-common source modules.

Validation run locally:

  • pnpm --filter=@posthog/browser-common lint
  • pnpm --filter=@posthog/browser-common build
  • pnpm --filter=@posthog/browser-common test:unit
  • pnpm --filter=posthog-js lint
  • pnpm --filter=posthog-js exec jest src/__tests__/utils/event-utils.test.ts src/__tests__/utils/survey-event-receiver.test.ts src/__tests__/utils/product-tour-event-receiver.test.ts src/__tests__/request-utils.test.ts src/__tests__/utils/elements-chain-utils.test.ts src/__tests__/utils/request-router.test.ts --runInBand

Known local limitation: pnpm --filter=posthog-js build currently stops before bundling because the rrweb workspace packages are not built locally (@posthog/rrweb* type declarations missing). Attempting to build @posthog/rrweb-types is blocked by existing TypeScript 6 deprecation errors in that package's tsconfig.

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/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)

Implemented with Pi. The user asked to prepare @posthog/browser-common for shared v1/v2 browser code by moving the browser utility layer first, before moving extensions. I kept extension implementation code in packages/browser, except for the survey action matcher which is now shared as a utility and re-exported from the old path for compatibility.

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Too many files changed for review. (186 files found, 100 file limit)

@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

@dustinbyrne is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

@dustinbyrne dustinbyrne self-assigned this Jun 18, 2026
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