forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing end-to-end test for an action that returns client components
This playwright test is using the Flight Fixture to demonstrate the Flight Reply equivalent of the scenario that was fixed in facebook#30528 for the Flight Client. It's basically an advanced case of what was outlined in facebook#28564, returning a client component from a server action that is used in `useActionState`. In addition, the client component uses another element twice, which leads to the element's props being deduped. Resolving those references needs to be handled specifically, both in the Flight Client (done in facebook#30528), as well as in the temporary references of the Flight Reply Client (and possibly Flight Reply Server?). The test should probably be converted into a unit test, e.g. in `packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js` or `packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js`.
- Loading branch information
1 parent
2b00018
commit da386d7
Showing
7 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @ts-check | ||
|
||
import {test, expect} from '@playwright/test'; | ||
|
||
test('action returning client component with deduped references', async ({ | ||
page, | ||
}) => { | ||
const pageErrors = []; | ||
|
||
page.on('pageerror', error => { | ||
pageErrors.push(error.stack); | ||
}); | ||
|
||
await page.goto('/'); | ||
|
||
const button = await page.getByRole('button', { | ||
name: 'Return element from action', | ||
}); | ||
|
||
await button.click(); | ||
|
||
await expect( | ||
page.getByTestId('temporary-references-action-result') | ||
).toHaveText('Hello'); | ||
|
||
// Click the button one more time to send the previous result (i.e. the | ||
// returned element) back to the server. | ||
await button.click(); | ||
|
||
await expect(pageErrors).toEqual([]); | ||
|
||
await expect( | ||
page.getByTestId('temporary-references-action-result') | ||
).toHaveText('HelloHello'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
|
||
export default function Deduped({children, thing}) { | ||
console.log({thing}); | ||
return <div>{children}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
|
||
export function TemporaryReferences({action}) { | ||
const [result, formAction] = React.useActionState(action, null); | ||
|
||
return ( | ||
<form action={formAction}> | ||
<button>Return element from action</button> | ||
<div data-testid="temporary-references-action-result">{result}</div> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters