bvaughn / suspense

Utilities for working with React Suspense

Home Page:https://suspense.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional params can break caches

bvaughn opened this issue · comments

Consider the following cache:

export const objectCache: Cache<[foo: string, bar?: boolean], Object> =
  createCache({
    load: async (foo, bar = false) => {
      // ...
    },
  });

This code assumes the array of ...params will always contain both parameters:

const valueOrPromiseLike = load(...params, abortController);

If not, the actual load function will end up being called with the AbortController in place of the boolean bar parameter.

The API should be changed such that params are not spread:

const valueOrPromiseLike = load(params, abortController);

Alternately "normal" caches could be changed to mirror streaming caches and pass the additional parameters first:

const valueOrPromiseLike = load(abortController, ...params);

Fixed in v0.0.25