Releases: atlassian/react-sweet-state
v2.7.2
v2.7.1
⚠️ Warning
This version accidentally causes a change in behaviour on React 16 with defaults.batchedUpdates
unset (or set to false) on Containers that use onUpdate
. Basically calling to setState inside an onUpdate
might trigger a warning and the subscribers might receive the updates on next tick. We recommend staying on <= v2.7.0 until moving to React 18
Bug fix
- Removed old implementation of Container (class based) that was causing a memory leak is some circumstances. It was replaced with a functional implementation that should perform better. There is a change in behaviour tho: Container stores now get initialised lazily, when the first hook/subscriber is rendered, so
onInit
might be deferred. In most cases that should improve performance, but might make some tests failing if only a container is rendered (with no subscribers).
v2.7.0
New features
Until now, containers were exclusively bound to a single store, they would trigger actions based on the container component lifecycle and would require knowledge of the store and actions. We developed a new API that evolves the concept to be more flexible by inverting the relationship: containers act as boundaries for all stores that declare that they are containedBy
it. This enables some great properties:
- a container can be shared across multiple stores forming a single boundary
- containers are super lightweight and can be imported anywhere without bundling the store
- the stores themselves can declare their own lifecycle handlers
- stores that specify containedBy but end up in a tree without container, will trigger an async error, making possible to track unintended global store leaks. Read more in the new Container docs.
The old container API still exists and is supported, as it makes sense in other contexts like tests, but we recommend the new API for production use cases.
This release also:
- improved performance on pages with thousands of listeners for a single store
- enabled Devtools tracing by default
v2.6.4
- Officially support React 18
- Use React
useSyncExternalStore
hook - Officially deprecate
batchUpdates
setting via types, making defaulttrue
for R18+ - Change internal API (
storeState.subscribe
) types to no longer expose get state/store as arguments. Still available in reality to not break compat
v2.6.0
Deprecations
actions
object in the action thunk is now officially deprecated (was already soft deprecated by not appearing in types and docs) and will now log a warning if accessed.
New features
createActionsHook
API to create stateless hooks that expose only actionscreateStateHook
API to create actionless hooks that expose only state
Bug fixes
- reduce scheduled timeout (when
batchUpdate
is enabled) to ensure snappier experiences
v2.5.2
Bug fixes
- Change
batch
implementation to not schedule if we are already inside a batched scheduled update
Other changes
- Published files are no longer transpiled to support IE11. RSS babel config now supports Edge 18+. But IE11 support can still be achieved by having consumers babel config transpile node_modules (or RSS specifically)
v2.5.1
Bug fixes
- Ensure selectors returning arrays are shallow-equal checked, so mapping same elements (eg when using a normalised state) will not trigger a re-render
v2.5.0
Types breaking changes
- Due to recent Flow behaviour change, had to change
Action
type generics to beAction<State, Props, Return>
fromAction<State, Props, AllActions>
. In most cases just removing the third generic will be fine. AlsoAction
dispatch
type is now better typed, so might surface some new errors. - Typescript
ActionAny
type has been renamedAction
and supports providing correct return type (still default tovoid
tho)
New feature
createSelector
is a new exported member that allows creating reselect like selectors, but optimised for sweet-statedefaults.batchUpdates
is a new settings that leverages React scheduler to batch updates and reduce the number of partial re-renders on state change. Currently defaults tofalse
but might be turned on by default in the future
v2.4.4
Bug fixes
- Allow selectors to return a function (bad pattern but should not break user code)
v2.4.3
Bug fixes
- Stop
<Container isGlobal />
from deleting stores on unmount, should only do that for scoped stores