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

refactor: support SSR in Deno #754

Merged
merged 3 commits into from
Nov 10, 2020
Merged

refactor: support SSR in Deno #754

merged 3 commits into from
Nov 10, 2020

Conversation

ije
Copy link
Contributor

@ije ije commented Nov 8, 2020

when use SSR with swr in Deno i got a warning:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.

import useSWR from "https://esm.sh/swr"

export default function Home() {
    const { data } = useSWR('/api/hi', fetcher);

    if (!data) {
        return <div>loading...</div>
    }
    return <div>hello {data.name}!</div>
}

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.

Looks amazing, thank you! Will test and merge later.

@ije
Copy link
Contributor Author

ije commented Nov 8, 2020

src/use-swr.ts Outdated
@@ -24,7 +24,7 @@ import {
updaterInterface
} from './types'

const IS_SERVER = typeof window === 'undefined'
const IS_SERVER = typeof window === 'undefined' || (typeof Deno !== 'undefined' && !!Deno?.version?.deno)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is typeof Deno !== 'undefined' ok enough for determining deno environment?
I'm wondering if we can skip the !!Deno?.versions?.deno seems it's crashing the tests on CI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for safety, better to check the Deno.version.deno, i just updated hope it can pass the tests

@ije ije requested review from shuding and huozhi November 9, 2020 04:02
@huozhi huozhi self-requested a review November 9, 2020 07:45
src/use-swr.ts Outdated Show resolved Hide resolved
Co-authored-by: Shu Ding <[email protected]>
@shuding shuding merged commit 0d61d99 into vercel:master Nov 10, 2020
@ije ije deleted the patch-1 branch November 10, 2020 18:46
shuding added a commit that referenced this pull request Nov 13, 2020
* 0.3.8

* replace rIC with rAF (#744)

* Fix race condition when calling mutate synchronously (#735)

* fix race condition when calling mutate synchronously

* fix test

* add comment

* fix code reviews

* refactor: support SSR in Deno (#754)

* refactor: support SSR in Deno

* refactor: improve Deno determining

* Add @ts-ignore

Co-authored-by: Shu Ding <[email protected]>

Co-authored-by: Shu Ding <[email protected]>

* update useSWR-loading and useSWR refresh

* fix eslint error (#768)

Co-authored-by: Shu Ding <[email protected]>
Co-authored-by: X <[email protected]>
shuding added a commit that referenced this pull request Dec 16, 2020
* 0.3.8

* replace rIC with rAF (#744)

* Fix race condition when calling mutate synchronously (#735)

* fix race condition when calling mutate synchronously

* fix test

* add comment

* fix code reviews

* refactor: support SSR in Deno (#754)

* refactor: support SSR in Deno

* refactor: improve Deno determining

* Add @ts-ignore

Co-authored-by: Shu Ding <[email protected]>

Co-authored-by: Shu Ding <[email protected]>

* fix eslint error (#768)

* Fix `mutateCallback` types (#745)

* Fix `mutateCallback` types

* WIP

* Add CodeSandbox CI (#769)

* add CodeSandbox CI

* add new line

* fix install cmd

Co-authored-by: Paco <[email protected]>

* dispatch's payload type is actionType and run lint (#772)

* chore: payload is actionType

* chore: move a ts-ignore comment

* Fix suspense (#777)

* fix #494

* add comment

* rename to initialMountedRef

* 0.3.9

* fix: mark isValidating as false when key is falsy (#757)

* fix: tear down when key turns to empty

* use false for empty key

* Fix README.md typo (#783)

'/api/data' => '/api/user' in "Multiple Arguments"

* fix: do mount check in config callback (#787)

* Update api-hooks example README.md (#790)

Updated the Vercel deploy link to the correct directory

* Return '@null' if args is null ASAP (#767)

* chore: return 'null' if arg[i] is null ASAP

* chore: update comment

* chore: use continue

* Bump ini from 1.3.5 to 1.3.8 (#806)

Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.8)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update test

Co-authored-by: Shu Ding <[email protected]>
Co-authored-by: X <[email protected]>
Co-authored-by: Umidbek Karimov <[email protected]>
Co-authored-by: Paco <[email protected]>
Co-authored-by: matamatanot <[email protected]>
Co-authored-by: Jiachi Liu <[email protected]>
Co-authored-by: sAy <[email protected]>
Co-authored-by: William Crutchfield <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

3 participants