Skip to content

♻️ migrate all packages to individual createHook instances#4749

Draft
BenoitZugmeyer wants to merge 2 commits into
mainfrom
benoit/individual-hooks
Draft

♻️ migrate all packages to individual createHook instances#4749
BenoitZugmeyer wants to merge 2 commits into
mainfrom
benoit/individual-hooks

Conversation

@BenoitZugmeyer
Copy link
Copy Markdown
Member

Motivation

The hooks system previously used a centralized object with a HookNames enum to register and trigger callbacks. This made each consumer depend on the full hooks object even when it only needed one specific hook, and provided no per-hook type safety. Moving to individual, typed Hook instances makes each component receive exactly the hook it needs, with proper TypeScript types for its parameters and return value.

This is a first step toward moving hooks and their dependencies to js-core, which will be done in a follow-up PR.

Changes

  • Add a createHook<Params, Result>() primitive to browser-core with a typed Hook<Params, Result> interface (register / trigger), preserving DISCARDED and SKIPPED semantics
  • Replace the centralized abstractHooks-based Hooks type in browser-rum-core with a plain object of named Hook instances (assemble, assembleTelemetry)
  • Migrate all context modules (accountContext, globalContext, tabContext, urlContexts, viewCollection, trackingConsentContext) to accept individual hook instances instead of the full hooks object

Test instructions

This is a pure internal refactoring — no user-visible behaviour changes. Load any standard RUM or Logs sandbox setup and verify that events continue to be collected normally.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 171.86 KiB 172.06 KiB +208 B +0.12%
Rum Profiler 7.88 KiB 7.88 KiB 0 B 0.00%
Rum Recorder 21.21 KiB 21.21 KiB 0 B 0.00%
Logs 54.31 KiB 54.40 KiB +92 B +0.17%
Rum Slim 129.69 KiB 129.90 KiB +212 B +0.16%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@datadog-datadog-prod-us1
Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 93.75%
Overall Coverage: 76.79% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2c93329 | Docs | Datadog PR Page | Give us feedback!

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