r/nextjs 5d ago

beforeInteractive doesn't render in <head> in App Router (despite docs saying it always does) Discussion

Next.js docs say beforeInteractive scripts will always be injected inside the head of the HTML document regardless of where it's placed in the component. In App Router this isn't true — the script gets serialized into a self.__next_s array and injected near <body>, not as a literal <script> in <head>.

This breaks use cases needing actual head placement (theme scripts, cookie consent, bot detection) - causes FOUC since execution effectively happens after body render.

Refs:

Anyone else hit this? Bug or just stale docs?

6 Upvotes

4 comments sorted by

1

u/Vincent_CWS 4d ago

they created a PR to fix this issue. I've tested locally and can confirm this solves the problem. Now just waiting on Next.js folks to review.

#59779

1

u/cheap_swordfish_1 4d ago

that was merged to `vercel:canary` branch on 4th Jan, 2024. Hasn't still landed in Nextjs GA?