0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fixes View transition styles being missing when component used multiple times (#8710)

This commit is contained in:
Matthew Phillips 2023-10-02 08:51:53 -04:00 committed by GitHub
parent a067c2a2c7
commit 4c2bec681b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 6 deletions

View file

@ -0,0 +1,6 @@
---
'@astrojs/markdoc': patch
'astro': patch
---
Fixes View transition styles being missing when component used multiple times

View file

@ -2209,7 +2209,7 @@ export interface SSRMetadata {
hasRenderedHead: boolean;
headInTree: boolean;
extraHead: string[];
propagators: Map<AstroComponentFactory, AstroComponentInstance>;
propagators: Set<AstroComponentInstance>;
}
/* Preview server stuff */

View file

@ -224,7 +224,7 @@ export function createResult(args: CreateResultArgs): SSRResult {
hasDirectives: new Set(),
headInTree: false,
extraHead: [],
propagators: new Map(),
propagators: new Set(),
},
};

View file

@ -82,8 +82,8 @@ export function createAstroComponentInstance(
) {
validateComponentProps(props, displayName);
const instance = new AstroComponentInstance(result, props, slots, factory);
if (isAPropagatingComponent(result, factory) && !result._metadata.propagators.has(factory)) {
result._metadata.propagators.set(factory, instance);
if (isAPropagatingComponent(result, factory)) {
result._metadata.propagators.add(instance);
}
return instance;
}

View file

@ -0,0 +1,4 @@
---
await new Promise(resolve => setTimeout(resolve, 10));
---
<pre transition:name="animate">{Astro.props.num}</pre>

View file

@ -0,0 +1,13 @@
---
import Wait from '../components/Wait.astro';
---
<html>
<head>
<title>Testing</title>
</head>
<body>
{[1,2].map(num => (
<Wait num={num} />
))}
</body>
</html>

View file

@ -0,0 +1,25 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('View Transitions styles', () => {
let fixture;
let devServer;
before(async () => {
fixture = await loadFixture({ root: './fixtures/view-transitions/' });
devServer = await fixture.startDevServer();
});
after(async () => {
await devServer.stop();
})
it('style tag added for each instance of the component', async () => {
let res = await fixture.fetch('/multiple');
let html = await res.text();
let $ = cheerio.load(html);
expect($('head style')).to.have.a.lengthOf(3);
});
});

View file

@ -92,8 +92,7 @@ export const ComponentNode = createComponent({
// `result.propagators` has been moved to `result._metadata.propagators`
// TODO: remove this fallback in the next markdoc integration major
const propagators = result._metadata.propagators || result.propagators;
propagators.set(
{},
propagators.add(
{
init() {
return headAndContent;