Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsc: clean client buffer cache after flushed #34475

Merged
merged 5 commits into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next/client/index.tsx
Expand Up @@ -702,6 +702,7 @@ if (process.env.__NEXT_RSC) {
writer.write(encoder.encode(val))
})
buffer.length = 0
serverDataBuffer.delete(key)
}
serverDataWriter.set(key, writer)
}
Expand Down
@@ -1,4 +1,5 @@
import Foo from '../components/foo.client'
import Link from 'next/link'

const envVar = process.env.ENV_VAR_TEST
const headerKey = 'x-next-test-client'
Expand All @@ -13,6 +14,9 @@ export default function Index({ header, router }) {
<div>
<Foo />
</div>
<Link href={'/'}>
<a id="refresh">refresh</a>
</Link>
</div>
)
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ export default function (context, { runtime, env }) {
page.on('request', (request) => {
requestsCount++
const url = request.url()
if (/__flight__=1/.test(url)) {
if (/\?__flight__=1/.test(url)) {
hasFlightRequest = true
}
})
Expand Down Expand Up @@ -95,9 +95,39 @@ export default function (context, { runtime, env }) {
})
}

// For prod build, the directory contains the build ID so it's not deterministic.
// Only enable it for dev for now.
it('should refresh correctly with next/link', async () => {
// Select the button which is not hidden but rendered
const selector = '#__next #refresh'
let hasFlightRequest = false
const browser = await webdriver(context.appPort, '/', {
beforePageLoad(page) {
page.on('request', (request) => {
const url = request.url()
if (/\?__flight__=1/.test(url)) {
hasFlightRequest = true
}
})
},
})

// wait for hydration
await new Promise((res) => setTimeout(res, 1000))
if (env === 'dev') {
expect(hasFlightRequest).toBe(false)
}
await browser.elementByCss(selector).click()
// wait for re-hydration
await new Promise((res) => setTimeout(res, 1000))
if (env === 'dev') {
expect(hasFlightRequest).toBe(true)
}
const refreshText = await browser.elementByCss(selector).text()
expect(refreshText).toBe('refresh')
})

if (env === 'dev') {
// For prod build, the directory contains the build ID so it's not deterministic.
// Only enable it for dev for now.
it('should not bundle external imports into client builds for RSC', async () => {
const html = await renderViaHTTP(context.appPort, '/external-imports')
expect(html).toContain('date:')
Expand Down