Recoil breaks w/ Next.js (window undefined on server)

Created on 31 May 2020  路  6Comments  路  Source: facebookexperimental/Recoil

Decided to play around with setting up recoil w/ next.js. The issue is it looks like in development mode, recoil looks for the window object which is undefined when next renders the app on the server.

Digging a little deeper, it stems from these window calls in dev mode.

For the time being, I created a workaround that I came up with here essentially loads RecoilRoot(and its children) on the client only.

Would be happy to add a check to see if window is defined before calling any methods on it as well as diving into any other issues that might come up when combing recoil with next :)

Most helpful comment

Hi @Chrischuck

An alternative temporary solution is to only use the production version of Recoil.

const recoil = require('recoil/dist/recoil.production');

All 6 comments

Hi @Chrischuck

An alternative temporary solution is to only use the production version of Recoil.

const recoil = require('recoil/dist/recoil.production');

Hi, is this solved yet ? Or must use workaround like mentioned by @Chrischuck

@x4080 - It's landing now, but that takes a bit of time...

@drarmstr Thanks, I'll wait for it

the temporary fix is working with atom but not with atomFamily

Where is the new error occurring?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

art1373 picture art1373  路  4Comments

Sawtaytoes picture Sawtaytoes  路  4Comments

atanasster picture atanasster  路  3Comments

thegauravthakur picture thegauravthakur  路  3Comments

karevn picture karevn  路  3Comments