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

setting an atom with a promise results in deleting atomState with read promise error #475

Closed
zcaudate opened this issue May 13, 2021 · 5 comments

Comments

@zcaudate
Copy link

zcaudate commented May 13, 2021

I put together an example here:

https://github.com/zcaudate/js-blessed.store-test

but basically I'm getting an error when using atoms with Suspense.

I'd like to be able to have an atom that is initialised with nil, can have a promise resolving to some data and then be reset back to nil.

So in the example, the atom's initial value is null. createRecord is basically create atom with some metadata stuffed into it:

Then I set the atom's value to a promise (which resolves after a time out) and it produces this error in the suspense element:

// React will try to recreate this component tree from scratch using the error boundary you provided, Debug.
[Bug] deleting atomState with read promise {
  toString: [Function: toString],
  init: null,
  read: [Function (anonymous)],
  write: [Function (anonymous)],
  id: 'js-blessed.store-test.main/UserData',
  section: 'js-blessed.store-test.main/User'
}

This is a bug or a feature of atoms in jotai and if it's a feature, how do I implement a resettable atom with a promise?

@dai-shi
Copy link
Member

dai-shi commented May 13, 2021

Thanks for reporting. It turns out this is valid and not a bug.
#471 fixes it.

https://ci.codesandbox.io/status/pmndrs/jotai/pr/471/builds/129397

yarn add https://pkg.csb.dev/pmndrs/jotai/commit/b246b77a/jotai

Would you try the csb build to confirm it?

@zcaudate
Copy link
Author

@dai-shi - I tried the dev build and the error has gone away but now I'm getting this error:

TypeError: hideInstance is not a function
    at hideOrUnhideAllChildren (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:12734:11)
    at commitSuspenseComponent (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:13536:7)
    at commitWork (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:13474:9)
    at commitMutationEffects (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:15968:11)
    at Object.invokeGuardedCallbackProd (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:12101:10)
    at invokeGuardedCallback (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:12292:31)
    at commitRootImpl (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:15682:9)
    at unstable_runWithPriority (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected]/node_modules/scheduler/cjs/scheduler.development.js:468:12)
    at runWithPriority (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:2495:10)
    at commitRoot (/Users/chris/Development/tahto/foundation/src-app/js_blessed/store_test/.build/node_modules/.pnpm/[email protected][email protected]/node_modules/react-reconciler/cjs/react-reconciler.development.js:15551:3)

it seems like resetting the Suspense element is not allowed.

@dai-shi
Copy link
Member

dai-shi commented May 14, 2021

Thanks for trying.
I'm not exactly sure if it's the expected behavior or a possible bug.
Would it be possible for you to create a minimal repro in codesandbox?
Base: https://codesandbox.io/s/react-typescript-5woxr

@zcaudate
Copy link
Author

okay. this actually works on the dom:

https://codesandbox.io/s/react-typescript-forked-813p1?file=/src/App.tsx

It must be an issue with the react-blessed renderer.

@zcaudate
Copy link
Author

thanks for your help!

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