Omnistac / zedux

:zap: A Molecular State Engine for React
https://Omnistac.github.io/zedux/
MIT License
376 stars 7 forks source link

feat(react): upgrade peer and dev deps to React 19 #121

Closed bowheart closed 2 months ago

bowheart commented 2 months ago

Description

Since React 19 resolves the big issue that has made Zedux's useAtomSelector hook so complex in the past, Zedux v1.3.0 and v2.0.0 (and all future versions) will technically drop support for React versions prior to 19.

Using Zedux in older versions will technically work, so we aren't labeling this as a breaking change or waiting till Zedux v2. However, it will be susceptible to a memory "leak" when using useAtomSelector. This isn't a real leak since Zedux gives you full control over the cache. This means you can set up e.g. an interval that regularly destroys cached selectors that have no dependents. For example:

const runCleanup = () => requestIdleCallback(() => {
  const graph = myEcosytem.viewGraph()

  Object.entries(myEcosystem.selectors.findAll()).forEach(([id, cache]) => {
    if (!Object.keys(graph[id].dependents).length) {
      myEcosystem.selectors.destroyCache(cache, undefined, true)
    }
  })

  // run cleanup every 10 seconds
  setTimeout(runCleanup, 10000)
})

runCleanup()

You're also free to not use selectors - they're optional in Zedux. Use ions instead until you can upgrade to React 19.

In older React versions, Zedux will also now be unable to determine a user-friendly name for graph pseudo-nodes created for React components. This doesn't break anything, it's just slightly worse DX. This is because React changed the name of their "internals" object in React 19. Since it isn't a big deal, we'd rather not lose perf by checking for the existence of all possible internals keys or build size by including both big strings.

While circumventing the "leak" is possible, it's still recommended to wait to upgrade Zedux until you upgrade to React 19.