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

[firebase] Recoil 3.0 cannot work with firebase #1053

Closed
namofnoah opened this issue Jun 1, 2021 · 2 comments
Closed

[firebase] Recoil 3.0 cannot work with firebase #1053

namofnoah opened this issue Jun 1, 2021 · 2 comments

Comments

@namofnoah
Copy link

Previously it was working with version 2.0 but after I upgrade to version 3.0, it crashed
export const firestoreState = atom({
key: "firestore", // unique ID (with respect to other atoms/selectors)
default: firebase.app().firestore(), // default value (aka initial value)
});

export const allMovieState = selector({
key: "allMovieState",
get: async ({ get }) => {
// Get your firestore instance
const firestore = get(firestoreState);
// Use it!
const movies = await firestore.collection("movies").get();
const movieNames = [...movies.docs].map((doc) => {
const movieData = doc.data();
return {
id: doc.id,
title: movieData.title,
assetRef: movieData.assetRef, // refers to the streaming asset
};
});
return movieNames;
},
});

It said something relating to _frozenObject.

@drarmstr
Copy link
Contributor

drarmstr commented Jun 2, 2021

There were some fixes where Recoil will now properly freeze objects stored as values in selectors in dev mode. This is done to help catch issues where users may attempt to mutate objects thinking they are changing state whereas all state changes must go through a proper Recoil set.

First question is if you or firebase is expecting to mutate these objects and if that could be avoided? If not, does the mutation represent a state change? If it doesn't then you can workaround the object freezing by maybe storing a handle to the object instead of the object itself or using the dangerouslyAllowMutability option for the selector.

@drarmstr drarmstr changed the title Recoil 3.0 cannot work with firebase [firebase] Recoil 3.0 cannot work with firebase Jun 2, 2021
@namofnoah
Copy link
Author

Hi,
I tried it but it still cried out cloud. Here is my setup for firebase:
export const firestoreState = selector({
key: "firestoreState",
get: () => {
return firebase.app().firestore()
},
dangerouslyAllowMutability: true,
})

And i got this error: TypeError: Cannot assign to read only property '_settingsFrozen' of object '#'

Version 2.0 is working for this way, is there anyway to workaround?

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

3 participants