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

Use IE conditional comment placeholders for server island start markers #12090

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-apes-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Server islands: changes the server island HTML placeholder comment so that it is much less likely to get removed by HTML minifiers.
4 changes: 2 additions & 2 deletions packages/astro/src/runtime/server/render/server-islands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function renderServerIsland(
}
}

destination.write('<!--server-island-start-->');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

astro here isn't anything special... it just needs to be a condition that evaluates to false. I wasn't sure about putting server-island-start in the condition part, because I was worried the dashes might break the regex minification libraries rely on to identify these conditional comments. As a bonus, it identifies "hey, Astro put this weird comment here" to anyone who might happen to see it and wonder. But this could be if false or if serverislandstart just as easily.

Copy link
Member

Choose a reason for hiding this comment

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

Fine with me!

destination.write('<!--[if astro]>server-island-start<![endif]-->');

// Render the slots
const renderedSlots: Record<string, string> = {};
Expand Down Expand Up @@ -88,7 +88,7 @@ if(response.status === 200 && response.headers.get('content-type') === 'text/htm
// Swap!
while(script.previousSibling &&
script.previousSibling.nodeType !== 8 &&
script.previousSibling.data !== 'server-island-start') {
script.previousSibling.data !== '[if astro]>server-island-start<![endif]') {
script.previousSibling.remove();
}
script.previousSibling?.remove();
Expand Down
Loading