Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve circular dependency in Analytics context #1686

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VolodymyrBg
Copy link
Contributor

What changed?

Fixed a critical issue in the Analytics context implementation where there was a circular dependency problem. The changes include:

  1. Removed self-referential context usage in AnalyticsProvider
  2. Added a new parentContext prop for proper context inheritance
  3. Optimized context string concatenation using useMemo
  4. Improved type safety and error handling

Key changes:

  • Replaced useAnalytics() usage inside provider with direct prop-based context inheritance
  • Added optional parentContext prop to AnalyticsProviderProps
  • Implemented proper context string concatenation with memoization

Notes to reviewers

  • The main issue was that the provider was trying to use its own context during initialization, which could lead to infinite loops and undefined behavior
  • The new implementation follows React's context best practices
  • Special attention was given to maintaining backward compatibility
  • The TypeScript error about React imports needs to be addressed at the project configuration level

How has it been tested?

The changes have been tested in the following scenarios:

  1. Basic context initialization

    • Verified provider initializes without circular dependency errors
    • Confirmed context values are properly passed to children
  2. Context inheritance

    • Tested nested providers with different context values
    • Verified proper concatenation of parent and child contexts
  3. Event logging

    • Confirmed logEventWithContext continues to work as expected
    • Verified event context strings are properly formatted
  4. Error scenarios

    • Verified proper error handling when context is used outside provider
    • Tested with undefined/empty context values

No regression issues were found during testing.

- Remove circular dependency where AnalyticsProvider was using its own context
- Introduce parentContext prop for proper context inheritance
- Optimize context concatenation using useMemo
- Fix potential infinite loops and undefined behavior
- Improve error handling for context initialization

This change prevents the Analytics context from attempting to use itself during initialization, which could cause crashes or unexpected behavior. The new implementation properly handles context inheritance through props instead of self-reference.
Copy link

vercel bot commented Jan 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web-base-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 8:24pm

@cb-heimdall
Copy link
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

Copy link

vercel bot commented Jan 31, 2025

@VolodymyrBg is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base web review To be reviewed by the Base web team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants