summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2023-09-25 22:14:37 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-25 10:14:37 -0400
commit69fbf95b22c0fb0d8e7e5fef9ec61e26cac9767f (patch)
tree481697fa3dd04ee05764392d96444da49b811009
parent306649c5a4321e1558a444d25862bb62fb53797b (diff)
downloadastro-69fbf95b22c0fb0d8e7e5fef9ec61e26cac9767f.tar.gz
astro-69fbf95b22c0fb0d8e7e5fef9ec61e26cac9767f.tar.zst
astro-69fbf95b22c0fb0d8e7e5fef9ec61e26cac9767f.zip
Head propagation graph walking on new pages (#8646)
* Head propagation graph walking on new pages * Add changeset * Avoid the bang * Add TODOs about handling in resolveId
-rw-r--r--.changeset/fifty-comics-cross.md5
-rw-r--r--packages/astro/src/vite-plugin-head/index.ts27
-rw-r--r--packages/astro/test/fixtures/view-transitions/package.json8
-rw-r--r--packages/astro/test/fixtures/view-transitions/src/components/Animate.astro1
-rw-r--r--packages/astro/test/fixtures/view-transitions/src/components/AnimateContainer.astro1
-rw-r--r--packages/astro/test/fixtures/view-transitions/src/components/Animations.astro4
-rw-r--r--packages/astro/test/fixtures/view-transitions/src/pages/one.astro11
-rw-r--r--packages/astro/test/fixtures/view-transitions/src/pages/two.astro15
-rw-r--r--pnpm-lock.yaml6
9 files changed, 78 insertions, 0 deletions
diff --git a/.changeset/fifty-comics-cross.md b/.changeset/fifty-comics-cross.md
new file mode 100644
index 000000000..6641dea15
--- /dev/null
+++ b/.changeset/fifty-comics-cross.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix cases of head propagation not occuring in dev server
diff --git a/packages/astro/src/vite-plugin-head/index.ts b/packages/astro/src/vite-plugin-head/index.ts
index f8a13f925..f89049c5e 100644
--- a/packages/astro/src/vite-plugin-head/index.ts
+++ b/packages/astro/src/vite-plugin-head/index.ts
@@ -45,19 +45,46 @@ export default function configHeadVitePlugin(): vite.Plugin {
return {
name: 'astro:head-metadata',
+ enforce: 'pre',
+ apply: 'serve',
configureServer(_server) {
server = _server;
},
+ resolveId(source, importer) {
+ if(importer) {
+ // Do propagation any time a new module is imported. This is because
+ // A module with propagation might be loaded before one of its parent pages
+ // is loaded, in which case that parent page won't have the in-tree and containsHead
+ // values. Walking up the tree in resolveId ensures that they do
+ return this.resolve(source, importer, { skipSelf: true }).then(result => {
+ if(result) {
+ let info = this.getModuleInfo(result.id);
+ const astro = info && getAstroMetadata(info);
+ if(astro) {
+ if(astro.propagation === 'self' || astro.propagation === 'in-tree') {
+ propagateMetadata.call(this, importer, 'propagation', 'in-tree');
+ }
+ if(astro.containsHead) {
+ propagateMetadata.call(this, importer, 'containsHead', true);
+ }
+ }
+ }
+ return result;
+ });
+ }
+ },
transform(source, id) {
if (!server) {
return;
}
+ // TODO This could probably be removed now that this is handled in resolveId
let info = this.getModuleInfo(id);
if (info && getAstroMetadata(info)?.containsHead) {
propagateMetadata.call(this, id, 'containsHead', true);
}
+ // TODO This could probably be removed now that this is handled in resolveId
if (info && getAstroMetadata(info)?.propagation === 'self') {
const mod = server.moduleGraph.getModuleById(id);
for (const parent of mod?.importers ?? []) {
diff --git a/packages/astro/test/fixtures/view-transitions/package.json b/packages/astro/test/fixtures/view-transitions/package.json
new file mode 100644
index 000000000..bc6790df4
--- /dev/null
+++ b/packages/astro/test/fixtures/view-transitions/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "@test/view-transitions",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "astro": "workspace:*"
+ }
+}
diff --git a/packages/astro/test/fixtures/view-transitions/src/components/Animate.astro b/packages/astro/test/fixtures/view-transitions/src/components/Animate.astro
new file mode 100644
index 000000000..251e44176
--- /dev/null
+++ b/packages/astro/test/fixtures/view-transitions/src/components/Animate.astro
@@ -0,0 +1 @@
+<pre transition:name="animate"></pre>
diff --git a/packages/astro/test/fixtures/view-transitions/src/components/AnimateContainer.astro b/packages/astro/test/fixtures/view-transitions/src/components/AnimateContainer.astro
new file mode 100644
index 000000000..d0ea817d5
--- /dev/null
+++ b/packages/astro/test/fixtures/view-transitions/src/components/AnimateContainer.astro
@@ -0,0 +1 @@
+<slot/>
diff --git a/packages/astro/test/fixtures/view-transitions/src/components/Animations.astro b/packages/astro/test/fixtures/view-transitions/src/components/Animations.astro
new file mode 100644
index 000000000..6c4a8733e
--- /dev/null
+++ b/packages/astro/test/fixtures/view-transitions/src/components/Animations.astro
@@ -0,0 +1,4 @@
+---
+import Animate from './Animate.astro';
+---
+<Animate />
diff --git a/packages/astro/test/fixtures/view-transitions/src/pages/one.astro b/packages/astro/test/fixtures/view-transitions/src/pages/one.astro
new file mode 100644
index 000000000..dbfaaadb8
--- /dev/null
+++ b/packages/astro/test/fixtures/view-transitions/src/pages/one.astro
@@ -0,0 +1,11 @@
+---
+import Animate from '../components/Animate.astro';
+---
+<html>
+<head>
+ <title>Testing</title>
+</head>
+<body>
+ <Animate />
+</body>
+</html>
diff --git a/packages/astro/test/fixtures/view-transitions/src/pages/two.astro b/packages/astro/test/fixtures/view-transitions/src/pages/two.astro
new file mode 100644
index 000000000..dea877830
--- /dev/null
+++ b/packages/astro/test/fixtures/view-transitions/src/pages/two.astro
@@ -0,0 +1,15 @@
+---
+
+import AnimateContainer from '../components/AnimateContainer.astro';
+import Animations from '../components/Animations.astro';
+---
+<html>
+<head>
+ <title>Testing</title>
+</head>
+<body>
+ <AnimateContainer>
+ <Animations />
+ </AnimateContainer>
+</body>
+</html>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 2463f9ef1..0216539d4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3512,6 +3512,12 @@ importers:
specifier: workspace:*
version: link:../../..
+ packages/astro/test/fixtures/view-transitions:
+ dependencies:
+ astro:
+ specifier: workspace:*
+ version: link:../../..
+
packages/astro/test/fixtures/virtual-astro-file:
dependencies:
astro: