Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix crash when image loading fails due to network error",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"fast-glob": "^3.2.11",
"husky": "^4.2.5",
"prettier-plugin-hermes-parser": "0.21.1",
"react-native-platform-override": "0.0.0-canary.1015",
"react-native-platform-override": "0.0.0-canary.1016",
"unbroken": "1.0.27",
"lage": "^2.7.1",
"lodash": "^4.17.15"
Expand Down
1 change: 1 addition & 0 deletions packages/@rnw-scripts/promote-release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@react-native-windows/package-utils": "^0.0.0-canary.96",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"minimatch": "^10.0.3",
"chalk": "^4.1.0",
"simple-git": "^3.3.0",
"source-map-support": "^0.5.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,11 @@ ImageResponseOrImageErrorInfo ImageFailedResponse::ResolveImage() {
if (imageOrError.errorInfo->error.empty()) {
imageOrError.errorInfo->error = "Failed to load image.";
}
for (auto &&[header, value] : m_responseHeaders) {
imageOrError.errorInfo->httpResponseHeaders.push_back(
std::make_pair<std::string, std::string>(winrt::to_string(header), winrt::to_string(value)));
if (m_responseHeaders) {
for (auto &&[header, value] : m_responseHeaders) {
imageOrError.errorInfo->httpResponseHeaders.push_back(
std::make_pair<std::string, std::string>(winrt::to_string(header), winrt::to_string(value)));
}
}
return imageOrError;
}
Expand Down
15 changes: 14 additions & 1 deletion vnext/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Fabric/Composition/ImageResponseImage.h>
#include <Fabric/Composition/UriImageManager.h>
#include <Networking/NetworkPropertyIds.h>
#include <Utils/CppWinrtLessExceptions.h>
#include <Utils/ImageUtils.h>
#include <fmt/format.h>
#include <functional/functor.h>
Expand Down Expand Up @@ -131,7 +132,19 @@ WindowsImageManager::GetImageRandomAccessStreamAsync(
request.Content(bodyContent);
}

winrt::Windows::Web::Http::HttpResponseMessage response(co_await m_httpClient.SendRequestAsync(request));
auto asyncOp = m_httpClient.SendRequestAsync(request);
co_await lessthrow_await_adapter<winrt::Windows::Foundation::IAsyncOperationWithProgress<
winrt::Windows::Web::Http::HttpResponseMessage,
winrt::Windows::Web::Http::HttpProgress>>{asyncOp};

if (asyncOp.Status() == winrt::Windows::Foundation::AsyncStatus::Error ||
asyncOp.Status() == winrt::Windows::Foundation::AsyncStatus::Canceled) {
auto errorMessage = FormatHResultError(winrt::hresult_error(asyncOp.ErrorCode()));
co_return winrt::Microsoft::ReactNative::Composition::ImageFailedResponse(
winrt::to_hstring("Network request failed: " + errorMessage));
}

winrt::Windows::Web::Http::HttpResponseMessage response = asyncOp.GetResults();

if (!response.IsSuccessStatusCode()) {
co_return winrt::Microsoft::ReactNative::Composition::ImageFailedResponse(
Expand Down
Loading
Loading