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