Aller au contenu principal

· Une minute de lecture

Optimizations and Fixes

  • Selector cache lookup optimizations (#1720, #1736)
  • Allow async selectors to re-evaluate when async dependencies are discovered with stale state (#1736)

· Une minute de lecture

Typing

Fixes

  • Avoid dev-mode console error with React 18 when using shared async selectors across multiple <RecoilRoot>'s. (#1712)
  • Cleanup potential memory leak when using async selectors. (#1714)
  • Fix potentially hung async selectors when shared across multiple roots that depend on atoms initialized with promises that don't resolve. (#1714)

· 3 minutes de lecture

Recoil 0.7 offers some minor API improvements, selector optimizations, and other fixes.

New Features

Atom Defaults are Optional

It is now optional to provide a default value for an atom. If no default is provided the atom will be kept in a "pending" state (e.g. triggering React Suspense) until it is set. (#1639)

This can help avoid awkward typing (such as unecessarily making the type nullable) or awkward placeholder values for the default. An example minimal string atom might be:

atom<string>({key: 'MyString'});

This is also useful when atoms are initialized with atom effects and a default may not be necessary:

atom({
key: 'MyQuery',
effects: [
dbSyncEffect({query, variables}),
],
});

Other New Features

  • Add .getStoreID() method to Snapshot (#1612)
  • Publish RecoilLoadable.loading() factory for making an async Loadable which never resolves. (#1641)

Improvements / Optimizations

Automatically retain snapshots for the duration of async callbacks.

You now no longer need to manually retain snapshots for async callbacks from useRecoilCallback(). (#1632)

  const myCallback = useRecoilCallback(({snapshot}) => async () => {
// No longer necessary to retain() here
await something;
... use snapshot ...
});

If you want to save a Snapshot or reference it from closure state from some other scheduled handler, then you still need to manually retain it.

Other Improvements / Optimizations

  • Optimizations for scaling with more selector dependencies. 2x improvement with 100 dependencies, 4x with 1,000, and now able to support 10,000+ dependencies. (#1651, #1515, #914)
  • Better error reporting when user selector implementations provide inconsistent results (#1696)

Breaking Changes

Selector evaluation or atom defaults can use a Loadable object

Now the selector get() evaluation callback or atom default property can use a Loadable object. (#1640) This can allow them to more cleanly accept synchronous error states:

atom({
key: 'Key',
default: RecoilLoadable.error(new Error('ERROR')),
});

or mapped Loadables or placeholders:

selector({
key: 'Key',
get: ({get}) => {
const queryLoadable = get(noWait(myQuerySelector));
if (queryLoadable.state === 'loading') {
return PLACEHOLDER;
}
return queryLoadable; // Pass on the query results or error state.
}
})

If you wish to explicitly evaluate a selector value to a Promise, Loadable, or RecoilState type object then you can now wrap them with selector.value() or atom.value().

selector({
key: 'Key',
get: ({get}) => {
// Returns an immediate synchronous value
return selector.value(Promise.resolve('Promise as a value'));
},
});

This is only a minor change. It helps make the API more consisent for handling wrappers such as Promise and Loadable, though is not yet available across the entire API. But, it helps set the stage for future potential ability to explicitly set atoms and selectors to asynchronous values or error states.

Other Breaking Changes

Fixes

  • Freezing user values in dev mode now works in JS environments without the Window interface. (#1571)
  • Avoid spurious console errors from atom effects when calling setSelf() from onSet() handlers. (#1589, #1582)

· 4 minutes de lecture

Recoil 0.6 introduces improved support for React 18, including concurrent rendering and transitions, along with new APIs, fixes, and optimizations.

· Une minute de lecture

Welcome to Recoil 0.5 with a few new APIs and improvements.

· Une minute de lecture

Recoil 0.4.1 has been released with some performance optimizations and fixes focused on optimizing when React will re-render components based on Recoil state changes.

· 4 minutes de lecture

We are pleased to announce the release of Recoil 0.4 with configurable selector caches, improved API for transactions with multiple atoms, and other optimizations and fixes.

· 2 minutes de lecture

We are pleased to announce the release of Recoil 0.3 with more flexible RecoilRoot nesting, callback generation, preparation for memory management, optimizations, and bug fixes.

· 4 minutes de lecture

We are pleased to announce the release of Recoil 0.2.0. This release has a new, more reliable implementation of async selectors, greatly improved performance, and many bug fixes and improvements.

· 3 minutes de lecture

Welcome to Recoil version 0.1.1! This release has performance improvements and introduces several experimental features such as support for React Native, working with Snapshots outside of React, and atom effects for managing side-effects of atoms such as logging, synchronization with external stores, persistence, etc.