question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

recoil-sync window is not defined in NextJS using SSR

See original GitHub issue

Hello!

I’m seeing this error when trying to use recoil-sync with NextJS. I assume it’s something to do with SSR.

index.js?46cb:352 Uncaught at getURL (file:///sites/node_modules/recoil-sync/cjs/index.js:2001:33)
    at <unknown> (file:///sites/node_modules/recoil-sync/cjs/index.js:2031:36)
    at useRecoilURLSync (file:///sites/node_modules/recoil-sync/cjs/index.js:2036:26)
    at useRecoilURLSyncJSON (file:///sites/node_modules/recoil-sync/cjs/index.js:2178:3)
    at RecoilURLSyncJSON (file:///sites/node_modules/recoil-sync/cjs/index.js:2185:3)
    at processChild (file:///sites/node_modules/react-dom/cjs/react-dom-server.node.development.js:3353:14)
    at resolve (file:///sites/node_modules/react-dom/cjs/react-dom-server.node.development.js:3270:5)
    at ReactDOMServerRenderer.render (file:///sites/node_modules/react-dom/cjs/react-dom-server.node.development.js:3753:22)
    at ReactDOMServerRenderer.read (file:///sites/node_modules/react-dom/cjs/react-dom-server.node.development.js:3690:29)
    at Object.renderToString (file:///sites/node_modules/react-dom/cjs/react-dom-server.node.development.js:4298:27)

Recoil 7.2 Recoil-sync 0.0.1-alpha.1 NextJS 12.1.0 React 17.0.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
mikeebeecommented, May 18, 2022

Ah, my mistake!

Confirmed this is working

getURL: () => {
  return `http://localhost:3000${router.route}`;
},

Thank you for your patience in helping me with this.

1reaction
mondaychencommented, May 23, 2022

currently the usage of refine should be

import {refine} from 'recoil-sync';
const {string} = refine;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Window is not defined in Next.js React app - Stack Overflow
I am using it to dynamically import libaries that are not compatible with SSR in next.js, since its own dynamic import is only...
Read more >
How to Fix "window is not defined" in Next.js - Upmostly
This issue has to do with Server-Side Rendering in Next.js. Next.js will by default try to use SSR for your site.
Read more >
How to solve Next.js window is not defined
Solve a the common ReferenceError: next.js window is not defined error that you may see when doing SSR & pre-rendering.
Read more >
How to solve "window is not defined" errors in React and Next.js
js world, window is not defined, window is only available in browsers. There are three ways to solve that: 1. First solution: typeof....
Read more >
Recoil Sync Stores for Next.js - Morioh
atom , but initial value can be specified when using it. Note: This is just a utility and does not depend on either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found