fix(astro): Fix isHTMLString check failing in multi-realm environments#16142
fix(astro): Fix isHTMLString check failing in multi-realm environments#16142ematipico merged 13 commits intowithastro:mainfrom
isHTMLString check failing in multi-realm environments#16142Conversation
🦋 Changeset detectedLatest commit: e97d963 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 |
|
I’ve made a few changes.
|
|
Did you get to see if adding |
|
I just tested this, and confirmed that even if I change
|
|
It seems that HMR not working when editing MDX files is by design, my apologies. |
renderToString during buildisHTMLString check failing in multi-realm environments
|
Just to follow up on the HMR mention, by "HMR," I specifically meant changes being applied without a full page reload. |
.changeset/jolly-ideas-sell.md
Outdated
| 'astro': patch | ||
| --- | ||
|
|
||
| Fix HTML escaping in `renderToString` for MDX slots during build |
There was a problem hiding this comment.
Can you reword the changeset to be more user-centric? https://contribute.docs.astro.build/docs-for-code-changes/changesets/#tips-and-examples
There was a problem hiding this comment.
I've updated the changeset. does this look good to you?
.changeset/jolly-ideas-sell.md
Outdated
| 'astro': patch | ||
| --- | ||
|
|
||
| Fixes HTML content being incorrectly escaped as plain text due to a failed `isHTMLString` check |
There was a problem hiding this comment.
| Fixes HTML content being incorrectly escaped as plain text due to a failed `isHTMLString` check | |
| Fixes HTML content being incorrectly escaped as plain text when rendering a MDX component using the `AstroContainer` APIs. |
cc @rururux for future reference
There was a problem hiding this comment.
I appreciate you tidying that up for me. Thanks for the reference!
|
Thank you! |
fixes: #16003
Changes
When using the Astro Container API, passing child elements to a component inside an MDX file could cause those elements to be incorrectly escaped.
This happened because the
value instanceof HTMLStringcheck in theisHTMLStringfunction failed to recognize theHTMLStringinstance correctly.astro/packages/astro/src/runtime/server/escape.ts
Lines 50 to 52 in 0d24e3b
(
if(isHTMLString(child))does not evaluate to true, so the program proceeds to the nextifstatement)Following Erika’s suggestion, I have updated the logic to check for the presence of
Symbol.for('astro:html-string')instead of usinginstanceof HTMLString.Testing
Added a test to verify that child elements passed to a component inside an MDX file are not incorrectly escaped.
Docs
N/A, bug fix