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

Enable New CSS Support by Default #9927

Merged
merged 13 commits into from Jan 9, 2020
2 changes: 2 additions & 0 deletions packages/next/client/dev/amp-dev.js
Expand Up @@ -3,6 +3,7 @@ import fetch from 'unfetch'
import EventSourcePolyfill from './event-source-polyfill'
import { getEventSourceWrapper } from './error-overlay/eventsource'
import { setupPing } from './on-demand-entries-utils'
import { displayContent } from './fouc'

if (!window.EventSource) {
window.EventSource = EventSourcePolyfill
Expand Down Expand Up @@ -89,3 +90,4 @@ getEventSourceWrapper({
})

setupPing(assetPrefix, () => page)
displayContent()
14 changes: 14 additions & 0 deletions packages/next/client/dev/fouc.js
@@ -0,0 +1,14 @@
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])
}
})
}
15 changes: 2 additions & 13 deletions packages/next/client/next-dev.js
Expand Up @@ -4,6 +4,7 @@ import initOnDemandEntries from './dev/on-demand-entries-client'
import initWebpackHMR from './dev/webpack-hot-middleware-client'
import initializeBuildWatcher from './dev/dev-build-watcher'
import initializePrerenderIndicator from './dev/prerender-indicator'
import { displayContent } from './dev/fouc'

// Temporary workaround for the issue described here:
// https://github.com/zeit/next.js/issues/3775#issuecomment-407438123
Expand Down Expand Up @@ -36,19 +37,7 @@ initNext({ webpackHMR })
initializePrerenderIndicator()
}

// 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])
}
})
displayContent()

let lastScroll

Expand Down
8 changes: 6 additions & 2 deletions packages/next/next-server/server/config.ts
Expand Up @@ -41,7 +41,7 @@ const defaultConfig: { [key: string]: any } = {
(Number(process.env.CIRCLE_NODE_TOTAL) ||
(os.cpus() || { length: 1 }).length) - 1
),
css: false,
css: true,
documentMiddleware: false,
granularChunks: true,
modern: false,
Expand Down Expand Up @@ -107,7 +107,11 @@ function assignDefaults(userConfig: { [key: string]: any }) {
if (result.experimental) {
if (result.experimental.css) {
// 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') {
Expand Down
6 changes: 5 additions & 1 deletion packages/next/pages/_document.tsx
Expand Up @@ -400,11 +400,15 @@ export class Head extends Component<
<>
<style
data-next-hide-fouc
data-ampdevmode={inAmpMode ? 'true' : undefined}
dangerouslySetInnerHTML={{
__html: `body{display:none}`,
}}
/>
<noscript data-next-hide-fouc>
<noscript
data-next-hide-fouc
data-ampdevmode={inAmpMode ? 'true' : undefined}
>
<style
dangerouslySetInnerHTML={{
__html: `body{display:block}`,
Expand Down
1 change: 0 additions & 1 deletion test/integration/chunking-minimal/next.config.js
@@ -1,6 +1,5 @@
module.exports = {
experimental: {
modern: true,
granularChunks: true,
},
}
3 changes: 0 additions & 3 deletions test/integration/chunking/next.config.js
Expand Up @@ -2,9 +2,6 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
module.exports = {
assetPrefix: '/foo/',
experimental: {
granularChunks: true,
},
webpack(config) {
config.plugins = config.plugins || []
config.plugins.push(
Expand Down
5 changes: 0 additions & 5 deletions test/integration/css-fixtures/next.config.js
Expand Up @@ -3,11 +3,6 @@ module.exports = {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
experimental: {
css: true,
// Intentionally set false to ensure we force to true.
granularChunks: false,
},
webpack(cfg) {
cfg.devtool = 'source-map'
return cfg
Expand Down