Skip to content
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

Fix head propagation for MDX components #7838

Merged
merged 4 commits into from
Jul 28, 2023
Merged

Fix head propagation for MDX components #7838

merged 4 commits into from
Jul 28, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jul 27, 2023

Changes

Revert this part #7782 (comment)

Fixes MDX fail (Presumably also fixes markdoc but it doesn't seem to have tests cover head propagation)

I'm actually not sure how MDX components can get their head propagated, because it involves attaching themselves to result._metadata.propagators (which I didn't see any for MDX specifically). But reverting this part for now fix it.

Testing

Ran MDX and markdoc test locally. Others tests should also pass.

Docs

n/a. bug fix.

@changeset-bot
Copy link

changeset-bot bot commented Jul 27, 2023

🦋 Changeset detected

Latest commit: 14d8b8f

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 27, 2023
@@ -37,6 +37,7 @@ export class AstroComponentInstance {
}

async init(result: SSRResult) {
if (this.returnValue !== undefined) return this.returnValue;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part makes sure this.returnValue is cached. Otherwise we're calling render() then init(), which causes double head rendering.

Comment on lines 152 to 167
// Recursively calls component instances that might have head content
// to be propagated up.
async function bufferHeadContent(result: SSRResult) {
const iterator = result._metadata.propagators.values();
while (true) {
const { value, done } = iterator.next();
if (done) {
break;
}
// Call component instances that might have head content to be propagated up.
const returnValue = await value.init(result);
if (isHeadAndContent(returnValue)) {
result._metadata.extraHead.push(returnValue.head);
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is what we had before I did the refactor, so no changes made here.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. There are conflicts to solve

@bluwy
Copy link
Member Author

bluwy commented Jul 28, 2023

Yup, the conflicts should go away after I revert #7843

@bluwy
Copy link
Member Author

bluwy commented Jul 28, 2023

Nevermind, I can't seem to revert that PR now. Will manually do it in this PR, then merge.

@bluwy bluwy requested a review from a team as a code owner July 28, 2023 08:47
@bluwy bluwy removed the request for review from a team July 28, 2023 08:47
@bluwy bluwy merged commit e50f646 into main Jul 28, 2023
@bluwy bluwy deleted the fix-mdx-render-fail branch July 28, 2023 10:00
This was referenced Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants