-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved React 18 support #1962
Conversation
* type: extends useConfig cache interface (vercel#1938) * remove mount check for react18 (vercel#1927) reactwg/react-18#82 related pr vercel#787 vercel#433 * lint: dont check unused vars with underscore prefix (vercel#1939) * test: upgrade to jest 28 (vercel#1942) * Upgrade to jest 28 * Upgrade to jest 28 * feat: useSyncExternalStoreWithSelector * refactor: remove stateUpdate and boardcast state update should be handled by uSESW * type: fix test type error * remove pnpm.lock * fix: import cjs for codesanbox * refactor: add selector * refactor: add cachestate interface and try fix custom cache * fix: custom cache init * refactor: remove useless flag * chore: codesanbox ci * refactor: remove force render in infinite * build: add _internal * chore: mark warning test * fix: dts generation * codesanbox ci * chore: rename swr folder to core Co-authored-by: Jiachi Liu <inbox@huozhi.im>
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 42dc3a1:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _internal
change increases the overall bundle size a lot caused by named exports which can't be mangled. But I will address these later with a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be some type regression from #1961
export interface CacheValue<Data = any, Error = any> { | ||
data?: Data | ||
error?: Error | ||
isValidating?: boolean | ||
isLoading?: boolean | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CacheValue
is identical to State
(see https://github.com/vercel/swr/pull/1961/files#r872242431)
Lines 177 to 182 in 9a0328f
export type State<Data, Error> = { | |
data?: Data | |
error?: Error | |
isValidating?: boolean | |
isLoading?: boolean | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two types should be merged
set(key: Key, value: State<Data, Error>): void | ||
export interface Cache<Data = any> { | ||
get(key: Key): CacheValue<Data> | undefined | ||
set(key: Key, value: Data): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of set
was updated in https://github.com/vercel/swr/pull/1961/files#r872245634 - seems like a regression.
This PR refactors the SWR core with
useSyncExternalStore
andstartTransition
, also moved utils into a shared sub-import.