Skip to content

Commit

Permalink
Simplify rsc related configs and fix test (#30546)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
3 people committed Oct 28, 2021
1 parent 7232415 commit 5b4ad4a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 48 deletions.
10 changes: 5 additions & 5 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ export default async function build(
setGlobal('phase', PHASE_PRODUCTION_BUILD)
setGlobal('distDir', distDir)

const webServerRuntime = !!config.experimental.concurrentFeatures
const hasConcurrentFeatures = !!config.experimental.concurrentFeatures
const hasServerComponents =
webServerRuntime && !!config.experimental.serverComponents
hasConcurrentFeatures && !!config.experimental.serverComponents

const { target } = config
const buildId: string = await nextBuildSpan
Expand Down Expand Up @@ -593,7 +593,7 @@ export default async function build(
rewrites,
runWebpackSpan,
}),
webServerRuntime
hasConcurrentFeatures
? getBaseWebpackConfig(dir, {
buildId,
reactProductionProfiling,
Expand Down Expand Up @@ -904,7 +904,7 @@ export default async function build(
if (
!isMiddlewareRoute &&
!page.match(RESERVED_PAGE) &&
!webServerRuntime
!hasConcurrentFeatures
) {
try {
let isPageStaticSpan =
Expand Down Expand Up @@ -1014,7 +1014,7 @@ export default async function build(
static: isStatic,
isSsg,
isWebSsr:
webServerRuntime &&
hasConcurrentFeatures &&
!isMiddlewareRoute &&
!page.match(RESERVED_PAGE),
isHybridAmp,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ export default async function getBaseWebpackConfig(
new PagesManifestPlugin({ serverless: isLikeServerless, dev }),
// MiddlewarePlugin should be after DefinePlugin so NEXT_PUBLIC_*
// replacement is done before its process.env.* handling
!isServer && new MiddlewarePlugin({ dev, hasServerComponents }),
!isServer && new MiddlewarePlugin({ dev }),
isServer && new NextJsSsrImportPlugin(),
!isServer &&
new BuildManifestPlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default async function transformSource(
this.loadModule
)

// next.js/packages/next/link.js
// next.js/packages/next/<component>.js
if (/[\\/]next[\\/](link|image)\.js$/.test(url)) {
names.push('default')
}
Expand Down
12 changes: 2 additions & 10 deletions packages/next/build/webpack/plugins/middleware-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,9 @@ export interface MiddlewareManifest {

export default class MiddlewarePlugin {
dev: boolean
hasServerComponents?: boolean

constructor({
dev,
hasServerComponents,
}: {
dev: boolean
hasServerComponents?: boolean
}) {

constructor({ dev }: { dev: boolean }) {
this.dev = dev
this.hasServerComponents = hasServerComponents
}

createAssets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,7 @@ export class TerserPlugin {
const pluginName = this.constructor.name
const availableNumberOfCores = this.options.parallel

compiler.hooks.compilation.tap(pluginName, (compilation) => {
// Don't run minifier against mini-css-extract-plugin
if (
compilation.name !== 'client' &&
compilation.name !== 'server' &&
compilation.name !== 'server-web'
) {
return
}

compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
const cache = compilation.getCache('TerserWebpackPlugin')

const handleHashForChunk = (hash, chunk) => {
Expand Down
31 changes: 13 additions & 18 deletions packages/next/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1193,25 +1193,20 @@ export async function renderToHTML(
)
}
: null,
renderOpts.optimizeCss
!process.browser && renderOpts.optimizeCss
? async (html: string) => {
if (process.browser) {
// Have to disable critters under the web environment.
return html
} else {
// eslint-disable-next-line import/no-extraneous-dependencies
const Critters = require('critters')
const cssOptimizer = new Critters({
ssrMode: true,
reduceInlineStyles: false,
path: renderOpts.distDir,
publicPath: `${renderOpts.assetPrefix}/_next/`,
preload: 'media',
fonts: false,
...renderOpts.optimizeCss,
})
return await cssOptimizer.process(html)
}
// eslint-disable-next-line import/no-extraneous-dependencies
const Critters = require('critters')
const cssOptimizer = new Critters({
ssrMode: true,
reduceInlineStyles: false,
path: renderOpts.distDir,
publicPath: `${renderOpts.assetPrefix}/_next/`,
preload: 'media',
fonts: false,
...renderOpts.optimizeCss,
})
return await cssOptimizer.process(html)
}
: null,
inAmpMode || hybridAmp
Expand Down
2 changes: 1 addition & 1 deletion test/integration/react-18/app/components/dynamic-hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dynamic from 'next/dynamic'
let ssr
const suspense = false

const Hello = dynamic(() => import('./hello'), {
const Hello = dynamic(() => import(/* webpackMode: "eager" */ './hello'), {
ssr,
suspense,
})
Expand Down
4 changes: 2 additions & 2 deletions test/integration/react-18/test/concurrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default (context, _render) => {
})
})

it.skip('should resolve suspense on server side if not suspended on server', async () => {
it('should resolve suspense on server side if not suspended on server', async () => {
await withBrowser('/suspense/no-thrown', async (browser) => {
await check(
() => browser.waitForElementByCss('#server-rendered').text(),
Expand All @@ -39,7 +39,7 @@ export default (context, _render) => {
})
})

it.skip('should resolve suspense on server side if suspended on server', async () => {
it('should resolve suspense on server side if suspended on server', async () => {
await withBrowser('/suspense/thrown', async (browser) => {
await check(
() => browser.waitForElementByCss('#server-rendered').text(),
Expand Down

0 comments on commit 5b4ad4a

Please sign in to comment.