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

Next.js 13 - Hydration error in production #208

Closed
0l1v3rr opened this issue Mar 8, 2024 · 0 comments
Closed

Next.js 13 - Hydration error in production #208

0l1v3rr opened this issue Mar 8, 2024 · 0 comments
Labels
repro needed Issue will be closed if reproduction isn't provided soon

Comments

@0l1v3rr
Copy link

0l1v3rr commented Mar 8, 2024

Hi there,

I have a Next.js 13+ application that uses t3-env. I have public env variables in my project:

import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
  server: {
    ...
  },
  skipValidation: process.env.SKIP_ENV_VALIDATION === 'true',
  client: {
    NEXT_PUBLIC_PRIMARY_MAIN: z.string().min(1).default('#00b49d'),
    NEXT_PUBLIC_PRIMARY_CONTRAST: z.string().min(1).default('#fff'),
  },
  experimental__runtimeEnv: {
    NEXT_PUBLIC_PRIMARY_MAIN: process.env.NEXT_PUBLIC_PRIMARY_MAIN,
    NEXT_PUBLIC_PRIMARY_CONTRAST: process.env.NEXT_PUBLIC_PRIMARY_CONTRAST,
  },
  emptyStringAsUndefined: true,
});

I have placed the env.mjs file in my root directory (same level as my next config).

I am accessing these variables on both the client and the server. When I access it on the server, it works fine. However, when I use it on the client, the correct env value is displayed for about half a second, and then it falls back to the default value. In dev mode, Next says it's a hydration error.

I should also mention that it works fine locally. It only happens in production. My application is deployed on AWS (an Ubuntu server) and is dockerized.

Has anyone ever run into this problem?

Huge thanks.

@juliusmarminge juliusmarminge added the repro needed Issue will be closed if reproduction isn't provided soon label Mar 13, 2024
@juliusmarminge juliusmarminge closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repro needed Issue will be closed if reproduction isn't provided soon
Projects
None yet
Development

No branches or pull requests

2 participants