bvaughn / suspense

Utilities for working with React Suspense

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getCacheForType is not a function

shellscape opened this issue · comments

Hey there. Interesting project, thanks for putting it together. I installed v0.0.50 and used the code below, and received the error below.

import { createCache } from 'suspense';

const cache = createCache({
  load: () => new Promise<string>((resolve) => setTimeout(() => resolve('done'), 2000))
});
TypeError: getCacheForType is not a function
    at getOrCreateRecord (/node_modules/.pnpm/suspense@0.0.50_react-dom@18.2.0_react@18.2.0/node_modules/suspense/dist/suspense.cjs.js:317:38)
    at Object.read (/node_modules/.pnpm/suspense@0.0.50_react-dom@18.2.0_react@18.2.0/node_modules/suspense/dist/suspense.cjs.js:405:20)

@shellscape are you using an experimental build of React, rather than the stable 18.2 or similar build?

Ah, I'm using stable 18.2.0

I'm learning about react suspense internals now and didn't realize that what the readme refers to are npm tags.

Yeah, React uses feature flags to enable experimental features in non-stable builds, and getCacheForType only exists in experimental builds.

I've added a new error message in 0.0.52 for this case to hopefully help avoid future confusion:
Screenshot 2023-12-15 at 9 35 26 AM