未验证 提交 8e7ddeb6 编写于 作者: J Joe Haddad 提交者: GitHub

Ensure CSS Is Preloaded First (#9486)

* Ensure CSS Is Preloaded First

* add test polyfills
上级 7ff95951
......@@ -474,6 +474,7 @@ export class Head extends Component<
href={canonicalBase + getAmpPath(ampPath, dangerousAsPath)}
/>
)}
{this.getCssLinks()}
{page !== '/_error' && (
<link
rel="preload"
......@@ -513,7 +514,6 @@ export class Head extends Component<
// (by default, style-loader injects at the bottom of <head />)
<noscript id="__next_css__DO_NOT_USE__" />
)}
{this.getCssLinks()}
{styles || null}
</>
)}
......
......@@ -21,6 +21,44 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const fixturesDir = join(__dirname, '..', 'fixtures')
if (!Array.prototype.flat) {
// eslint-disable-next-line no-extend-native
Object.defineProperty(Array.prototype, 'flat', {
configurable: true,
value: function flat() {
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0])
return depth
? Array.prototype.reduce.call(
this,
function(acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1))
} else {
acc.push(cur)
}
return acc
},
[]
)
: Array.prototype.slice.call(this)
},
writable: true,
})
}
if (!Array.prototype.flatMap) {
// eslint-disable-next-line no-extend-native
Object.defineProperty(Array.prototype, 'flatMap', {
configurable: true,
value: function flatMap() {
return Array.prototype.map.apply(this, arguments).flat()
},
writable: true,
})
}
describe('CSS Support', () => {
describe('Basic Global Support', () => {
const appDir = join(fixturesDir, 'single-global')
......@@ -476,6 +514,13 @@ describe('CSS Support', () => {
const cssSheet = $('link[rel="stylesheet"]')
expect(cssSheet.length).toBe(1)
expect(cssSheet.attr('href')).toMatch(/^\/_next\/static\/css\/.*\.css$/)
/* ensure CSS preloaded first */
const allPreloads = [].slice.call($('link[rel="preload"]'))
const styleIndexes = allPreloads.flatMap((p, i) =>
p.attribs.as === 'style' ? i : []
)
expect(styleIndexes).toEqual([0])
})
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册