-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Prefetch CSS only once #4557
Closed
Closed
Prefetch CSS only once #4557
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c3df2a
test1
Jelenkee 361e02e
fixed test
Jelenkee 97d97ba
removed console.log
Jelenkee 663115a
changeset
Jelenkee 550283c
pnpm-lock
Jelenkee bae22f5
fixed test again
Jelenkee 9d00b7a
Merge branch 'main' into prefetch-styles
matthewp 3004259
fta
Jelenkee 1256ae4
fta2
Jelenkee 5d019fc
fix: wait for fetch
natemoo-re c52979f
Merge branch 'main' into prefetch-styles
natemoo-re File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/prefetch': minor | ||
--- | ||
|
||
Prefetch CSS files once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/integrations/prefetch/test/fixtures/style-prefetch/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import prefetch from '@astrojs/prefetch'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [prefetch()], | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/integrations/prefetch/test/fixtures/style-prefetch/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/astro-prefetch", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/prefetch": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Home</title> | ||
</head> | ||
<body> | ||
<h1>Home</h1> | ||
<ul> | ||
<li><a href="/style1">1</a></li> | ||
<li><a href="/style2">2</a></li> | ||
</ul> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style1.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Style1</title> | ||
<link rel="stylesheet" href="/main.css"> | ||
</head> | ||
<body> | ||
<h1>Style1</h1> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style2.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Style2</title> | ||
<link rel="stylesheet" href="/main.css"> | ||
</head> | ||
<body> | ||
<h1>Style2</h1> | ||
</body> | ||
</html> |
55 changes: 55 additions & 0 deletions
55
packages/integrations/prefetch/test/style-prefetch.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { expect } from '@playwright/test'; | ||
import { testFactory } from './test-utils.js'; | ||
|
||
const test = testFactory({ root: './fixtures/style-prefetch/' }); | ||
|
||
test.describe('Style prefetch', () => { | ||
test.describe('dev', () => { | ||
let devServer; | ||
|
||
test.beforeEach(async ({ astro }) => { | ||
devServer = await astro.startDevServer(); | ||
}); | ||
|
||
test.afterEach(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
testPrefetch(); | ||
}); | ||
|
||
test.describe('build', () => { | ||
let previewServer; | ||
|
||
test.beforeAll(async ({ astro }) => { | ||
await astro.build(); | ||
previewServer = await astro.preview(); | ||
}); | ||
|
||
// important: close preview server (free up port and connection) | ||
test.afterAll(async () => { | ||
await previewServer.stop(); | ||
}); | ||
|
||
testPrefetch(); | ||
}); | ||
|
||
function testPrefetch() { | ||
test.describe('prefetches rel="prefetch" links', () => { | ||
test('style fetching', async ({ page, astro }) => { | ||
const requests = []; | ||
|
||
page.on('request', async (request) => requests.push(request.url())); | ||
|
||
await page.goto(astro.resolveUrl('/')); | ||
|
||
await page.waitForLoadState('networkidle'); | ||
|
||
await expect(requests.filter(req => req.includes('/style1'))).toBeTruthy(); | ||
await expect(requests.filter(req => req.includes('/style2'))).toBeTruthy(); | ||
const cssRequestCount = requests.filter(req => req.includes('/main.css')).length; | ||
await expect(cssRequestCount).toBe(1); | ||
}); | ||
}); | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This promise needed to be returned, which might fix the tests! Watching CI to see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jelenkee can you try this?