diff --git a/change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json b/change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json new file mode 100644 index 00000000000..741668071df --- /dev/null +++ b/change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Allow disabling Blob Cxx module", + "packageName": "react-native-windows", + "email": "julio.rocha@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp b/vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp index b9f3886dc94..cfdda6f0ff6 100644 --- a/vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp +++ b/vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp @@ -223,5 +223,12 @@ TEST_CLASS (RNTesterIntegrationTests) { Assert::AreEqual(TestStatus::Passed, result.Status, result.Message.c_str()); } + BEGIN_TEST_METHOD_ATTRIBUTE(Fetch) + END_TEST_METHOD_ATTRIBUTE() + TEST_METHOD(Fetch) { + auto result = m_runner.RunTest("IntegrationTests/FetchTest", "FetchTest"); + Assert::AreEqual(TestStatus::Passed, result.Status, result.Message.c_str()); + } + #pragma endregion Extended Tests }; diff --git a/vnext/Shared/OInstance.cpp b/vnext/Shared/OInstance.cpp index 5b8565cfc4e..589b3ca5c1a 100644 --- a/vnext/Shared/OInstance.cpp +++ b/vnext/Shared/OInstance.cpp @@ -554,17 +554,20 @@ std::vector> InstanceImpl::GetDefaultNativeModules }, nativeQueue)); - modules.push_back(std::make_unique( - m_innerInstance, - Microsoft::React::GetBlobModuleName(), - [transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); }, - nativeQueue)); + // Use in case the host app provides its a non-Blob-compatilbe HTTP module. + if (!Microsoft::React::GetRuntimeOptionBool("Blob.DisableModule")) { + modules.push_back(std::make_unique( + m_innerInstance, + Microsoft::React::GetBlobModuleName(), + [transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); }, + nativeQueue)); - modules.push_back(std::make_unique( - m_innerInstance, - Microsoft::React::GetFileReaderModuleName(), - [transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); }, - nativeQueue)); + modules.push_back(std::make_unique( + m_innerInstance, + Microsoft::React::GetFileReaderModuleName(), + [transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); }, + nativeQueue)); + } modules.push_back(std::make_unique( m_innerInstance, diff --git a/vnext/overrides.json b/vnext/overrides.json index 3948e71eef7..20cfdd2bb38 100644 --- a/vnext/overrides.json +++ b/vnext/overrides.json @@ -156,6 +156,10 @@ "type": "platform", "file": "src/IntegrationTests/DummyTest.js" }, + { + "type": "platform", + "file": "src/IntegrationTests/FetchTest.js" + }, { "type": "platform", "file": "src/IntegrationTests/LoggingTest.js" diff --git a/vnext/src/IntegrationTests/FetchTest.js b/vnext/src/IntegrationTests/FetchTest.js new file mode 100644 index 00000000000..79c666fa581 --- /dev/null +++ b/vnext/src/IntegrationTests/FetchTest.js @@ -0,0 +1,53 @@ +/** + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * @format + * @flow + */ + +'use strict'; + +const React = require('react'); +const ReactNative = require('react-native'); + +const {AppRegistry, View} = ReactNative; + +const {TestModule} = ReactNative.NativeModules; + +const uri = + 'https://raw.githubusercontent.com/microsoft/react-native-windows/main/.yarnrc.yml'; +const expectedContent = 'enableScripts: false'; + +type State = { + uri: string, + expected: string, + content: string, +}; + +class FetchTest extends React.Component<{...}, State> { + state: State = { + uri: 'https://raw.githubusercontent.com/microsoft/react-native-windows/main/.yarnrc.yml', + expected: 'enableScripts: false', + content: '', + }; + + async componentDidMount() { + const response = await fetch(uri); + const text = await response.text(); + this.setState({content: text}); + + if (this.state.content === expectedContent) { + TestModule.markTestPassed(true); + } else { + TestModule.markTestPassed(false); + } + } + + render(): React.Node { + return ; + } +} + +AppRegistry.registerComponent('FetchTest', () => FetchTest); + +module.exports = FetchTest;