Next.js Discord

Discord Forum

Script with strategy="beforeInteractive" doesn't go to <head> on not-found.tsx page

Unanswered
Dutch posted this in #help-forum
Open in Discord
DutchOP
I have this file structure

src/components/Script.tsx
src/app/.../layout.tsx
src/app/.../page.tsx
src/app/.../not-found.tsx

1) Script.tsx contains a script of this kind:
useEffect(here something that the script needs that cannot be obtained from a server component)

<Script
    strategy="beforeInteractive"
    ...
/>


2) layout.tsx has this Script in it's return. Unfortunately I can't move the Script to <head> directly because it relies on some data that comes from a provider.

3) I can see this script in <head> for a "normal" page.tsx
But it doesn't go to <head> when not-found.tsx renders.

Q: Does Next.js work with "beforeInteractive" script when we render a not-found page? Is there a way to make it work in not-found as it does on page.tsx?

0 Replies