Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flight loader for shared components (#34692)
* fix flight loader for shared components * add tests * fix condition
- Loading branch information
Showing
10 changed files
with
176 additions
and
62 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
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
7 changes: 7 additions & 0 deletions
7
test/integration/react-streaming-and-server-components/app/components/client.client.js
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,7 @@ | ||
import { useState } from 'react' | ||
|
||
export default function Client() { | ||
// To ensure that this component is rendered as a client component, we use a | ||
// state here. | ||
return useState('client_component')[0] | ||
} |
3 changes: 3 additions & 0 deletions
3
test/integration/react-streaming-and-server-components/app/components/shared.client.js
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,3 @@ | ||
import Shared from './shared' | ||
|
||
export default Shared |
21 changes: 21 additions & 0 deletions
21
test/integration/react-streaming-and-server-components/app/components/shared.js
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,21 @@ | ||
import { useState } from 'react' | ||
import Client from './client.client' | ||
|
||
const random = ~~(Math.random() * 10000) | ||
|
||
export default function Shared() { | ||
let isServerComponent | ||
try { | ||
useState() | ||
isServerComponent = false | ||
} catch (e) { | ||
isServerComponent = true | ||
} | ||
|
||
return ( | ||
<> | ||
<Client />,{' '} | ||
{(isServerComponent ? 'shared:server' : 'shared:client') + ':' + random} | ||
</> | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
test/integration/react-streaming-and-server-components/app/pages/shared.server.js
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,22 @@ | ||
import ClientFromDirect from '../components/client.client' | ||
import ClientFromShared from '../components/shared' | ||
import SharedFromClient from '../components/shared.client' | ||
|
||
export default function Page() { | ||
// All three client components should be rendered correctly, but only | ||
// shared component is a server component, and another is a client component. | ||
// These two shared components should be created as two module instances. | ||
return ( | ||
<div id="main"> | ||
<ClientFromDirect /> | ||
<br /> | ||
<ClientFromShared /> | ||
<br /> | ||
<ClientFromShared /> | ||
<br /> | ||
<SharedFromClient /> | ||
<br /> | ||
<SharedFromClient /> | ||
</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
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