@@ -464,6 +464,67 @@ implementations.forEach((implementation) => {
464
464
465
465
test . describe ( "Server Actions" , ( ) => {
466
466
test ( "Supports React Server Functions" , async ( { page } ) => {
467
+ let port = await getPort ( ) ;
468
+ stop = await setupRscTest ( {
469
+ implementation,
470
+ port,
471
+ files : {
472
+ "src/routes/home.actions.ts" : js `
473
+ "use server";
474
+
475
+ export function incrementCounter(count: number, formData: FormData) {
476
+ return count + parseInt(formData.get("by") as string || "1", 10);
477
+ }
478
+ ` ,
479
+ "src/routes/home.tsx" : js `
480
+ "use client";
481
+
482
+ import { useActionState } from "react";
483
+
484
+ import { incrementCounter } from "./home.actions";
485
+
486
+ export default function ClientComponent() {
487
+ const [count, incrementCounterAction, incrementing] = useActionState(incrementCounter, 0);
488
+
489
+ return (
490
+ <div>
491
+ <h2 data-home>Home: ({count})</h2>
492
+ <form action={incrementCounterAction}>
493
+ <input type="hidden" name="name" value="Updated" />
494
+ <button type="submit" data-submit>
495
+ {incrementing ? "Updating via Server Function" : "Update via Server Function"}
496
+ </button>
497
+ </form>
498
+ </div>
499
+ );
500
+ }
501
+ ` ,
502
+ } ,
503
+ } ) ;
504
+
505
+ await page . goto ( `http://localhost:${ port } /` ) ;
506
+
507
+ // Verify initial server render
508
+ await page . waitForSelector ( "[data-home]" ) ;
509
+ expect ( await page . locator ( "[data-home]" ) . textContent ( ) ) . toBe (
510
+ "Home: (0)"
511
+ ) ;
512
+
513
+ // Submit the form to trigger server function
514
+ await page . click ( "[data-submit]" ) ;
515
+
516
+ // Verify server function updated the UI
517
+ await expect ( page . locator ( "[data-home]" ) ) . toHaveText ( "Home: (1)" ) ;
518
+
519
+ // Submit again to ensure server functions work repeatedly
520
+ await page . click ( "[data-submit]" ) ;
521
+ await expect ( page . locator ( "[data-home]" ) ) . toHaveText ( "Home: (2)" ) ;
522
+
523
+ // Ensure this is using RSC
524
+ validateRSCHtml ( await page . content ( ) ) ;
525
+ } ) ;
526
+
527
+ test ( "Supports Inline React Server Functions" , async ( { page } ) => {
467
528
// FIXME: Waiting on parcel support: https://github.com/parcel-bundler/parcel/pull/10165
468
529
test . skip (
469
530
implementation . name === "parcel" ,
0 commit comments