Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnvScript works on client but not server #144

Open
badtant opened this issue Jun 27, 2024 · 2 comments
Open

EnvScript works on client but not server #144

badtant opened this issue Jun 27, 2024 · 2 comments

Comments

@badtant
Copy link

badtant commented Jun 27, 2024

Hi,

I'm currently exploring this lib (3.2.2) with next (14.2.4).
Testing it in the app router I get undefined for my env on the server but it works on the client. This throws an hydration error...

Here is my code:

layout.tsx

import React from 'react';
import { EnvScript } from 'next-runtime-env';
import { unstable_noStore as noStore } from 'next/cache';

export default function RootLayout({ children }: { children: React.ReactNode }) {
    noStore();

    return (
        <html lang="sv" className="no-js">
            <head>
                <EnvScript
                    env={{
                        NEXT_PUBLIC_FOO: 'VAL_NEXT_PUBLIC_FOO',
                    }}
                />
            </head>
            <body>{children}</body>
        </html>
    );
}

component on test route:

'use client';

import React from 'react';
import { env } from 'next-runtime-env';

const Foo = () => {
    const fooPublic = env('NEXT_PUBLIC_FOO');
    console.log('fooPublic', fooPublic);

    return <h1>{fooPublic}</h1>;
};

export default Foo;
@JSONRice
Copy link

You're only working with a client component not server side.

@badtant
Copy link
Author

badtant commented Sep 19, 2024

Doesn't use client mean run both on the server and on the client?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants