@@ -6,6 +6,7 @@ import * as React from "react";
6
6
import * as ReactDOMServer from "react-dom/server" ;
7
7
import { json } from "@remix-run/router" ;
8
8
import {
9
+ Form ,
9
10
Link ,
10
11
Outlet ,
11
12
useLoaderData ,
@@ -511,6 +512,123 @@ describe("A <StaticRouterProvider>", () => {
511
512
) ;
512
513
} ) ;
513
514
515
+ it ( "encodes auto-generated <a href> values to avoid hydration errors" , async ( ) => {
516
+ let routes = [ { path : "/path/:param" , element : < Link to = "." > 👋</ Link > } ] ;
517
+ let { query } = createStaticHandler ( routes ) ;
518
+
519
+ let context = ( await query (
520
+ new Request ( "http://localhost/path/with space" , {
521
+ signal : new AbortController ( ) . signal ,
522
+ } )
523
+ ) ) as StaticHandlerContext ;
524
+
525
+ let html = ReactDOMServer . renderToStaticMarkup (
526
+ < React . StrictMode >
527
+ < StaticRouterProvider
528
+ router = { createStaticRouter ( routes , context ) }
529
+ context = { context }
530
+ />
531
+ </ React . StrictMode >
532
+ ) ;
533
+ expect ( html ) . toContain ( '<a href="/path/with%20space">👋</a>' ) ;
534
+ } ) ;
535
+
536
+ it ( "does not encode user-specified <a href> values" , async ( ) => {
537
+ let routes = [
538
+ { path : "/" , element : < Link to = "/path/with space" > 👋</ Link > } ,
539
+ ] ;
540
+ let { query } = createStaticHandler ( routes ) ;
541
+
542
+ let context = ( await query (
543
+ new Request ( "http://localhost/" , {
544
+ signal : new AbortController ( ) . signal ,
545
+ } )
546
+ ) ) as StaticHandlerContext ;
547
+
548
+ let html = ReactDOMServer . renderToStaticMarkup (
549
+ < React . StrictMode >
550
+ < StaticRouterProvider
551
+ router = { createStaticRouter ( routes , context ) }
552
+ context = { context }
553
+ />
554
+ </ React . StrictMode >
555
+ ) ;
556
+ expect ( html ) . toContain ( '<a href="/path/with space">👋</a>' ) ;
557
+ } ) ;
558
+
559
+ it ( "encodes auto-generated <form action> values to avoid hydration errors (action=undefined)" , async ( ) => {
560
+ let routes = [ { path : "/path/:param" , element : < Form > 👋</ Form > } ] ;
561
+ let { query } = createStaticHandler ( routes ) ;
562
+
563
+ let context = ( await query (
564
+ new Request ( "http://localhost/path/with space" , {
565
+ signal : new AbortController ( ) . signal ,
566
+ } )
567
+ ) ) as StaticHandlerContext ;
568
+
569
+ let html = ReactDOMServer . renderToStaticMarkup (
570
+ < React . StrictMode >
571
+ < StaticRouterProvider
572
+ router = { createStaticRouter ( routes , context ) }
573
+ context = { context }
574
+ />
575
+ </ React . StrictMode >
576
+ ) ;
577
+ expect ( html ) . toContain (
578
+ '<form method="get" action="/path/with%20space">👋</form>'
579
+ ) ;
580
+ } ) ;
581
+
582
+ it ( 'encodes auto-generated <form action> values to avoid hydration errors (action=".")' , async ( ) => {
583
+ let routes = [
584
+ { path : "/path/:param" , element : < Form action = "." > 👋</ Form > } ,
585
+ ] ;
586
+ let { query } = createStaticHandler ( routes ) ;
587
+
588
+ let context = ( await query (
589
+ new Request ( "http://localhost/path/with space" , {
590
+ signal : new AbortController ( ) . signal ,
591
+ } )
592
+ ) ) as StaticHandlerContext ;
593
+
594
+ let html = ReactDOMServer . renderToStaticMarkup (
595
+ < React . StrictMode >
596
+ < StaticRouterProvider
597
+ router = { createStaticRouter ( routes , context ) }
598
+ context = { context }
599
+ />
600
+ </ React . StrictMode >
601
+ ) ;
602
+ expect ( html ) . toContain (
603
+ '<form method="get" action="/path/with%20space">👋</form>'
604
+ ) ;
605
+ } ) ;
606
+
607
+ it ( "does not encode user-specified <form action> values" , async ( ) => {
608
+ let routes = [
609
+ { path : "/" , element : < Form action = "/path/with space" > 👋</ Form > } ,
610
+ ] ;
611
+ let { query } = createStaticHandler ( routes ) ;
612
+
613
+ let context = ( await query (
614
+ new Request ( "http://localhost/" , {
615
+ signal : new AbortController ( ) . signal ,
616
+ } )
617
+ ) ) as StaticHandlerContext ;
618
+
619
+ let html = ReactDOMServer . renderToStaticMarkup (
620
+ < React . StrictMode >
621
+ < StaticRouterProvider
622
+ router = { createStaticRouter ( routes , context ) }
623
+ context = { context }
624
+ />
625
+ </ React . StrictMode >
626
+ ) ;
627
+ expect ( html ) . toContain (
628
+ '<form method="get" action="/path/with space">👋</form>'
629
+ ) ;
630
+ } ) ;
631
+
514
632
it ( "serializes ErrorResponse instances" , async ( ) => {
515
633
let routes = [
516
634
{
0 commit comments