Skip to content

Commit

Permalink
only reset ASYNC_CLIENT_MODULES for each compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 26, 2022
1 parent 13ea3b8 commit eef6fb7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
Expand Up @@ -64,7 +64,11 @@ export class FlightClientEntryPlugin {
})

compiler.hooks.afterCompile.tap(PLUGIN_NAME, (compilation) => {
ASYNC_CLIENT_MODULES.clear()
if (!this.isEdgeServer) {
// Reset only in server compiler for each round of compilation,
// then it's still preserved for edge compiler
ASYNC_CLIENT_MODULES.clear()
}
traverseModules(compilation, (mod) => {
// The module must has request, and resource so it's not a new entry created with loader.
// Using the client layer module, which doesn't have `rsc` tag in buildInfo.
Expand Down
37 changes: 16 additions & 21 deletions test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -132,26 +132,6 @@ describe('app dir - react server components', () => {
expect(html).toContain('foo.client')
})

it('should resolve different kinds of components correctly', async () => {
const html = await renderViaHTTP(next.url, '/shared')
const main = getNodeBySelector(html, '#main').html()

// Should have 5 occurrences of "client_component".
expect(Array.from(main.matchAll(/client_component/g)).length).toBe(5)

// Should have 2 occurrences of "shared:server", and 2 occurrences of
// "shared:client".
const sharedServerModule = Array.from(main.matchAll(/shared:server:(\d+)/g))
const sharedClientModule = Array.from(main.matchAll(/shared:client:(\d+)/g))
expect(sharedServerModule.length).toBe(2)
expect(sharedClientModule.length).toBe(2)

// Should have 2 modules created for the shared component.
expect(sharedServerModule[0][1]).toBe(sharedServerModule[1][1])
expect(sharedClientModule[0][1]).toBe(sharedClientModule[1][1])
expect(sharedServerModule[0][1]).not.toBe(sharedClientModule[0][1])
})

it('should be able to navigate between rsc routes', async () => {
const browser = await webdriver(next.url, '/root')

Expand Down Expand Up @@ -302,10 +282,25 @@ describe('app dir - react server components', () => {
expect(content).toContain('foo.client')
})

it('should support the re-export syntax in server component', async () => {
it('should resolve different kinds of components correctly', async () => {
const html = await renderViaHTTP(next.url, '/shared')
const main = getNodeBySelector(html, '#main').html()
const content = getNodeBySelector(html, '#bar').text()

// Should have 5 occurrences of "client_component".
expect(Array.from(main.matchAll(/client_component/g)).length).toBe(5)

// Should have 2 occurrences of "shared:server", and 2 occurrences of
// "shared:client".
const sharedServerModule = Array.from(main.matchAll(/shared:server:(\d+)/g))
const sharedClientModule = Array.from(main.matchAll(/shared:client:(\d+)/g))
expect(sharedServerModule.length).toBe(2)
expect(sharedClientModule.length).toBe(2)

// Should have 2 modules created for the shared component.
expect(sharedServerModule[0][1]).toBe(sharedServerModule[1][1])
expect(sharedClientModule[0][1]).toBe(sharedClientModule[1][1])
expect(sharedServerModule[0][1]).not.toBe(sharedClientModule[0][1])
expect(content).toContain('bar.server.js:')
})

Expand Down
1 change: 0 additions & 1 deletion test/e2e/app-dir/rsc-basic/app/shared/page.js
Expand Up @@ -14,7 +14,6 @@ export default function Page() {
<div id="main" suppressHydrationWarning>
<Random />
<br />
<br />
<ClientFromDirect />
<br />
<ClientFromShared />
Expand Down

0 comments on commit eef6fb7

Please sign in to comment.