File tree Expand file tree Collapse file tree 3 files changed +68
-3
lines changed Expand file tree Collapse file tree 3 files changed +68
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @remix-run/router " : patch
3
+ ---
4
+
5
+ Fix error boundary tracking for multiple errors bubbling to the same boundary
Original file line number Diff line number Diff line change @@ -10774,6 +10774,61 @@ describe("a router", () => {
10774
10774
} ) ;
10775
10775
} ) ;
10776
10776
10777
+ it ( "should handle multiple errors at separate boundaries" , async ( ) => {
10778
+ let routes = [
10779
+ {
10780
+ id : "root" ,
10781
+ path : "/" ,
10782
+ loader : ( ) => Promise . reject ( "ROOT" ) ,
10783
+ hasErrorBoundary : true ,
10784
+ children : [
10785
+ {
10786
+ id : "child" ,
10787
+ path : "child" ,
10788
+ loader : ( ) => Promise . reject ( "CHILD" ) ,
10789
+ hasErrorBoundary : true ,
10790
+ } ,
10791
+ ] ,
10792
+ } ,
10793
+ ] ;
10794
+
10795
+ let { query } = createStaticHandler ( routes ) ;
10796
+ let context ;
10797
+
10798
+ context = await query ( createRequest ( "/child" ) ) ;
10799
+ expect ( context . errors ) . toEqual ( {
10800
+ root : "ROOT" ,
10801
+ child : "CHILD" ,
10802
+ } ) ;
10803
+ } ) ;
10804
+
10805
+ it ( "should handle multiple errors at the same boundary" , async ( ) => {
10806
+ let routes = [
10807
+ {
10808
+ id : "root" ,
10809
+ path : "/" ,
10810
+ loader : ( ) => Promise . reject ( "ROOT" ) ,
10811
+ hasErrorBoundary : true ,
10812
+ children : [
10813
+ {
10814
+ id : "child" ,
10815
+ path : "child" ,
10816
+ loader : ( ) => Promise . reject ( "CHILD" ) ,
10817
+ } ,
10818
+ ] ,
10819
+ } ,
10820
+ ] ;
10821
+
10822
+ let { query } = createStaticHandler ( routes ) ;
10823
+ let context ;
10824
+
10825
+ context = await query ( createRequest ( "/child" ) ) ;
10826
+ expect ( context . errors ) . toEqual ( {
10827
+ // higher error value wins
10828
+ root : "ROOT" ,
10829
+ } ) ;
10830
+ } ) ;
10831
+
10777
10832
it ( "should handle aborted load requests" , async ( ) => {
10778
10833
let dfd = createDeferred ( ) ;
10779
10834
let controller = new AbortController ( ) ;
Original file line number Diff line number Diff line change @@ -2848,9 +2848,14 @@ function processRouteLoaderData(
2848
2848
error = Object . values ( pendingError ) [ 0 ] ;
2849
2849
pendingError = undefined ;
2850
2850
}
2851
- errors = Object . assign ( errors || { } , {
2852
- [ boundaryMatch . route . id ] : error ,
2853
- } ) ;
2851
+
2852
+ errors = errors || { } ;
2853
+
2854
+ // Prefer higher error values if lower errors bubble to the same boundary
2855
+ if ( errors [ boundaryMatch . route . id ] == null ) {
2856
+ errors [ boundaryMatch . route . id ] = error ;
2857
+ }
2858
+
2854
2859
// Once we find our first (highest) error, we set the status code and
2855
2860
// prevent deeper status codes from overriding
2856
2861
if ( ! foundError ) {
You can’t perform that action at this time.
0 commit comments