Skip to content

Commit

Permalink
Remove dead code elimination for when iSSG isn't used (#9267)
Browse files Browse the repository at this point in the history
* Don't rely on page-config plugin to detect iSSG usage

* Make sure to only update sprStatus if page file

* Remove dead-code elimination for iSSG code

* Revert next-page-config.ts

* Update index.js

* Update index.test.js
  • Loading branch information
ijjk authored and Timer committed Oct 31, 2019
1 parent 81066a3 commit aafbd53
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { SourceMapConsumer } from 'source-map'
import { SourceMapSource, RawSource } from 'webpack-sources'
import { RequestShortener } from 'webpack'
import TaskRunner from './TaskRunner'
import { sprStatus } from '../../../../babel/plugins/next-page-config'

const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/

Expand Down Expand Up @@ -177,15 +176,6 @@ export class TerserPlugin {
inputSourceMap = null
}

// force dead-code elimination for SPR related code if not used
const { compress } = this.options.terserOptions
if (compress) {
if (!compress.global_defs) {
compress.global_defs = {}
}
compress.global_defs['self.__HAS_SPR'] = !!sprStatus.used
}

const task = {
file,
input,
Expand Down
6 changes: 1 addition & 5 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,7 @@ export default class Router implements BaseRouter {
const { Component: App } = this.components['/_app']
let props

if (
// @ts-ignore workaround for dead-code elimination
(self.__HAS_SPR || process.env.NODE_ENV !== 'production') &&
(Component as any).__NEXT_SPR
) {
if ((Component as any).__NEXT_SPR) {
let status: any
// pathname should have leading slash
let { pathname } = parse(ctx.asPath || ctx.pathname)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/size-limit/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Production response size', () => {
)

// These numbers are without gzip compression!
expect(responseSizeKilobytes).toBeLessThanOrEqual(221) // Kilobytes
expect(responseSizeKilobytes).toBeLessThanOrEqual(222) // Kilobytes
})

it('should not increase the overall response size of modern build', async () => {
Expand All @@ -99,6 +99,6 @@ describe('Production response size', () => {
)

// These numbers are without gzip compression!
expect(responseSizeKilobytes).toBeLessThanOrEqual(199) // Kilobytes
expect(responseSizeKilobytes).toBeLessThanOrEqual(200) // Kilobytes
})
})

0 comments on commit aafbd53

Please sign in to comment.