Skip to content

Releases: atlassian/react-sweet-state

v2.7.2

24 Aug 04:43
Compare
Choose a tag to compare

Bug fixes

  • Fix container subscription leak in StrictMode in #228

v2.7.1

10 Sep 01:06
Compare
Choose a tag to compare

⚠️ 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

02 Aug 06:17
Compare
Choose a tag to compare

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

11 Aug 23:50
Compare
Choose a tag to compare
  • Officially support React 18
  • Use React useSyncExternalStore hook
  • Officially deprecate batchUpdates setting via types, making default true 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

16 Mar 02:07
Compare
Choose a tag to compare

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 actions
  • createStateHook 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

03 Feb 23:20
Compare
Choose a tag to compare

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

09 Dec 23:39
Compare
Choose a tag to compare

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

07 Dec 23:05
Compare
Choose a tag to compare

Types breaking changes

  • Due to recent Flow behaviour change, had to change Action type generics to be Action<State, Props, Return> from Action<State, Props, AllActions>. In most cases just removing the third generic will be fine. Also Action dispatch type is now better typed, so might surface some new errors.
  • Typescript ActionAny type has been renamed Action and supports providing correct return type (still default to void tho)

New feature

  • createSelector is a new exported member that allows creating reselect like selectors, but optimised for sweet-state
  • defaults.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 to false but might be turned on by default in the future

v2.4.4

05 Nov 07:50
Compare
Choose a tag to compare

Bug fixes

  • Allow selectors to return a function (bad pattern but should not break user code)

v2.4.3

03 Nov 07:49
Compare
Choose a tag to compare

Bug fixes

  • Stop <Container isGlobal /> from deleting stores on unmount, should only do that for scoped stores