Skip to content

Commit 48747cb

Browse files
author
Nathan Booker
committed
f
1 parent f1087c3 commit 48747cb

3 files changed

Lines changed: 5 additions & 28 deletions

File tree

core/app/[locale]/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { revalidate } from '~/client/revalidate-target';
1919
import { WebAnalyticsFragment } from '~/components/analytics/fragment';
2020
import { AnalyticsProvider } from '~/components/analytics/provider';
2121
import { ContainerQueryPolyfill } from '~/components/polyfills/container-query';
22-
import { FooterScripts, HeaderScripts, ScriptsFragment } from '~/components/scripts';
22+
import { ScriptManagerScripts, ScriptsFragment } from '~/components/scripts';
2323
import { routing } from '~/i18n/routing';
2424
import { getToastNotification } from '~/lib/server-toast';
2525

@@ -114,7 +114,7 @@ export default async function RootLayout({ params, children }: Props) {
114114
return (
115115
<html className={clsx(fonts.map((f) => f.variable))} lang={locale}>
116116
<head>
117-
<HeaderScripts scripts={data.site.content.scripts} />
117+
<ScriptManagerScripts location="head" scripts={data.site.content.scripts} strategy="afterInteractive" />
118118
</head>
119119
<body className="flex min-h-screen flex-col">
120120
<NextIntlClientProvider>
@@ -131,7 +131,7 @@ export default async function RootLayout({ params, children }: Props) {
131131
</NextIntlClientProvider>
132132
<VercelComponents />
133133
<ContainerQueryPolyfill />
134-
<FooterScripts scripts={data.site.content.scripts} />
134+
<ScriptManagerScripts location="footer" scripts={data.site.content.scripts} strategy="lazyOnload" />
135135
</body>
136136
</html>
137137
);

core/components/scripts/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { HeaderScripts, FooterScripts } from './scripts';
1+
export { ScriptManagerScripts } from './scripts';
22
export { ScriptsFragment } from './fragment';

core/components/scripts/scripts.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { FragmentOf } from '~/client/graphql';
77
import { ScriptsFragment } from './fragment';
88

99
type ScriptsData = FragmentOf<typeof ScriptsFragment>;
10-
type ScriptNode = NonNullable<ScriptsData['scripts']['edges']>[number]['node'];
1110

1211
interface ScriptRendererProps {
1312
scripts: ScriptsData['scripts'] | null;
@@ -27,7 +26,7 @@ interface ScriptsProps {
2726
* @param {ComponentProps<typeof Script>['strategy']} props.strategy - The loading strategy
2827
* @returns {JSX.Element | null} JSX element containing the rendered scripts
2928
*/
30-
const ScriptRenderer = ({ scripts, location, strategy }: ScriptRendererProps) => {
29+
export const ScriptManagerScripts = ({ scripts, location, strategy }: ScriptRendererProps) => {
3130
if (!scripts?.edges) return null;
3231

3332
const scriptNodes = removeEdgesAndNodes(scripts);
@@ -75,25 +74,3 @@ const ScriptRenderer = ({ scripts, location, strategy }: ScriptRendererProps) =>
7574
</>
7675
);
7776
};
78-
79-
/**
80-
* Renders scripts that should be placed in the <head> tag
81-
* Uses afterInteractive strategy for critical functionality
82-
* @param {ScriptsProps} props - The props containing scripts data
83-
* @param {ScriptsData['scripts'] | null} props.scripts - The scripts data from GraphQL
84-
* @returns {JSX.Element | null} JSX element containing header scripts
85-
*/
86-
export const HeaderScripts = ({ scripts }: ScriptsProps) => {
87-
return <ScriptRenderer location="head" scripts={scripts} strategy="afterInteractive" />;
88-
};
89-
90-
/**
91-
* Renders scripts that should be placed before the closing </body> tag
92-
* Uses lazyOnload strategy for better performance
93-
* @param {ScriptsProps} props - The props containing scripts data
94-
* @param {ScriptsData['scripts'] | null} props.scripts - The scripts data from GraphQL
95-
* @returns {JSX.Element | null} JSX element containing footer scripts
96-
*/
97-
export const FooterScripts = ({ scripts }: ScriptsProps) => {
98-
return <ScriptRenderer location="footer" scripts={scripts} strategy="lazyOnload" />;
99-
};

0 commit comments

Comments
 (0)