Skip to content

Window [__ENV] not being set in Header Script - Next 14.2.3 #145

Open
@KieranTH

Description

@KieranTH

Issue

I recently discovered an issue with my Next Env Variables, where it seems only SSR Components are able to access runtime variables.

After some debugging, it seems although the issue is coming from the <Script/> component from Next.

        <Script id={"test"} strategy={"beforeInteractive"} dangerouslySetInnerHTML={{__html: `console.log('test', window); window['__ENV'] = 'test'; console.log(window);`}}/>

The above code will fail due to the beforeInteractive strategy. If it's set to afterInteractive the window will be updated as expected.

It seems although beforeInteractive causes the script to not run at all in the client.

Anyone else ever encountered a similar issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions