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
This commit is contained in:
parent
306649c5a4
commit
69fbf95b22
9 changed files with 78 additions and 0 deletions
5
.changeset/fifty-comics-cross.md
Normal file
5
.changeset/fifty-comics-cross.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix cases of head propagation not occuring in dev server
|
|
@ -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 ?? []) {
|
||||
|
|
8
packages/astro/test/fixtures/view-transitions/package.json
vendored
Normal file
8
packages/astro/test/fixtures/view-transitions/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "@test/view-transitions",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
1
packages/astro/test/fixtures/view-transitions/src/components/Animate.astro
vendored
Normal file
1
packages/astro/test/fixtures/view-transitions/src/components/Animate.astro
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<pre transition:name="animate"></pre>
|
1
packages/astro/test/fixtures/view-transitions/src/components/AnimateContainer.astro
vendored
Normal file
1
packages/astro/test/fixtures/view-transitions/src/components/AnimateContainer.astro
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<slot/>
|
4
packages/astro/test/fixtures/view-transitions/src/components/Animations.astro
vendored
Normal file
4
packages/astro/test/fixtures/view-transitions/src/components/Animations.astro
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
import Animate from './Animate.astro';
|
||||
---
|
||||
<Animate />
|
11
packages/astro/test/fixtures/view-transitions/src/pages/one.astro
vendored
Normal file
11
packages/astro/test/fixtures/view-transitions/src/pages/one.astro
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
import Animate from '../components/Animate.astro';
|
||||
---
|
||||
<html>
|
||||
<head>
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<Animate />
|
||||
</body>
|
||||
</html>
|
15
packages/astro/test/fixtures/view-transitions/src/pages/two.astro
vendored
Normal file
15
packages/astro/test/fixtures/view-transitions/src/pages/two.astro
vendored
Normal file
|
@ -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>
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue