Skip to content
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

Merged
merged 9 commits into from May 13, 2022
Merged

Improved React 18 support #1962

merged 9 commits into from May 13, 2022

Conversation

promer94
Copy link
Collaborator

@promer94 promer94 commented May 13, 2022

This PR refactors the SWR core with useSyncExternalStore and startTransition, also moved utils into a shared sub-import.

shuding and others added 9 commits May 13, 2022 19:38
* 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>
@codesandbox-ci
Copy link

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:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

Copy link
Member

@shuding shuding left a 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.

@shuding shuding merged commit 4d65099 into vercel:main May 13, 2022
Copy link
Member

@chibicode chibicode left a 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

Comment on lines +274 to +279
export interface CacheValue<Data = any, Error = any> {
data?: Data
error?: Error
isValidating?: boolean
isLoading?: boolean
}
Copy link
Member

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)

swr/_internal/types.ts

Lines 177 to 182 in 9a0328f

export type State<Data, Error> = {
data?: Data
error?: Error
isValidating?: boolean
isLoading?: boolean
}

Copy link
Collaborator Author

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
Copy link
Member

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.

_internal/utils/use-swr-config.ts Show resolved Hide resolved
test/type/config.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants