You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
There is an issue with the relatedProductsLoader function where it uses Promise.all to fetch related products. If any individual call within the Promise.all fails (e.g., due to an API error or network issue), the entire Promise.all rejects. This causes the loader to fail and propagate the error up the call stack, potentially leading to unhandled promise rejections and application instability.
Steps to Reproduce (for bugs)
Use the relatedProductsLoader in an application to fetch related products.
Simulate a failure in one of the batched calls to productList (e.g., by causing an API endpoint to return an error or by interrupting the network connection).
Observe that the Promise.all in the loader rejects due to the failure in one of the promises.
Notice that the loader does not handle the error internally, and the error propagates to the calling function.
Expected Behavior
The relatedProductsLoader should handle errors internally to ensure that a failure in one of the batched productList calls does not cause the entire loader to fail. Instead, it should:
Use Promise.allSettled to wait for all promises to complete, regardless of individual failures.
Collect and return the successful results.
Handle or log the errors from failed promises appropriately.
Ensure that the loader's return type remains consistent (Product[] | null), even when some calls fail.
Actual Behavior
The loader uses Promise.all, which rejects if any promise rejects.
A failure in any productList call causes the entire loader to reject.
Errors are not handled within the loader, leading to potential unhandled promise rejections.
The calling code may receive unexpected errors or null values, disrupting the application flow.
Additional Context
This issue affects the robustness and resilience of applications using the relatedProductsLoader.
Modifying the loader to use Promise.allSettled and handling the results can resolve the problem.
Issue Type
Bug
Bug Report
Description
There is an issue with the relatedProductsLoader function where it uses Promise.all to fetch related products. If any individual call within the Promise.all fails (e.g., due to an API error or network issue), the entire Promise.all rejects. This causes the loader to fail and propagate the error up the call stack, potentially leading to unhandled promise rejections and application instability.
Steps to Reproduce (for bugs)
Use the relatedProductsLoader in an application to fetch related products.
Simulate a failure in one of the batched calls to productList (e.g., by causing an API endpoint to return an error or by interrupting the network connection).
Observe that the Promise.all in the loader rejects due to the failure in one of the promises.
Notice that the loader does not handle the error internally, and the error propagates to the calling function.
Expected Behavior
The relatedProductsLoader should handle errors internally to ensure that a failure in one of the batched productList calls does not cause the entire loader to fail. Instead, it should:
Actual Behavior
Additional Context
This issue affects the robustness and resilience of applications using the relatedProductsLoader.
Modifying the loader to use Promise.allSettled and handling the results can resolve the problem.
Example modification:
By handling errors internally, the loader becomes more stable and prevents failures from propagating unnecessarily.
The text was updated successfully, but these errors were encountered: