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

Build times out when doing next build #2149

Open
niwatoliver opened this issue Jan 3, 2023 · 1 comment
Open

Build times out when doing next build #2149

niwatoliver opened this issue Jan 3, 2023 · 1 comment

Comments

@niwatoliver
Copy link

Doing async on selector's get causes build to time out.

Example project: https://github.com/minakawa-daiki/recoil-build-test

If you remove the async in the following line, the build will pass without incident.
https://github.com/minakawa-daiki/recoil-build-test/blob/main/src/testState.ts#L10

I believe this is a bug in Recoil.

@pcreehan
Copy link

pcreehan commented Jan 10, 2023

To work around this, there are two options.

  1. Rather than using your selector directly on your page, wrap it in a component and then put a Suspense around it.
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import {Suspense} from 'react';
import {useRecoilValue} from "recoil";
import {charCountState} from "../src/testState";

const Count => {
  const count = useRecoilValue(charCountState);
  return (<>{count}</>);
}
export default function Home() {

  return (
    <>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <main className={styles.main}>
        <Suspense fallback='Loading...'><Count/></Suspense>
      </main>
    </>
  )
}
  1. Use useRecoilValueLoadable intead of useRecoilValue.
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import {useRecoilValueLoadable} from "recoil";
import {charCountState} from "../src/testState";

export default function Home() {
  const count = useRecoilValueLoadable(charCountState);
 
  return (
    <>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <main className={styles.main}>
        {count.state == 'hasValue' ? count.getValue() : null}
      </main>
    </>
  ) ;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants