@@ -1004,6 +1004,91 @@ describe('ReactDOMServerHooks', () => {
1004
1004
) ;
1005
1005
} ) ;
1006
1006
1007
+ it ( 'useOpaqueIdentifier prefix works for server renderer and does not clash' , async ( ) => {
1008
+ function ChildTwo ( { id} ) {
1009
+ return < div id = { id } > Child Three</ div > ;
1010
+ }
1011
+ function App ( ) {
1012
+ const id = useOpaqueIdentifier ( ) ;
1013
+ const idTwo = useOpaqueIdentifier ( ) ;
1014
+
1015
+ return (
1016
+ < div >
1017
+ < div aria-labelledby = { id } > Chid One</ div >
1018
+ < ChildTwo id = { id } />
1019
+ < div aria-labelledby = { idTwo } > Child Three</ div >
1020
+ < div id = { idTwo } > Child Four</ div >
1021
+ </ div >
1022
+ ) ;
1023
+ }
1024
+
1025
+ const containerOne = document . createElement ( 'div' ) ;
1026
+ document . body . append ( containerOne ) ;
1027
+
1028
+ containerOne . innerHTML = ReactDOMServer . renderToString ( < App /> , {
1029
+ prefix : 'one' ,
1030
+ } ) ;
1031
+
1032
+ const containerTwo = document . createElement ( 'div' ) ;
1033
+ document . body . append ( containerTwo ) ;
1034
+
1035
+ containerTwo . innerHTML = ReactDOMServer . renderToString ( < App /> , {
1036
+ prefix : 'two' ,
1037
+ } ) ;
1038
+
1039
+ expect ( document . body . children . length ) . toEqual ( 2 ) ;
1040
+ const childOne = document . body . children [ 0 ] ;
1041
+ const childTwo = document . body . children [ 1 ] ;
1042
+
1043
+ expect (
1044
+ childOne . children [ 0 ] . children [ 0 ] . getAttribute ( 'aria-labelledby' ) ,
1045
+ ) . toEqual ( childOne . children [ 0 ] . children [ 1 ] . getAttribute ( 'id' ) ) ;
1046
+ expect (
1047
+ childOne . children [ 0 ] . children [ 2 ] . getAttribute ( 'aria-labelledby' ) ,
1048
+ ) . toEqual ( childOne . children [ 0 ] . children [ 3 ] . getAttribute ( 'id' ) ) ;
1049
+
1050
+ expect (
1051
+ childOne . children [ 0 ] . children [ 0 ] . getAttribute ( 'aria-labelledby' ) ,
1052
+ ) . not . toEqual (
1053
+ childOne . children [ 0 ] . children [ 2 ] . getAttribute ( 'aria-labelledby' ) ,
1054
+ ) ;
1055
+
1056
+ expect (
1057
+ childOne . children [ 0 ] . children [ 0 ]
1058
+ . getAttribute ( 'aria-labelledby' )
1059
+ . startsWith ( 'one' ) ,
1060
+ ) . toBe ( true ) ;
1061
+ expect (
1062
+ childOne . children [ 0 ] . children [ 2 ]
1063
+ . getAttribute ( 'aria-labelledby' )
1064
+ . includes ( 'one' ) ,
1065
+ ) . toBe ( true ) ;
1066
+
1067
+ expect (
1068
+ childTwo . children [ 0 ] . children [ 0 ] . getAttribute ( 'aria-labelledby' ) ,
1069
+ ) . toEqual ( childTwo . children [ 0 ] . children [ 1 ] . getAttribute ( 'id' ) ) ;
1070
+ expect (
1071
+ childTwo . children [ 0 ] . children [ 2 ] . getAttribute ( 'aria-labelledby' ) ,
1072
+ ) . toEqual ( childTwo . children [ 0 ] . children [ 3 ] . getAttribute ( 'id' ) ) ;
1073
+
1074
+ expect (
1075
+ childTwo . children [ 0 ] . children [ 0 ] . getAttribute ( 'aria-labelledby' ) ,
1076
+ ) . not . toEqual (
1077
+ childTwo . children [ 0 ] . children [ 2 ] . getAttribute ( 'aria-labelledby' ) ,
1078
+ ) ;
1079
+
1080
+ expect (
1081
+ childTwo . children [ 0 ] . children [ 0 ]
1082
+ . getAttribute ( 'aria-labelledby' )
1083
+ . startsWith ( 'two' ) ,
1084
+ ) . toBe ( true ) ;
1085
+ expect (
1086
+ childTwo . children [ 0 ] . children [ 2 ]
1087
+ . getAttribute ( 'aria-labelledby' )
1088
+ . startsWith ( 'two' ) ,
1089
+ ) . toBe ( true ) ;
1090
+ } ) ;
1091
+
1007
1092
it ( 'useOpaqueIdentifier: IDs match when, after hydration, a new component that uses the ID is rendered' , async ( ) => {
1008
1093
let _setShowDiv ;
1009
1094
function App ( ) {
0 commit comments