Unverified Commit af82f322 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Enable New CSS Support by Default (#9927)

* Enable New CSS Support by Default

* Adjust configs

* Fix invisible AMP body

* Fix AMP validation warning

* test fix

* Use expression that won't be eliminated by babel
parent 1fe6e9bb
...@@ -3,6 +3,7 @@ import fetch from 'unfetch' ...@@ -3,6 +3,7 @@ import fetch from 'unfetch'
import EventSourcePolyfill from './event-source-polyfill' import EventSourcePolyfill from './event-source-polyfill'
import { getEventSourceWrapper } from './error-overlay/eventsource' import { getEventSourceWrapper } from './error-overlay/eventsource'
import { setupPing } from './on-demand-entries-utils' import { setupPing } from './on-demand-entries-utils'
import { displayContent } from './fouc'
if (!window.EventSource) { if (!window.EventSource) {
window.EventSource = EventSourcePolyfill window.EventSource = EventSourcePolyfill
...@@ -89,3 +90,4 @@ getEventSourceWrapper({ ...@@ -89,3 +90,4 @@ getEventSourceWrapper({
}) })
setupPing(assetPrefix, () => page) setupPing(assetPrefix, () => page)
displayContent()
export function displayContent() {
// This is the fallback helper that removes Next.js' no-FOUC styles when
// CSS mode is enabled. This only really activates if you haven't created
// _any_ styles in your application yet.
;(window.requestAnimationFrame || setTimeout)(function() {
for (
var x = document.querySelectorAll('[data-next-hide-fouc]'), i = x.length;
i--;
) {
x[i].parentNode.removeChild(x[i])
}
})
}
/* globals __REPLACE_NOOP_IMPORT__ */
import initNext, * as next from './' import initNext, * as next from './'
import EventSourcePolyfill from './dev/event-source-polyfill' import EventSourcePolyfill from './dev/event-source-polyfill'
import initOnDemandEntries from './dev/on-demand-entries-client' import initOnDemandEntries from './dev/on-demand-entries-client'
import initWebpackHMR from './dev/webpack-hot-middleware-client' import initWebpackHMR from './dev/webpack-hot-middleware-client'
import initializeBuildWatcher from './dev/dev-build-watcher' import initializeBuildWatcher from './dev/dev-build-watcher'
import initializePrerenderIndicator from './dev/prerender-indicator' import initializePrerenderIndicator from './dev/prerender-indicator'
import { displayContent } from './dev/fouc'
// Temporary workaround for the issue described here: // Temporary workaround for the issue described here:
// https://github.com/zeit/next.js/issues/3775#issuecomment-407438123 // https://github.com/zeit/next.js/issues/3775#issuecomment-407438123
// The runtimeChunk doesn't have dynamic import handling code when there hasn't been a dynamic import // The runtimeChunk doesn't have dynamic import handling code when there hasn't been a dynamic import
// The runtimeChunk can't hot reload itself currently to correct it when adding pages using on-demand-entries // The runtimeChunk can't hot reload itself currently to correct it when adding pages using on-demand-entries
// REPLACE_NOOP_IMPORT // eslint-disable-next-line no-unused-expressions
__REPLACE_NOOP_IMPORT__
// Support EventSource on Internet Explorer 11 // Support EventSource on Internet Explorer 11
if (!window.EventSource) { if (!window.EventSource) {
...@@ -36,19 +39,7 @@ initNext({ webpackHMR }) ...@@ -36,19 +39,7 @@ initNext({ webpackHMR })
initializePrerenderIndicator() initializePrerenderIndicator()
} }
// This is the fallback helper that removes Next.js' no-FOUC styles when displayContent()
// CSS mode is enabled. This only really activates if you haven't created
// _any_ styles in your application yet.
;(window.requestAnimationFrame || setTimeout)(function() {
for (
var x = document.querySelectorAll('[data-next-hide-fouc]'),
i = x.length;
i--;
) {
x[i].parentNode.removeChild(x[i])
}
})
let lastScroll let lastScroll
......
...@@ -41,7 +41,7 @@ const defaultConfig: { [key: string]: any } = { ...@@ -41,7 +41,7 @@ const defaultConfig: { [key: string]: any } = {
(Number(process.env.CIRCLE_NODE_TOTAL) || (Number(process.env.CIRCLE_NODE_TOTAL) ||
(os.cpus() || { length: 1 }).length) - 1 (os.cpus() || { length: 1 }).length) - 1
), ),
css: false, css: true,
documentMiddleware: false, documentMiddleware: false,
granularChunks: true, granularChunks: true,
modern: false, modern: false,
...@@ -107,7 +107,11 @@ function assignDefaults(userConfig: { [key: string]: any }) { ...@@ -107,7 +107,11 @@ function assignDefaults(userConfig: { [key: string]: any }) {
if (result.experimental) { if (result.experimental) {
if (result.experimental.css) { if (result.experimental.css) {
// The new CSS support requires granular chunks be enabled. // The new CSS support requires granular chunks be enabled.
result.experimental.granularChunks = true if (result.experimental.granularChunks !== true) {
throw new Error(
`The new CSS support requires granular chunks be enabled.`
)
}
} }
if (typeof result.experimental.basePath !== 'string') { if (typeof result.experimental.basePath !== 'string') {
......
...@@ -400,11 +400,15 @@ export class Head extends Component< ...@@ -400,11 +400,15 @@ export class Head extends Component<
<> <>
<style <style
data-next-hide-fouc data-next-hide-fouc
data-ampdevmode={inAmpMode ? 'true' : undefined}
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: `body{display:none}`, __html: `body{display:none}`,
}} }}
/> />
<noscript data-next-hide-fouc> <noscript
data-next-hide-fouc
data-ampdevmode={inAmpMode ? 'true' : undefined}
>
<style <style
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: `body{display:block}`, __html: `body{display:block}`,
......
...@@ -10,6 +10,7 @@ module.exports = function(task) { ...@@ -10,6 +10,7 @@ module.exports = function(task) {
const options = { const options = {
...babelOpts, ...babelOpts,
compact: true, compact: true,
comments: false,
babelrc: false, babelrc: false,
configFile: false, configFile: false,
filename: file.base, filename: file.base,
...@@ -30,7 +31,7 @@ module.exports = function(task) { ...@@ -30,7 +31,7 @@ module.exports = function(task) {
// Workaround for noop.js loading // Workaround for noop.js loading
if (file.base === 'next-dev.js') { if (file.base === 'next-dev.js') {
output.code = output.code.replace( output.code = output.code.replace(
'// REPLACE_NOOP_IMPORT', '__REPLACE_NOOP_IMPORT__',
`import('./dev/noop');` `import('./dev/noop');`
) )
} }
......
module.exports = { module.exports = {
experimental: { experimental: {
modern: true, modern: true,
granularChunks: true,
}, },
} }
...@@ -2,9 +2,6 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') ...@@ -2,9 +2,6 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin .BundleAnalyzerPlugin
module.exports = { module.exports = {
assetPrefix: '/foo/', assetPrefix: '/foo/',
experimental: {
granularChunks: true,
},
webpack(config) { webpack(config) {
config.plugins = config.plugins || [] config.plugins = config.plugins || []
config.plugins.push( config.plugins.push(
......
...@@ -3,11 +3,6 @@ module.exports = { ...@@ -3,11 +3,6 @@ module.exports = {
// Make sure entries are not getting disposed. // Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60, maxInactiveAge: 1000 * 60 * 60,
}, },
experimental: {
css: true,
// Intentionally set false to ensure we force to true.
granularChunks: false,
},
webpack(cfg) { webpack(cfg) {
cfg.devtool = 'source-map' cfg.devtool = 'source-map'
return cfg return cfg
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment