Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/runtime/src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ const buildHeader = (buildHeaderParams: BuildHeaderParams) => {
// configuration does not support.
const sanitizePath = (path: string) => path.replace(/:[^*/]+\*$/, '*')

/**
* Sets Content-type header for static RSC assets (text/x-component), so application/octet-stream is not used when serving them
* @param netlifyHeaders - Existing headers that are already configured in the Netlify configuration
*/
export const addContentTypeHeaderToStaticRSCAssets = (netlifyHeaders: NetlifyHeaders = []) => {
netlifyHeaders.push({
for: `*.rsc`,
values: {
'Content-Type': 'text/x-component',
},
})
}

/**
* Persist Next.js custom headers to the Netlify configuration so the headers work with static files
* See {@link https://nextjs.org/docs/api-reference/next.config.js/headers} for more information on custom
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/helpers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ export const generateRscDataEdgeManifest = async ({
const staticAppdirRoutes: Array<string> = []
for (const [path, route] of Object.entries(prerenderManifest.routes)) {
if (isAppDirRoute(route.srcRoute, appPathRoutesManifest) && route.dataRoute) {
staticAppdirRoutes.push(path, route.dataRoute)
staticAppdirRoutes.push(path)
}
}
const dynamicAppDirRoutes: Array<string> = []

for (const [path, route] of Object.entries(prerenderManifest.dynamicRoutes)) {
if (isAppDirRoute(path, appPathRoutesManifest) && route.dataRouteRegex) {
dynamicAppDirRoutes.push(route.routeRegex, route.dataRouteRegex)
dynamicAppDirRoutes.push(route.routeRegex)
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
updateRequiredServerFiles,
configureHandlerFunctions,
generateCustomHeaders,
addContentTypeHeaderToStaticRSCAssets,
} from './helpers/config'
import { onPreDev } from './helpers/dev'
import { writeEdgeFunctions, loadMiddlewareManifest, cleanupEdgeFunctions } from './helpers/edge'
Expand Down Expand Up @@ -250,6 +251,7 @@ const plugin: NetlifyPlugin = {

const { basePath, appDir, experimental } = nextConfig

addContentTypeHeaderToStaticRSCAssets(headers)
generateCustomHeaders(nextConfig, headers)

warnForProblematicUserRewrites({ basePath, redirects })
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime/src/templates/edge-shared/rsc-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ export declare type PrerenderManifest = {

const noop = () => {}

// Ensure that routes with and without a trailing slash map to different ODB paths
const rscifyPath = (route: string) => {
if (route.endsWith('/')) {
return route.slice(0, -1) + '.rsc/'
return route.slice(0, -1) + '.rsc'
}
return route + '.rsc'
}
Expand Down
12 changes: 0 additions & 12 deletions test/helpers/edge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ describe('generateRscDataEdgeManifest', () => {
name: 'RSC data routing',
path: '/',
},
{
function: 'rsc-data',
generator: '@netlify/next-runtime@1.0.0',
name: 'RSC data routing',
path: '/index.rsc',
},
])
})

Expand Down Expand Up @@ -99,12 +93,6 @@ describe('generateRscDataEdgeManifest', () => {
name: 'RSC data routing',
pattern: '^/blog/([^/]+?)(?:/)?$',
},
{
function: 'rsc-data',
generator: '@netlify/next-runtime@1.0.0',
name: 'RSC data routing',
pattern: '^/blog/([^/]+?)\\.rsc$',
},
])
})

Expand Down
18 changes: 18 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,12 @@ describe('onPostBuild', () => {
})

expect(netlifyConfig.headers).toEqual([
{
for: `*.rsc`,
values: {
'Content-Type': 'text/x-component',
},
},
{
for: '/',
values: {
Expand Down Expand Up @@ -1001,6 +1007,12 @@ describe('onPostBuild', () => {
'x-existing-header-in-configuration': 'existing header in configuration value',
},
},
{
for: `*.rsc`,
values: {
'Content-Type': 'text/x-component',
},
},
{
for: '/',
values: {
Expand Down Expand Up @@ -1108,6 +1120,12 @@ describe('onPostBuild', () => {
'x-existing-header-in-configuration': 'existing header in configuration value',
},
},
{
for: `*.rsc`,
values: {
'Content-Type': 'text/x-component',
},
},
])
})

Expand Down