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

Fix missing option in createFromFetch #47216

Merged
merged 4 commits into from Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Expand Up @@ -4,6 +4,7 @@ import type { ReactElement } from "react";
// @ts-expect-error
import { version } from "next/package.json";
import { createFromReadableStream } from "next/dist/compiled/react-server-dom-webpack/client";
import { callServer } from 'next/dist/client/app-call-server';

import { HeadManagerContext } from "next/dist/shared/lib/head-manager-context";

Expand Down Expand Up @@ -109,7 +110,7 @@ function useInitialServerResponse(cacheKey: string) {
},
});

const newResponse = createFromReadableStream(readable);
const newResponse = createFromReadableStream(readable, { callServer });

rscCache.set(cacheKey, newResponse);
return newResponse;
Expand Down
Expand Up @@ -12,6 +12,7 @@ import {
RSC_CONTENT_TYPE_HEADER,
} from '../app-router-headers'
import { urlToUrlWithoutFlightMarker } from '../app-router'
import { callServer } from '../../app-call-server'

/**
* Fetch the flight data for the provided url. Takes in the current router state to decide what to render server-side.
Expand Down Expand Up @@ -75,7 +76,9 @@ export async function fetchServerResponse(
}

// Handle the `fetch` readable stream that can be unwrapped by `React.use`.
const flightData: FlightData = await createFromFetch(Promise.resolve(res))
const flightData: FlightData = await createFromFetch(Promise.resolve(res), {
callServer,
})
return [flightData, canonicalUrl]
} catch (err) {
console.error(
Expand Down
31 changes: 30 additions & 1 deletion test/e2e/app-dir/actions/app-action.test.ts
Expand Up @@ -7,7 +7,7 @@ createNextDescribe(
files: __dirname,
skipDeployment: true,
},
({ next }) => {
({ next, isNextDev }) => {
it('should handle basic actions correctly', async () => {
const browser = await next.browser('/server')

Expand Down Expand Up @@ -83,5 +83,34 @@ createNextDescribe(
await browser.elementByCss('#dec').click()
await check(() => browser.elementByCss('h1').text(), '3')
})

if (isNextDev) {
describe('HMR', () => {
it('should support updating the action', async () => {
const filePath = 'app/server/actions.js'
const origContent = await next.readFile(filePath)

try {
const browser = await next.browser('/server')

const cnt = await browser.elementByCss('h1').text()
expect(cnt).toBe('0')

await browser.elementByCss('#inc').click()
await check(() => browser.elementByCss('h1').text(), '1')

await next.patchFile(
filePath,
origContent.replace('return value + 1', 'return value + 1000')
)

await browser.elementByCss('#inc').click()
await check(() => browser.elementByCss('h1').text(), '1001')
} finally {
await next.patchFile(filePath, origContent)
}
})
})
}
}
)