@@ -783,6 +783,116 @@ describe('ReactDOMResources', () => {
783
783
) ;
784
784
} ) ;
785
785
786
+ it ( 'treats resource eligible elements with data-* attributes as components instead of resources' , async ( ) => {
787
+ await actIntoEmptyDocument ( async ( ) => {
788
+ const { pipe} = ReactDOMFizzServer . renderToPipeableStream (
789
+ < html >
790
+ < head >
791
+ < link rel = "stylesheet" href = "foo" />
792
+ < link rel = "stylesheet" href = "foo" crossOrigin = "" />
793
+ < link rel = "stylesheet" href = "foo" crossOrigin = "use-credentials" />
794
+ </ head >
795
+ < body >
796
+ < link rel = "stylesheet" href = "foo" crossOrigin = "" data-foo = "" />
797
+ < link rel = "stylesheet" href = "foo" crossOrigin = "" data-foo = "" />
798
+ < div > hello world</ div >
799
+ </ body >
800
+ </ html > ,
801
+ ) ;
802
+ pipe ( writable ) ;
803
+ } ) ;
804
+ // data attribute links get their own individual representation in the stream because they are treated
805
+ // like regular HostComponents
806
+ expect ( getVisibleChildren ( document ) ) . toEqual (
807
+ < html >
808
+ < head >
809
+ < link rel = "stylesheet" href = "foo" />
810
+ < link rel = "stylesheet" href = "foo" crossorigin = "" />
811
+ < link rel = "stylesheet" href = "foo" crossorigin = "use-credentials" />
812
+ </ head >
813
+ < body >
814
+ < link rel = "stylesheet" href = "foo" crossorigin = "" data-foo = "" />
815
+ < link rel = "stylesheet" href = "foo" crossorigin = "" data-foo = "" />
816
+ < div > hello world</ div >
817
+ </ body >
818
+ </ html > ,
819
+ ) ;
820
+
821
+ const root = ReactDOMClient . hydrateRoot (
822
+ container ,
823
+ < html >
824
+ < head >
825
+ < link rel = "stylesheet" href = "foo" />
826
+ < link rel = "stylesheet" href = "foo" crossOrigin = "" />
827
+ < link rel = "stylesheet" href = "foo" crossOrigin = "use-credentials" />
828
+ </ head >
829
+ < body >
830
+ < link rel = "stylesheet" href = "foo" crossOrigin = "" data-foo = "" />
831
+ < link rel = "stylesheet" href = "foo" crossOrigin = "" data-foo = "" />
832
+ < div > hello world</ div >
833
+ </ body >
834
+ </ html > ,
835
+ ) ;
836
+ expect ( Scheduler ) . toFlushWithoutYielding ( ) ;
837
+ expect ( getVisibleChildren ( document ) ) . toEqual (
838
+ < html >
839
+ < head >
840
+ < link rel = "stylesheet" href = "foo" />
841
+ < link rel = "stylesheet" href = "foo" crossorigin = "" />
842
+ < link rel = "stylesheet" href = "foo" crossorigin = "use-credentials" />
843
+ </ head >
844
+ < body >
845
+ < link rel = "stylesheet" href = "foo" crossorigin = "" data-foo = "" />
846
+ < link rel = "stylesheet" href = "foo" crossorigin = "" data-foo = "" />
847
+ < div > hello world</ div >
848
+ </ body >
849
+ </ html > ,
850
+ ) ;
851
+
852
+ // Drop the foo crossorigin anonymous HostResource that might match if we weren't useing data attributes
853
+ // It is actually removed from the head because the body representation is a HostComponent and completely
854
+ // disconnected from the Resource runtime.
855
+ root . render (
856
+ < html >
857
+ < head >
858
+ < link rel = "stylesheet" href = "foo" />
859
+ < link rel = "stylesheet" href = "foo" crossOrigin = "use-credentials" />
860
+ </ head >
861
+ < body >
862
+ < link
863
+ rel = "stylesheet"
864
+ href = "foo"
865
+ crossOrigin = ""
866
+ data-bar = "baz"
867
+ data-foo = ""
868
+ />
869
+ < link rel = "stylesheet" href = "foo" crossOrigin = "" data-foo = "" />
870
+ < div > hello world</ div >
871
+ </ body >
872
+ </ html > ,
873
+ ) ;
874
+ expect ( Scheduler ) . toFlushWithoutYielding ( ) ;
875
+ expect ( getVisibleChildren ( document ) ) . toEqual (
876
+ < html >
877
+ < head >
878
+ < link rel = "stylesheet" href = "foo" />
879
+ < link rel = "stylesheet" href = "foo" crossorigin = "use-credentials" />
880
+ </ head >
881
+ < body >
882
+ < link
883
+ rel = "stylesheet"
884
+ href = "foo"
885
+ crossorigin = ""
886
+ data-bar = "baz"
887
+ data-foo = ""
888
+ />
889
+ < link rel = "stylesheet" href = "foo" crossorigin = "" data-foo = "" />
890
+ < div > hello world</ div >
891
+ </ body >
892
+ </ html > ,
893
+ ) ;
894
+ } ) ;
895
+
786
896
describe ( 'link resources' , ( ) => {
787
897
// @gate enableFloat
788
898
it ( 'keys resources on href, crossOrigin, and referrerPolicy' , async ( ) => {
0 commit comments