File tree 3 files changed +51
-0
lines changed
3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " react-router " : patch
3
+ ---
4
+
5
+ Don't bundle ` react-router ` in ` react-router/dom ` CJS export
Original file line number Diff line number Diff line change
1
+ import * as React from "react" ;
2
+
3
+ import { render , screen } from "@testing-library/react" ;
4
+ import { createMemoryRouter , useParams } from "react-router" ;
5
+ import { RouterProvider } from "react-router/dom" ;
6
+
7
+ describe ( "react-router/dom" , ( ) => {
8
+ function ShowParams ( ) {
9
+ return < pre data-testid = "params" > { JSON . stringify ( useParams ( ) ) } </ pre > ;
10
+ }
11
+
12
+ describe ( "Does not bundle react-router causing duplicate context issues" , ( ) => {
13
+ it ( "with route provider shows the url params" , async ( ) => {
14
+ const router = createMemoryRouter (
15
+ [
16
+ {
17
+ path : "/blog/:slug" ,
18
+ element : < ShowParams /> ,
19
+ } ,
20
+ ] ,
21
+ {
22
+ initialEntries : [ "/blog/react-router" ] ,
23
+ }
24
+ ) ;
25
+
26
+ // When react-router was bundled in CJS scenarios, this `react-router/dom`
27
+ // version of `RouterProvider` caused duplicate contexts and we would not
28
+ // find the param values
29
+ render ( < RouterProvider router = { router } /> ) ;
30
+
31
+ expect ( await screen . findByTestId ( "params" ) ) . toMatchInlineSnapshot ( `
32
+ <pre
33
+ data-testid="params"
34
+ >
35
+ {"slug":"react-router"}
36
+ </pre>
37
+ ` ) ;
38
+ } ) ;
39
+ } ) ;
40
+ } ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ const config = (enableDevWarnings: boolean) =>
13
13
clean : false ,
14
14
entry,
15
15
format : [ "cjs" ] ,
16
+ // Don't bundle `react-router` in sub-exports (i.e., `react-router/dom`)
17
+ external : [ "react-router" ] ,
16
18
outDir : enableDevWarnings ? "dist/development" : "dist/production" ,
17
19
dts : true ,
18
20
banner : {
@@ -28,6 +30,10 @@ const config = (enableDevWarnings: boolean) =>
28
30
clean : false ,
29
31
entry,
30
32
format : [ "esm" ] ,
33
+ // We don't do the external thing for `react-router` here because it
34
+ // doesn't get bundled by default in the ESM build, and when we tried it
35
+ // in https://github.com/remix-run/react-router/pull/13497 it changed up
36
+ // some chunk creation that we didn't want to risk having any side effects
31
37
outDir : enableDevWarnings ? "dist/development" : "dist/production" ,
32
38
dts : true ,
33
39
banner : {
You can’t perform that action at this time.
0 commit comments