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

Strip internal pages for pagesDir in app edge ssr #40776

Merged
merged 4 commits into from Sep 22, 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
10 changes: 7 additions & 3 deletions .github/actions/next-stats-action/src/run/index.js
Expand Up @@ -253,9 +253,13 @@ async function linkPkgs(pkgDir = '', pkgPaths) {
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgData, null, 2), 'utf8')

await fs.remove(yarnEnvValues.YARN_CACHE_FOLDER)
await exec(`cd ${pkgDir} && pnpm install`, false, {
env: yarnEnvValues,
})
await exec(
`cd ${pkgDir} && pnpm install --strict-peer-dependencies=false`,
false,
{
env: yarnEnvValues,
}
)
}

module.exports = runConfigs
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -1401,7 +1401,7 @@ export default async function getBaseWebpackConfig(
runtimeChunk: isClient
? { name: CLIENT_STATIC_FILES_RUNTIME_WEBPACK }
: undefined,
minimize: !dev && isClient,
minimize: !dev && (isClient || isEdgeServer),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we finally settled down with this? I'm glad about it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we need minification for applying tree-shaking, so adding this could help monitoring the size without dead code

minimizer: [
// Minify JavaScript
(compiler: webpack.Compiler) => {
Expand Down
Expand Up @@ -68,29 +68,33 @@ export default async function edgeSSRLoader(this: any) {
import { adapter, enhanceGlobals } from 'next/dist/server/web/adapter'
import { getRender } from 'next/dist/build/webpack/loaders/next-edge-ssr-loader/render'

import Document from ${stringifiedDocumentPath}

enhanceGlobals()

const pageType = ${JSON.stringify(pagesType)}
${
isAppDir
? `
const Document = null
const appRenderToHTML = require('next/dist/server/app-render').renderToHTMLOrFlight
const pagesRenderToHTML = null
const pageMod = require(${JSON.stringify(pageModPath)})
const appMod = null
const errorMod = null
const error500Mod = null
`
: `
const Document = require(${stringifiedDocumentPath}).default
const appRenderToHTML = null
const pagesRenderToHTML = require('next/dist/server/render').renderToHTML
const pageMod = require(${stringifiedPagePath})
const appMod = require(${stringifiedAppPath})
const errorMod = require(${stringifiedErrorPath})
const error500Mod = ${
stringified500Path ? `require(${stringified500Path})` : 'null'
}
`
}

const appMod = require(${stringifiedAppPath})
const errorMod = require(${stringifiedErrorPath})
const error500Mod = ${
stringified500Path ? `require(${stringified500Path})` : 'null'
}

const buildManifest = self.__BUILD_MANIFEST
const reactLoadableManifest = self.__REACT_LOADABLE_MANIFEST
Expand All @@ -101,6 +105,7 @@ export default async function edgeSSRLoader(this: any) {
}

const render = getRender({
pageType,
dev: ${dev},
page: ${JSON.stringify(page)},
appMod,
Expand Down
Expand Up @@ -17,6 +17,7 @@ export function getRender({
pageMod,
errorMod,
error500Mod,
pagesType,
Document,
buildManifest,
reactLoadableManifest,
Expand All @@ -28,6 +29,7 @@ export function getRender({
config,
buildId,
}: {
pagesType?: 'app' | 'pages' | 'root'
dev: boolean
page: string
appMod: any
Expand All @@ -46,13 +48,14 @@ export function getRender({
config: NextConfig
buildId: string
}) {
const isAppPath = pagesType === 'app'
const baseLoadComponentResult = {
dev,
buildManifest,
reactLoadableManifest,
subresourceIntegrityManifest,
Document,
App: appMod.default as AppType,
App: appMod?.default as AppType,
}

const server = new WebServer({
Expand All @@ -72,6 +75,7 @@ export function getRender({
appRenderToHTML,
pagesRenderToHTML,
loadComponent: async (pathname) => {
if (isAppPath) return null
if (pathname === page) {
return {
...baseLoadComponentResult,
Expand Down
7 changes: 7 additions & 0 deletions test/.stats-app/app/app-edge-ssr/page.js
@@ -0,0 +1,7 @@
export default function page() {
return 'edge-ssr'
}

export const config = {
runtime: 'experimental-edge',
}
9 changes: 9 additions & 0 deletions test/.stats-app/next.config.js
@@ -0,0 +1,9 @@
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: !!process.env.TEST_ANALYZE,
})

module.exports = withBundleAnalyzer({
experimental: {
appDir: true,
},
})
4 changes: 2 additions & 2 deletions test/.stats-app/package.json
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"dependencies": {
"next": "latest",
"react": "18.2.0",
"react-dom": "18.2.0"
"react": "experimental",
"react-dom": "experimental"
}
}
6 changes: 0 additions & 6 deletions test/.stats-app/pages/edge-ssr.js
Expand Up @@ -2,12 +2,6 @@ export default function page() {
return 'edge-ssr'
}

export async function getServerSideProps() {
return {
props: {},
}
}

export const config = {
runtime: 'experimental-edge',
}
21 changes: 18 additions & 3 deletions test/.stats-app/stats-config.js
Expand Up @@ -32,8 +32,11 @@ const clientGlobs = [
globs: ['fetched-pages/**/*.html'],
},
{
name: 'Edge SSR Page bundle Size',
globs: ['.next/server/pages/edge-ssr.js'],
name: 'Edge SSR bundle Size',
globs: [
'.next/server/pages/edge-ssr.js',
'.next/server/app/app-edge-ssr/page.js',
],
},
huozhi marked this conversation as resolved.
Show resolved Hide resolved
{
name: 'Middleware size',
Expand Down Expand Up @@ -89,6 +92,9 @@ module.exports = {
path: 'next.config.js',
content: `
module.exports = {
experimental: {
appDir: true,
},
generateBuildId: () => 'BUILD_ID',
webpack(config) {
config.optimization.minimize = false
Expand All @@ -109,7 +115,10 @@ module.exports = {
{
path: 'next.config.js',
content: `
module.exports = {
module.exports = {
experimental: {
appDir: true,
},
generateBuildId: () => 'BUILD_ID'
}
`,
Expand Down Expand Up @@ -144,6 +153,9 @@ module.exports = {
path: 'next.config.js',
content: `
module.exports = {
experimental: {
appDir: true,
},
generateBuildId: () => 'BUILD_ID',
swcMinify: true,
webpack(config) {
Expand All @@ -166,6 +178,9 @@ module.exports = {
path: 'next.config.js',
content: `
module.exports = {
experimental: {
appDir: true,
},
swcMinify: true,
generateBuildId: () => 'BUILD_ID'
}
Expand Down