Order server CSS the same as static (#4149)
* Order server CSS the same as static * Adds a changeset
This commit is contained in:
parent
7300f094fd
commit
4d64752274
9 changed files with 114 additions and 2 deletions
5
.changeset/curvy-donuts-build.md
Normal file
5
.changeset/curvy-donuts-build.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes SSR CSS ordering to match static mode
|
|
@ -139,7 +139,7 @@ function buildManifest(
|
||||||
|
|
||||||
routes.push({
|
routes.push({
|
||||||
file: '',
|
file: '',
|
||||||
links: Array.from(pageData.css),
|
links: Array.from(pageData.css).reverse(),
|
||||||
scripts: [
|
scripts: [
|
||||||
...scripts,
|
...scripts,
|
||||||
...astroConfig._ctx.scripts
|
...astroConfig._ctx.scripts
|
||||||
|
|
57
packages/astro/test/css-order.test.js
Normal file
57
packages/astro/test/css-order.test.js
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import * as cheerio from 'cheerio';
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
import testAdapter from './test-adapter.js';
|
||||||
|
|
||||||
|
describe('CSS production ordering', () => {
|
||||||
|
let staticHTML, serverHTML;
|
||||||
|
let staticCSS, serverCSS;
|
||||||
|
|
||||||
|
const commonConfig = Object.freeze({
|
||||||
|
root: './fixtures/css-order/',
|
||||||
|
});
|
||||||
|
|
||||||
|
function getLinks(html) {
|
||||||
|
let $ = cheerio.load(html);
|
||||||
|
let out = [];
|
||||||
|
$('link[rel=stylesheet]').each((i, el) => {
|
||||||
|
out.push($(el).attr('href'))
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
let fixture = await loadFixture({ ...commonConfig });
|
||||||
|
await fixture.build();
|
||||||
|
staticHTML = await fixture.readFile('/one/index.html');
|
||||||
|
staticCSS = await Promise.all(getLinks(staticHTML).map(async (href) => {
|
||||||
|
const css = await fixture.readFile(href);
|
||||||
|
return { href, css };
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
let fixture = await loadFixture({
|
||||||
|
...commonConfig,
|
||||||
|
adapter: testAdapter(),
|
||||||
|
output: 'server',
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
|
||||||
|
const app = await fixture.loadTestAdapterApp();
|
||||||
|
const request = new Request('http://example.com/one');
|
||||||
|
const response = await app.render(request);
|
||||||
|
serverHTML = await response.text();
|
||||||
|
serverCSS = await Promise.all(getLinks(serverHTML).map(async (href) => {
|
||||||
|
const css = await fixture.readFile(`/client${href}`);
|
||||||
|
return { href, css };
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is in the same order for output: server and static', async () => {
|
||||||
|
const staticContent = staticCSS.map(o => o.css);
|
||||||
|
const serverContent = serverCSS.map(o => o.css);
|
||||||
|
|
||||||
|
expect(staticContent).to.deep.equal(serverContent);
|
||||||
|
});
|
||||||
|
});
|
6
packages/astro/test/fixtures/css-order/package.json
vendored
Normal file
6
packages/astro/test/fixtures/css-order/package.json
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"name": "@test/css-order",
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
5
packages/astro/test/fixtures/css-order/src/components/CommonHead.astro
vendored
Normal file
5
packages/astro/test/fixtures/css-order/src/components/CommonHead.astro
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<style is:global>
|
||||||
|
body {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
</style>
|
17
packages/astro/test/fixtures/css-order/src/pages/one.astro
vendored
Normal file
17
packages/astro/test/fixtures/css-order/src/pages/one.astro
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
import CommonHead from '../components/CommonHead.astro';
|
||||||
|
---
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Testing</title>
|
||||||
|
<CommonHead />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 1px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Testing</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
17
packages/astro/test/fixtures/css-order/src/pages/two.astro
vendored
Normal file
17
packages/astro/test/fixtures/css-order/src/pages/two.astro
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
import CommonHead from '../components/CommonHead.astro';
|
||||||
|
---
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Testing</title>
|
||||||
|
<CommonHead />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Testing</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,5 +1,4 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { load as cheerioLoad } from 'cheerio';
|
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture } from './test-utils.js';
|
||||||
import testAdapter from './test-adapter.js';
|
import testAdapter from './test-adapter.js';
|
||||||
|
|
||||||
|
|
|
@ -1462,6 +1462,12 @@ importers:
|
||||||
packages/astro/test/fixtures/css-assets/packages/font-awesome:
|
packages/astro/test/fixtures/css-assets/packages/font-awesome:
|
||||||
specifiers: {}
|
specifiers: {}
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/css-order:
|
||||||
|
specifiers:
|
||||||
|
astro: workspace:*
|
||||||
|
dependencies:
|
||||||
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/custom-404:
|
packages/astro/test/fixtures/custom-404:
|
||||||
specifiers:
|
specifiers:
|
||||||
astro: workspace:*
|
astro: workspace:*
|
||||||
|
|
Loading…
Reference in a new issue