diff --git a/change/react-native-windows-ee3c2acb-502a-473c-9908-7cb9d170678f.json b/change/react-native-windows-ee3c2acb-502a-473c-9908-7cb9d170678f.json new file mode 100644 index 00000000000..fafb4c0e97c --- /dev/null +++ b/change/react-native-windows-ee3c2acb-502a-473c-9908-7cb9d170678f.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Allow disabling Blob Cxx module (#11979)", + "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 a4a0daed9e8..c18b97b2f38 100644 --- a/vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp +++ b/vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp @@ -231,5 +231,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 06ef3c90356..78383131d5b 100644 --- a/vnext/Shared/OInstance.cpp +++ b/vnext/Shared/OInstance.cpp @@ -570,17 +570,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 c2cc1b99742..d5fdf30e1c3 100644 --- a/vnext/overrides.json +++ b/vnext/overrides.json @@ -129,6 +129,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;