Skip to content

Commit f6ce5c9

Browse files
authored
fix(sveltekit): Fix <meta> tag injection (#7612)
Apparently, the `%sveltekit.head%` placeholder isn't present in the html that's passed to `transformPageChunk`. Hence our `<meta>` tag injection logic introduced in #7574 didn't find the anchor point where to inject the tags. This PR fixes the injection, by simply appending it to an open `<head>` tag. It's not pretty but it should do the trick 🤞 (we can revisit if this breaks folks).
1 parent 2e5d850 commit f6ce5c9

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

packages/sveltekit/src/server/handle.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export const transformPageChunk: NonNullable<ResolveOptions['transformPageChunk'
4040
if (transaction) {
4141
const traceparentData = transaction.toTraceparent();
4242
const dynamicSamplingContext = dynamicSamplingContextToSentryBaggageHeader(transaction.getDynamicSamplingContext());
43-
const content = `<meta name="sentry-trace" content="${traceparentData}"/>
44-
<meta name="baggage" content="${dynamicSamplingContext}"/>
45-
%sveltekit.head%`;
46-
return html.replace('%sveltekit.head%', content);
43+
const content = `<head>
44+
<meta name="sentry-trace" content="${traceparentData}"/>
45+
<meta name="baggage" content="${dynamicSamplingContext}"/>`;
46+
return html.replace('<head>', content);
4747
}
4848

4949
return html;

packages/sveltekit/test/server/handle.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ describe('transformPageChunk', () => {
271271
<meta charset="utf-8" />
272272
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
273273
<meta name="viewport" content="width=device-width" />
274-
%sveltekit.head%
275274
</head>
276275
<body data-sveltekit-preload-data="hover">
277276
<div style="display: contents">%sveltekit.body%</div>

0 commit comments

Comments
 (0)