Skip to content

Nt 2571 implement react web sdk root provider components and related hooks#161

Merged
Lotfi Anwar L Arif (Lotfi-Arif) merged 15 commits intomainfrom
NT-2571-implement-react-web-sdk-root-provider-components-and-related-hooks
Mar 4, 2026
Merged

Nt 2571 implement react web sdk root provider components and related hooks#161
Lotfi Anwar L Arif (Lotfi-Arif) merged 15 commits intomainfrom
NT-2571-implement-react-web-sdk-root-provider-components-and-related-hooks

Conversation

@Lotfi-Arif
Copy link
Contributor

Summary

  • Implemented React Web core parity primitives for @contentful/optimization-react-web:

    • Added OptimizationContext + OptimizationProvider (required instance)
    • Added useOptimization() with actionable error outside provider
    • Added LiveUpdatesContext + LiveUpdatesProvider (global live updates state)
    • Added useLiveUpdates() (nullable outside provider)
  • Implemented OptimizationRoot as the recommended wrapper

  • Updated public exports from package entrypoint.

  • Added/updated unit tests to cover:

    • Provider context wiring
    • useOptimization() error behavior outside provider
    • Root default and propagation of liveUpdates
    • Combined useOptimization() + useLiveUpdates() usage under OptimizationRoot
    • Live updates fallback semantics (component override -> root -> false)
  • Updated package README with usage and provider requirements

  • Wired minimal dev harness integration:

    • Creates/reuses a real @contentful/optimization-web instance
    • Wraps app with OptimizationRoot
    • Displays simple runtime wiring status (instance + global live updates)

- Update OptimizationRoot and OptimizationProvider to accept SDK config
  props
  (clientId, environment, analytics, etc.) instead of an instance
- Update README and usage docs to reflect new initialization pattern
- Update dev and test apps to use config-as-props pattern
- Improve error messages and test coverage for provider usage
- Remove legacy instance-based initialization code
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome!

- Use OptimizationConfig for provider props
- Change useLiveUpdates to throw outside provider
- Remove logLevel from dev config
- Update live updates resolution example
- Export OptimizationConfig type from web SDK
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only thing I think probably needs to change (after this PR) is the necessity of the types in the types.ts file. We can go over that separately to ensure we understand what's going on, what's available, and what should be available.

@Lotfi-Arif Lotfi Anwar L Arif (Lotfi-Arif) merged commit 60ae601 into main Mar 4, 2026
30 checks passed
@Lotfi-Arif Lotfi Anwar L Arif (Lotfi-Arif) deleted the NT-2571-implement-react-web-sdk-root-provider-components-and-related-hooks branch March 4, 2026 11:55
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.

2 participants