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

Hydration errors in NextJS User Auth guide #15145

Closed
aleciavogel opened this issue Jun 17, 2023 · 3 comments
Closed

Hydration errors in NextJS User Auth guide #15145

aleciavogel opened this issue Jun 17, 2023 · 3 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed

Comments

@aleciavogel
Copy link

Improve documentation

Link

https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs

(Here's a link to the markdown file to edit for your convenience)

Describe the problem

Following the tutorial exactly results in hydration errors where supabase/auth-helpers-nextjs is used on the client. This may actually require an improvement in that particular library, but there is a pretty easy workaround in the meanwhile.

You also get an error in your terminal if you don't run npm install encoding (again, might have to do with a different library that needs improvement, but it's a simple fix).

Describe the improvement

Add something about running npm install encoding.

In app/auth-form.tsx:

import { useState, useEffect } from 'react';

export default function AuthForm() {
  const supabase = createClientComponentClient<Database>()
  const [isMounted, setIsMounted] = useState(false);

  useEffect(() => {
    setIsMounted(true);
  }, []);

  if (!isMounted) {
    return null;
  }

  // ...
}

And then follow the same pattern for app/account/account-form.tsx.

Additional context

Screenshots of the issues after following the tutorial in a fresh project where I'm using the latest version of NextJS (13.4.6)

Auth form error Account form error

encoding dependency error

@aleciavogel aleciavogel added the documentation Improvements or additions to documentation label Jun 17, 2023
@gregnr
Copy link
Member

gregnr commented Jun 19, 2023

Thanks for reporting @aleciavogel!

I found a related Firebase SDK issue firebase/firebase-js-sdk#7280 which mentions that node-fetch v3 might fix the problem. For @supabase/supabase-js, node-fetch comes from cross-fetch, which is still using node-fetch v2 unfortunately.

I agree that an update to the docs is the best short-term solution. Update to install encoding, probably here:

```bash
npm install @supabase/supabase-js
```

@aleciavogel would you be interested in opening a small PR for this?

@gregnr gregnr added help wanted Extra attention is needed good first issue Good for newcomers labels Jun 19, 2023
@aleciavogel
Copy link
Author

Certainly! I'll get it done after work tonight.

aleciavogel added a commit to aleciavogel/supabase that referenced this issue Jun 20, 2023
- Added a temporary workaround for a console error about the encoding module not being found (this is due to cross-env using node-fetch v2 instead of v3)
- Updated the code snippets for the auth-form and account-form to prevent hydration errors

Refs supabase#15145
@saltcod
Copy link
Contributor

saltcod commented Aug 25, 2023

Addressed on the library side. Marking this one as closed.

@saltcod saltcod closed this as completed Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants