Repository navigation
Make native module resolution lazy and expose core internals entry point #1316
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
Merged
cdn34dd
merged 10 commits into
develop
from
carlosnogueira/draft/lazy-native-module-resolution
Nov 4, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b6c3981
Make native module specs resolve lazily
cdn34dd 8eefac3
Add import safety regression tests
cdn34dd 5ba18cc
Expose core internals entry point
cdn34dd dd71829
Adapt native module tests after rebase
cdn34dd 1836b10
Fix lint errors
cdn34dd e401ee3
Resolve native modules lazily in SDK wrappers
cdn34dd 17e64ed
Don't cache missing native modules
cdn34dd 89808f9
Remove Proxy from DdSdkInternal
cdn34dd 4a5e70f
Fix import safety and bridge tests
cdn34dd 70bd170
Fix lazy flags resolution and Babel plugin test mock
cdn34dd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| describe('./internal entry', () => { | ||
| it('exports the internals react-native-vega needs', () => { | ||
| // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires | ||
| const internal = require('../internal'); | ||
| const expected = [ | ||
| 'addDefaultValuesToAutoInstrumentationConfiguration', | ||
| 'buildConfigurationFromPartialConfiguration', | ||
| 'DdSdkNativeConfiguration', | ||
| 'RUM_DEFAULTS', | ||
| 'adaptLongTaskThreshold', | ||
| 'version', | ||
| 'AccountInfoSingleton', | ||
| 'AttributesSingleton', | ||
| 'UserInfoSingleton', | ||
| 'GlobalState', | ||
| 'BufferSingleton', | ||
| 'DatadogProviderState', | ||
| 'DdRumResourceTracking' | ||
| ]; | ||
| for (const name of expected) { | ||
| expect(internal[name]).toBeDefined(); | ||
| } | ||
| }); | ||
|
|
||
| // Import safety of this entry point is covered in wrapperImportSafety.test.ts. | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
| * This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| * Copyright 2016-Present Datadog, Inc. | ||
| */ | ||
|
|
||
| describe('native spec getters', () => { | ||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['../specs/NativeDdSdk', 'getNativeDdSdk', 'DdSdk'], | ||
| ['../specs/NativeDdRum', 'getNativeDdRum', 'DdRum'], | ||
| ['../specs/NativeDdLogs', 'getNativeDdLogs', 'DdLogs'], | ||
| ['../specs/NativeDdTrace', 'getNativeDdTrace', 'DdTrace'], | ||
| ['../specs/NativeDdFlags', 'getNativeDdFlags', 'DdFlags'] | ||
| ])( | ||
| '%s retries a missing module and caches it once found', | ||
| (modulePath, getterName, registryName) => { | ||
| jest.isolateModules(() => { | ||
| // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires | ||
| const { TurboModuleRegistry } = require('react-native'); | ||
| const nativeModule = { name: registryName }; | ||
| const getSpy = jest | ||
| .spyOn(TurboModuleRegistry, 'get') | ||
| .mockReturnValueOnce(null) | ||
| .mockReturnValue(nativeModule); | ||
| // eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires | ||
| const getter = require(modulePath)[getterName]; | ||
|
|
||
| expect(getter()).toBeNull(); | ||
| expect(getter()).toBe(nativeModule); | ||
| expect(getter()).toBe(nativeModule); | ||
| expect(getSpy).toHaveBeenCalledTimes(2); | ||
| expect(getSpy).toHaveBeenCalledWith(registryName); | ||
| }); | ||
| } | ||
| ); | ||
|
|
||
| it('FlagsClient retries a missing module and uses it for fetching and tracking', async () => { | ||
| await jest.isolateModulesAsync(async () => { | ||
| // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires | ||
| const { TurboModuleRegistry } = require('react-native'); | ||
| const nativeModule = { | ||
| setEvaluationContext: jest.fn().mockResolvedValue({ | ||
| feature: { key: 'feature', value: true, reason: 'STATIC' } | ||
| }), | ||
| trackEvaluation: jest.fn().mockResolvedValue(undefined) | ||
| }; | ||
| const getSpy = jest | ||
| .spyOn(TurboModuleRegistry, 'get') | ||
| .mockReturnValueOnce(null) | ||
| .mockReturnValue(nativeModule); | ||
| // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires | ||
| const { FlagsClient } = require('../flags/FlagsClient'); | ||
| const client = new FlagsClient('late-native'); | ||
| const context = { targetingKey: 'user', attributes: {} }; | ||
|
|
||
| expect(getSpy).not.toHaveBeenCalled(); | ||
| await expect( | ||
| client.setEvaluationContext(context) | ||
| ).rejects.toThrow(); | ||
| await expect( | ||
| client.setEvaluationContext(context) | ||
| ).resolves.toBeUndefined(); | ||
| expect(nativeModule.setEvaluationContext).toHaveBeenCalledWith( | ||
| 'late-native', | ||
| 'user', | ||
| {} | ||
| ); | ||
| expect(client.getBooleanValue('feature', false)).toBe(true); | ||
| expect(nativeModule.trackEvaluation).toHaveBeenCalledWith( | ||
| 'late-native', | ||
| 'feature', | ||
| expect.objectContaining({ value: true }), | ||
| 'user', | ||
| {} | ||
| ); | ||
| expect(getSpy).toHaveBeenCalledTimes(2); | ||
| expect(getSpy).toHaveBeenCalledWith('DdFlags'); | ||
| }); | ||
| }); | ||
|
|
||
| it('DdSdkWrapper picks up a module that was missing on first use', () => { | ||
| jest.isolateModules(() => { | ||
| // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires | ||
| const { TurboModuleRegistry } = require('react-native'); | ||
| const nativeModule = { clearAllData: jest.fn() }; | ||
| jest.spyOn(TurboModuleRegistry, 'get') | ||
| .mockReturnValueOnce(null) | ||
| .mockReturnValue(nativeModule); | ||
| // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires | ||
| const { DdSdkWrapper } = require('../sdk/DdSdkInternal'); | ||
| const sdk = new DdSdkWrapper(); | ||
|
|
||
| expect(() => sdk.clearAllData()).toThrow(); | ||
| sdk.clearAllData(); | ||
| expect(nativeModule.clearAllData).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.