atlassian-labs / react-resource-router

Configuration driven routing solution for React SPAs that manages route matching, data fetching and progressive rendering
https://atlassian-labs.github.io/react-resource-router
Apache License 2.0
202 stars 28 forks source link

Improvements to consistency #152

Closed bholloway closed 2 years ago

bholloway commented 2 years ago

Support for synchronous return from getData().

Fix some inconsistencies (potential bugs as marked).

actions
  getResourceFromRemote
    where getData() synchronously returns new data
      before:
        ✓ should enter loading state with new data as promise [BUG] (prefetch=false)
        ✓ should enter loading state with new data as promise [BUG] (prefetch=true)
      after:
        ✓ should enter loading state with promise resolving new data (prefetch=false)
        ✓ should enter loading state with promise resolving new data (prefetch=true)
    where getData() times out
      before:
        ✓ should enter loading state with promise unrepresentive of rejecting TimeoutError [BUG] and clear existing data on loaded [BUG] (prefetch=false, w/ timeout)
        ✓ should enter loading state with promise unrepresentive of rejecting TimeoutError [BUG] and clear existing data on loaded [BUG] (prefetch=true, w/ timeout)
      after:
        ✓ should enter loading state with promise rejecting TimeoutError and preserve existing data on loaded (prefetch=false, w/ timeout)
        ✓ should enter loading state with promise rejecting TimeoutError and preserve existing data on loaded (prefetch=true, w/ timeout)
consistency of promise and data under race conditions
  when update occurs outside loading
    before:
      ✓ should retain stale error [BUG] and stale promise [BUG] on update
      ✓ should set promise when loading but keep data and error (assume not expired)
      ✓ should clear error and set new data and on loaded
    after:
      ✓ should clear error and set promise on update
      ✓ should set promise when loading but keep data (assume not expired)
      ✓ should set new data and on loaded
  when update occurs during loading
    before:
      ✓ should set promise when loading but retain data and error (assume not expired)
      ✓ should retain stale error [BUG] and async promise on update
      ✓ should clear error and set new data on loaded
      ✓ should reinstate stale initial data [BUG] and set error on failed
    after:
      ✓ should set promise on loading but retain data and error (assume not expired)
      ✓ should clear error on update but retain promise
      ✓ should set new data on loaded
      ✓ should retain updated data and set error on failed
  when clear occurs during loading
    before:
      ✓ should set promise on loading but retain data and error (assume not expired)
      ✓ should delete resource state on clear
      ✓ should not reinstate resource slice on loaded
      ✓ should not reinstate resource slice on failed, should reinstate stale data [BUG]
    after:
      ✓ should set promise on loading but retain data and error (assume not expired)
      ✓ should delete resource state on clear
      ✓ should not reinstate resource slice on loaded
      ✓ should not reinstate resource slice on failed