Skip to content

Conversation

duyhungtnn
Copy link
Collaborator

@duyhungtnn duyhungtnn commented Apr 17, 2025

This PR adds support for the React Native environment by updating the SDK’s initialization flow and configuration along with new and updated tests for native and node contexts.

Please merge this PR #226 before merge this PR.

@duyhungtnn duyhungtnn marked this pull request as draft April 17, 2025 08:46
@duyhungtnn duyhungtnn changed the title fix: support react native SDK fix: support the React native environment Apr 19, 2025
@duyhungtnn duyhungtnn changed the title fix: support the React native environment fix: add support for the React Native environment. Apr 19, 2025
@duyhungtnn duyhungtnn requested a review from Copilot April 19, 2025 03:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for the React Native environment by updating the SDK’s initialization flow and configuration along with new and updated tests for native and node contexts.

  • Adds a native entry point (src/main.native.ts) that enforces an idGenerator via assertIdGenerator.
  • Introduces a DummyPlatformModule and updates platform module selection in both node and React Native environments.
  • Updates configuration (BKTConfig) to optionally accept an idGenerator and adjusts various test and e2e files accordingly.

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vitest-e2e-node.config.ts New node configuration with embedded SDK version.
test/main.native.spec.ts Tests for React Native environment ensuring proper idGenerator handling.
src/main.ts Updated platform module selection based on idGenerator presence for Node.
src/main.native.ts Added React Native entry point with mandatory idGenerator enforcement.
src/internal/di/PlatformModule.ts New BasePlatformModule and DummyPlatformModule implementations added.
src/BKTConfig.ts Extended configuration to optionally support idGenerator.
e2e/node/BKTClient.spec.ts End-to-end tests for Node environment with updated logic.
e2e/browser/events.spec.ts Import path updates for browser events tests.
e2e/browser/evaluations.spec.ts Import path updates for browser evaluations tests.
e2e/browser/BKTClient.spec.ts Import path updates and revised test setup for browser client tests.
Files not reviewed (1)
  • package.json: Language not supported

@duyhungtnn duyhungtnn force-pushed the feat/support-react-native-sdk branch from c5751a0 to 316f045 Compare April 21, 2025 02:53
@duyhungtnn duyhungtnn requested a review from Copilot April 21, 2025 03:24
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for the React Native environment by introducing a new native entry point while updating configurations and tests for multiple environments.

  • Adds a new React Native initialization file (src/main.native.ts) that enforces the presence of an idGenerator.
  • Updates configuration and DI logic to conditionally use BasePlatformModule when an idGenerator is provided.
  • Adjusts e2e tests and environment setups (both browser and node) to use environment-appropriate fetch providers and storage handling.

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vitest-e2e.config.ts Adds browser-specific setup file to support e2e tests in happy-dom environment.
vitest-e2e-node.config.ts Introduces a new e2e config for node with proper setup files.
test/main.native.spec.ts Adds tests ensuring requiredIdGenerator behavior in the native environment.
src/main.ts Modifies component creation to conditionally use BasePlatformModule when idGenerator is set.
src/main.native.ts New file providing React Native initialization using requiredIdGenerator.
src/internal/di/PlatformModule.ts Adds BasePlatformModule implementation for environments where an idGenerator is provided.
src/BKTConfig.ts Updates configuration to optionally include an idGenerator.
e2e/**/*.ts Adjusts various tests to rely on fetchLike and conditionally clear localStorage.
e2e/environment.ts Provides functions to set fetch provider and environment flags.
e2e/BKTClient.spec.ts Updates tests to use fetchLike and remove redundant localStorage clear calls.
Files not reviewed (1)
  • package.json: Language not supported
Comments suppressed due to low confidence (2)

src/internal/di/PlatformModule.ts:10

  • [nitpick] Consider renaming '_idGenerator' to 'idGenerator' to simplify the property name, unless the underscore prefix is a deliberate convention for indicating a protected member.
protected _idGenerator: IdGenerator

e2e/events.spec.ts:177

  • [nitpick] Consider abstracting the localStorage clearing logic into a helper function to reduce repetition and improve maintainability in your test cleanup code.
if (typeof localStorage !== 'undefined') { localStorage.clear() }

@duyhungtnn duyhungtnn requested a review from Copilot April 21, 2025 03:33
Copilot

This comment was marked as outdated.

@duyhungtnn duyhungtnn force-pushed the feat/support-react-native-sdk branch from e9284fd to 116c420 Compare May 11, 2025 01:39
@duyhungtnn duyhungtnn force-pushed the feat/support-react-native-sdk branch from 116c420 to f56b14b Compare June 12, 2025 04:55
@duyhungtnn duyhungtnn force-pushed the feat/support-react-native-sdk branch 2 times, most recently from f29d97d to b0dcaa8 Compare July 8, 2025 15:22
@duyhungtnn duyhungtnn self-assigned this Jul 20, 2025
@duyhungtnn duyhungtnn requested a review from Copilot July 20, 2025 03:45
@duyhungtnn duyhungtnn marked this pull request as ready for review July 20, 2025 03:45
@duyhungtnn duyhungtnn changed the title fix: add support for the React Native environment. feat: support for the React Native environment. Jul 20, 2025
Copilot

This comment was marked as outdated.

@duyhungtnn duyhungtnn requested a review from cre8ivejp July 20, 2025 03:46
@duyhungtnn
Copy link
Collaborator Author

@cre8ivejp please help me to take a look.

fix: support react native SDK

fix: test fail on node:e2e

test: remove duplicate/ unnecessary  localStorage.clear()

Update events.spec.ts

Update events.spec.ts

test: inject correct entry point for node environment

Update package.json

Update package.json

fix: lint fail

chore: required id-generator for react native environment

bump to 2.2.13

fix: missing default user agent in react native environment

Update package.json
@duyhungtnn duyhungtnn force-pushed the feat/support-react-native-sdk branch from 0259869 to 346bd91 Compare July 31, 2025 06:50
@duyhungtnn duyhungtnn requested a review from Copilot July 31, 2025 06:52
Copilot

This comment was marked as outdated.

Comment on lines +66 to +70
if (
typeof window !== 'undefined' &&
window.navigator &&
typeof window.navigator.userAgent === 'string'
) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

on react-native environment, we have window != undefined but the navigator is undefined.

@cre8ivejp cre8ivejp requested a review from Copilot July 31, 2025 08:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds React Native support to the JavaScript client SDK by introducing environment-specific entry points and configuration validation. The implementation ensures React Native environments provide required dependencies while maintaining compatibility with existing browser and Node.js environments.

Key changes:

  • Added React Native-specific module with mandatory idGenerator validation
  • Updated package.json exports to include React Native entry points
  • Refactored e2e tests to support multiple environments with shared test logic

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main.native.ts New React Native entry point with idGenerator validation
src/BKTConfig.ts Added idGenerator to configuration interface and improved user agent detection
src/internal/di/PlatformModule.ts Added BasePlatformModule for dependency injection
package.json Added React Native exports and updated test scripts
e2e/ files Refactored tests for environment-agnostic execution
Comments suppressed due to low confidence (1)

@cre8ivejp cre8ivejp changed the title feat: support for the React Native environment. feat: support for the React Native environment Jul 31, 2025
Copy link
Member

@cre8ivejp cre8ivejp left a comment

Choose a reason for hiding this comment

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

Nice work 🚀

@cre8ivejp cre8ivejp merged commit 9825060 into main Jul 31, 2025
3 checks passed
@cre8ivejp cre8ivejp deleted the feat/support-react-native-sdk branch July 31, 2025 08:47
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