-
-
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
Fix head propagation for MDX components #7838
Conversation
🦋 Changeset detectedLatest 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 |
@@ -37,6 +37,7 @@ export class AstroComponentInstance { | |||
} | |||
|
|||
async init(result: SSRResult) { | |||
if (this.returnValue !== undefined) return this.returnValue; |
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 part makes sure this.returnValue
is cached. Otherwise we're calling render()
then init()
, which causes double head rendering.
// 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); | ||
} | ||
} | ||
} |
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 code is what we had before I did the refactor, so no changes made here.
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.
Looks good. There are conflicts to solve
Yup, the conflicts should go away after I revert #7843 |
Nevermind, I can't seem to revert that PR now. Will manually do it in this PR, then merge. |
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.