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

useTitle broken in Next.js SSR (document is not defined) #749

Closed
ecwyne opened this issue Nov 5, 2019 · 9 comments
Closed

useTitle broken in Next.js SSR (document is not defined) #749

ecwyne opened this issue Nov 5, 2019 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@ecwyne
Copy link

ecwyne commented Nov 5, 2019

What is the current behavior?
Throws error on server ReferenceError: document is not defined
Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:
Use useTitle hook in Next.js project
What is the expected behavior?
Only sets title on client?
A little about versions:

  • OS: macOS Catalina
  • Browser (vendor and version): Chrome 78.0.3904.70
  • React: 16.11.0
  • react-use: 13.2.1
  • Did this worked in the previous package version?
    Yes

Apears to be a consequence of a133267

@streamich streamich added the bug Something isn't working label Nov 6, 2019
@xobotyi
Copy link
Contributor

xobotyi commented Nov 6, 2019

Hm, due to now useTitile is synchronous hook it evaluets on server side, looks like next.js or even react itself been blocking the useEffect hooks on the sevrer side 🤔

@xobotyi xobotyi self-assigned this Nov 6, 2019
@xobotyi
Copy link
Contributor

xobotyi commented Nov 6, 2019

Ill fix it today

@ecwyne
Copy link
Author

ecwyne commented Nov 6, 2019

Could be as simple as

if (typeof document !== 'undefined && t.current !== title) {
    document.title = t.current = title;
}

@xobotyi
Copy link
Contributor

xobotyi commented Nov 6, 2019

@ecwyne i know, just dont have a time yet. In 3-4 hours i think ill push the fix.

xobotyi added a commit that referenced this issue Nov 6, 2019
xobotyi added a commit that referenced this issue Nov 6, 2019
fix(#749): now should work with SSR
streamich pushed a commit that referenced this issue Nov 6, 2019
## [13.2.2](v13.2.1...v13.2.2) (2019-11-06)

### Bug Fixes

* **#749:** now should work with SSR ([c12976c](c12976c)), closes [#749](#749)
@xobotyi
Copy link
Contributor

xobotyi commented Nov 6, 2019

@ecwyne chek new version pls.

@ecwyne
Copy link
Author

ecwyne commented Nov 6, 2019

@xobotyi still getting ReferenceError: document is not defined

@ecwyne
Copy link
Author

ecwyne commented Nov 6, 2019

I think it needs to be typeof document === 'undefined'

@xobotyi
Copy link
Contributor

xobotyi commented Nov 6, 2019

That bad >_> okay, fix will be done in 10-15 minutes i suppose.

xobotyi added a commit that referenced this issue Nov 6, 2019
xobotyi added a commit that referenced this issue Nov 6, 2019
streamich pushed a commit that referenced this issue Nov 6, 2019
## [13.2.2](v13.2.1...v13.2.2) (2019-11-06)

### Bug Fixes

* **#749:** now should work with SSR ([c12976c](c12976c)), closes [#749](#749)
xobotyi added a commit that referenced this issue Nov 6, 2019
@xobotyi
Copy link
Contributor

xobotyi commented Nov 6, 2019

@ecwyne and noooow =) it should be fine.

@xobotyi xobotyi closed this as completed Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants