Unverified Commit a37a86ac authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

tests: Improve use-cache-cross-deployment tests (#98049)

Followup to #95233

- unskip one client component test since that is actually expected
behavior already, we just need to test the observable behavior instead
- Fix instant insights warnings
- Don't use console.log since that errors when trying to print server
references
parent 2fe6f962
globalThis.noop = () => {}
export async function getData(action) { export async function getData(action) {
'use cache: remote' 'use cache: remote'
console.log(action) // Pretend to use it
globalThis.noop(action)
return Math.random() return Math.random()
} }
...@@ -2,6 +2,8 @@ import { connection } from 'next/server' ...@@ -2,6 +2,8 @@ import { connection } from 'next/server'
import { action } from './action' import { action } from './action'
import { getData } from './get-data' import { getData } from './get-data'
export const instant = false
export default async function Page() { export default async function Page() {
await connection() await connection()
......
'use client' 'use client'
export function client() { import { useState } from 'react'
return 'first'
export function Client() {
const [text, setText] = useState('')
return (
<div>
<div id="title">Client Component A</div>
<button
onClick={() => {
setText('Button clicked')
}}
>
Click me
</button>
<span id="state">{text}</span>
</div>
)
} }
export async function getData(client) {
'use cache: remote'
console.log(client)
return Math.random()
}
export async function getData(Client) {
'use cache: remote'
return (
<div>
<span id="data">{Math.random()}</span>
<Client />
</div>
)
}
import { connection } from 'next/server' import { connection } from 'next/server'
import { client } from './client' import { Client } from './client'
import { getData } from './get-data' import { getData } from './get-data'
export const instant = false
export default async function Page() { export default async function Page() {
await connection() await connection()
return <span id="data">{await getData(client)}</span> return <div>{await getData(Client)}</div>
} }
globalThis.noop = () => {}
export async function getData(action) { export async function getData(action) {
'use cache: remote' 'use cache: remote'
console.log(action) // Pretend to use it
globalThis.noop(action)
return Math.random() return Math.random()
} }
...@@ -2,6 +2,8 @@ import { connection } from 'next/server' ...@@ -2,6 +2,8 @@ import { connection } from 'next/server'
import { action } from './action' import { action } from './action'
import { getData } from './get-data' import { getData } from './get-data'
export const instant = false
export default async function Page() { export default async function Page() {
await connection() await connection()
......
...@@ -10,6 +10,8 @@ async function DynamicCache({ id }: { id: string }) { ...@@ -10,6 +10,8 @@ async function DynamicCache({ id }: { id: string }) {
return <Client>{getDate()}</Client> return <Client>{getDate()}</Client>
} }
export const instant = false
export default async function Page() { export default async function Page() {
await connection() await connection()
......
...@@ -13,6 +13,8 @@ async function getOuterData() { ...@@ -13,6 +13,8 @@ async function getOuterData() {
return getInnerData() return getInnerData()
} }
export const instant = false
export default async function Page() { export default async function Page() {
await connection() await connection()
......
...@@ -14,6 +14,8 @@ async function AsyncComp() { ...@@ -14,6 +14,8 @@ async function AsyncComp() {
return <span id="data">{data}</span> return <span id="data">{data}</span>
} }
export const instant = false
export default async function Home() { export default async function Home() {
await connection() await connection()
......
...@@ -8,6 +8,8 @@ async function DynamicCache({ id }: { id: string }) { ...@@ -8,6 +8,8 @@ async function DynamicCache({ id }: { id: string }) {
return <span id="data">{getDate()}</span> return <span id="data">{getDate()}</span>
} }
export const instant = false
export default function Page() { export default function Page() {
return ( return (
<main> <main>
......
...@@ -241,6 +241,7 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'BUILD_ID', 'default'])( ...@@ -241,6 +241,7 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'BUILD_ID', 'default'])(
// TODO when serializing server reference arguments, we need to include the server reference's // TODO when serializing server reference arguments, we need to include the server reference's
// entropy in the argument-part of the cache key. // entropy in the argument-part of the cache key.
// But currently, you cannot do anything with the passed server reference anyway.
it.skip('should recompute when a use cache reference argument changes', async () => { it.skip('should recompute when a use cache reference argument changes', async () => {
const key1 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-1') const key1 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-1')
...@@ -258,7 +259,8 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'BUILD_ID', 'default'])( ...@@ -258,7 +259,8 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'BUILD_ID', 'default'])(
// TODO when serializing server reference arguments, we need to include the server reference's // TODO when serializing server reference arguments, we need to include the server reference's
// entropy in the argument-part of the cache key. // entropy in the argument-part of the cache key.
// Furthermore, we need to compute the metadata information for use-server functions. // But currently, you cannot do anything with the passed server reference anyway.
// Furthermore, we need to compute the metadata information for `use cache` functions as well.
it.skip('should recompute when a use server reference argument changes', async () => { it.skip('should recompute when a use server reference argument changes', async () => {
const key1 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-1') const key1 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-1')
...@@ -349,22 +351,29 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'BUILD_ID', 'default'])( ...@@ -349,22 +351,29 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'BUILD_ID', 'default'])(
) )
}) })
// TODO this seems like a preexisting bug? The reference gets serialized into the cache key as just "$T" it('should work still when a client reference argument changes', async () => {
it.skip('should recompute when a client reference argument changes', async () => { // The client reference is passed as an opaque argument. Instead, we need to make sure that
// the client reference still uses the up-to-date chunks.
const key1 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-1') const key1 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-1')
await next.patchFile( await next.patchFile(
'app/argument-use-client/client.tsx', 'app/argument-use-client/client.tsx',
(oldContent) => (oldContent) =>
oldContent.replace( oldContent
"'use client'", .replace('Client Component A', 'Client Component B')
"'use client'\n\nawait Promise.resolve()" .replace('Button clicked', 'Handle clicked'),
),
async () => { async () => {
const key2 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-2') const key2 = await execute(next, 'NEXT_DEPLOYMENT_ID', 'dpl-id-2')
expect(key1.keyArgumentUseClient).not.toBe(key2.keyArgumentUseClient) expect(key1.keyArgumentUseClient).toBe(key2.keyArgumentUseClient)
expect(key1.dataArgumentUseClient).not.toBe( expect(key1.dataArgumentUseClient).toBe(key2.dataArgumentUseClient)
key2.dataArgumentUseClient
const browser = await next.browser('/argument-use-client')
expect(await browser.elementById('title').text()).toBe(
'Client Component B'
)
await browser.elementByCss('button').click()
expect(await browser.elementById('state').text()).toBe(
'Handle clicked'
) )
} }
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment