From 7c482ea1b0a0556ae959f64495285794a1290822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar=20Rocha?= Date: Fri, 4 Aug 2023 15:33:53 -0700 Subject: [PATCH 1/3] Allow disabling Blob Cxx module (#11979) * Define FetchTest * Implement fetch test * Allow disabling Blob Cxx module * Change files * Format FetchTest.js * yarn lint --- ...-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json | 7 +++ .../RNTesterIntegrationTests.cpp | 7 +++ vnext/Shared/OInstance.cpp | 23 ++++---- vnext/overrides.json | 4 ++ vnext/src/IntegrationTests/FetchTest.js | 53 +++++++++++++++++++ 5 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json create mode 100644 vnext/src/IntegrationTests/FetchTest.js 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 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; From 54f323f10f25ee54764eba6349852a70994abbbf Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Fri, 4 Aug 2023 15:39:58 -0700 Subject: [PATCH 2/3] Remove change files --- ...ative-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json diff --git a/change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json b/change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json deleted file mode 100644 index 741668071df..00000000000 --- a/change/react-native-windows-8d9e88e3-ce8b-46b7-a11e-af04d9f3d59d.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "prerelease", - "comment": "Allow disabling Blob Cxx module", - "packageName": "react-native-windows", - "email": "julio.rocha@microsoft.com", - "dependentChangeType": "patch" -} From 1194c940ea65289c42581fe012c285caf54c3a80 Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Fri, 4 Aug 2023 15:43:41 -0700 Subject: [PATCH 3/3] Change files --- ...ative-windows-ee3c2acb-502a-473c-9908-7cb9d170678f.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-ee3c2acb-502a-473c-9908-7cb9d170678f.json 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" +}