Skip to content

Commit

Permalink
Disable experimental.optimizeServer by default (#69788)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 6, 2024
1 parent 86547db commit bf48448
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ export const defaultConfig: NextConfig = {
: false,
webpackBuildWorker: undefined,
missingSuspenseWithCSRBailout: true,
optimizeServerReact: true,
optimizeServerReact: false,
useEarlyImport: false,
staleTimes: {
dynamic: 30,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore avoid ts errors during manual testing
import { type NextInstance } from 'e2e-utils'

async function getActionsMappingByRuntime(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use server'

export async function action1() {
return { hello: 'world' }
}
export async function action2() {
return { hello: 'action2' }
}
export async function action3() {
return { hello: 'action3' }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { action3 } from './actions'

export default function MyComponent() {
// to prevent tree-shaking
if (globalThis.DO_NOT_TREE_SHAKE) {
console.log('MyComponent imported action3', action3)
}
return <span>i'm MyComponent</span>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use client'

import React, { useEffect } from 'react'
import { action1, action2 } from './actions'
import MyComponent from './my-component'

export default function Page() {
// to prevent tree-shaking
if (globalThis.DO_NOT_TREE_SHAKE) {
console.log('Page imported action2', action2)
}

// calling action1 fails!!
useEffect(() => {
if (globalThis.DO_NOT_TREE_SHAKE) {
action1().then((obj) => {
console.log('action1 returned:', obj)
})
}
}, [])

return <MyComponent />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.TEST_EDGE = '1'

require('./use-effect-actions.test')
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { nextTestSetup } from 'e2e-utils'
import {
getActionsRoutesStateByRuntime,
markLayoutAsEdge,
} from '../_testing/utils'

describe('actions-tree-shaking - use-effect-actions', () => {
const { next } = nextTestSetup({
files: __dirname,
})

if (process.env.TEST_EDGE) {
markLayoutAsEdge(next)
}

it('should not tree shake the used action under useEffect', async () => {
const actionsRoutesState = await getActionsRoutesStateByRuntime(next)

expect(actionsRoutesState).toMatchObject({
'app/mixed/page': {
'action-browser': 3,
},
})
})
})
18 changes: 18 additions & 0 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15600,6 +15600,24 @@
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/production/app-dir/actions-tree-shaking/use-effect-actions/use-effect-actions-edge.test.ts": {
"passed": [],
"failed": [
"actions-tree-shaking - use-effect-actions should not tree shake the used action under useEffect"
],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/production/app-dir/actions-tree-shaking/use-effect-actions/use-effect-actions.test.ts": {
"passed": [],
"failed": [
"actions-tree-shaking - use-effect-actions should not tree shake the used action under useEffect"
],
"pending": [],
"flakey": [],
"runtimeError": false
}
},
"rules": {
Expand Down

0 comments on commit bf48448

Please sign in to comment.