-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat(react): create client tailored to React #1473
Conversation
These changes ensure that we work more tightly with React that can also result in unforeseen performance boosts. In case we would decide on expanding to other libraries/frameworks, a new file per framework could be added. We might also want to update the import from `next-auth/client` to `next-auth/react`. BREAKING CHANGE: Some performance issues (#844) could only be fixed by moving setting up event listeners inside `Provider`. This breaks the current tab/window sync behavior for users who don't use `Provider` in their app. For these users, wrap your app in `<Provider>` at a level above all of your `useSession` calls. If you don't care about tab/window syncing, this might not be needed, but still recommended.
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nextauthjs/next-auth/G9wkLL8BcqcqvAyACVcfM9dzRH7d |
Conflicts: package-lock.json package.json src/providers/faceit.js src/providers/index.js src/providers/instagram.js src/providers/zoho.js src/server/index.js src/server/lib/oauth/client.js www/docs/configuration/providers.md www/docs/providers/faceit.md www/docs/providers/zoho.md www/package-lock.json
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.
Looks good so far!
Codecov Report
@@ Coverage Diff @@
## next #1473 +/- ##
=========================================
- Coverage 10.05% 9.71% -0.35%
=========================================
Files 81 82 +1
Lines 1382 1390 +8
Branches 387 381 -6
=========================================
- Hits 139 135 -4
- Misses 1022 1034 +12
Partials 221 221
Continue to review full report at Codecov.
|
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.
I used npm link
for my existing project to confirm this solves the issue of the unnecessary client-side session call. 🎉
I had to install nodemailer
, which seems like it only be an peerOptionalDependency
though.
@hboylan yes, from version 4, nodemailer will be optional, as it's only needed if someone uses the email provider. anyone else won't have to install it. smaller bundle size, faster install. 😊 |
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.
Impressive work 💯 , did a pair programming review with @balazsorban44 and in my opinion, we're good to go as a base for v4 👍🏽
**What**: These changes ensure that we work more tightly with React that can also result in unforeseen performance boosts. In case we would decide on expanding to other libraries/frameworks, a new file per framework could be added. **Why**: Some performance issues (nextauthjs#844) could only be fixed by moving more of the client code into the `Provider`. **How**: Refactoring `next-auth/client` Related: nextauthjs#1461, nextauthjs#1084, nextauthjs#1462 BREAKING CHANGE: **1.** `next-auth/client` is renamed to `next-auth/react`. **2.** In the past, we exposed most of the functions with different names for convenience. To simplify our source code, the new React specific client code exports only the following functions, listed with the necessary changes: - `setOptions`: Not exposed anymore, use `SessionProvider` props - `options`: Not exposed anymore, use `SessionProvider` props - `session`: Rename to `getSession` - `providers`: Rename to `getProviders` - `csrfToken`: Rename to `getCsrfToken` - `signin`: Rename to `signIn` - `signout`: Rename to `signOut` - `Provider`: Rename to `SessionProvider` **3.** `Provider` changes. - `Provider` is renamed to `SessionProvider` - The `options` prop is now flattened as the props of `SessionProvider`. - `clientMaxAge` has been renamed to `staleTime`. - `keepAlive` has been renamed to `refetchInterval`. An example of the changes: ```diff - <Provider options={{clientMaxAge: 0, keepAlive: 0}}>{children}</Provider> + <SessionProvider staleTime={0} refetchInterval={0}>{children}</SessionProvider> ``` **4.** It is now **required** to wrap the part of your application that uses `useSession` into a `SessionProvider`. Usually, the best place for this is in your `pages/_app.jsx` file: ```jsx import { SessionProvider } from "next-auth/react" export default function App({ Component, pageProps: { session, ...pageProps } }) { return ( // `session` comes from `getServerSideProps` or `getInitialProps`. // Avoids flickering/session loading on first load. <SessionProvider session={session}> <Component {...pageProps} /> </SessionProvider> ) } ```
What:
These changes ensure that we work more tightly with React that can also result in unforeseen performance boosts. In case we would decide on expanding to other libraries/frameworks, a new file per framework could be added.
Why:
Some performance issues (#844) could only be fixed by moving more of the client code into the
Provider
.How:
Refactoring
next-auth/client
Related: #1461, #1084, #1462
BREAKING CHANGE:
1.
next-auth/client
is renamed tonext-auth/react
.2. In the past, we exposed most of the functions with different names for convenience. To simplify our source code, the new React specific client code exports only the following functions, listed with the necessary changes:
setOptions
: Not exposed anymore, useSessionProvider
propsoptions
: Not exposed anymore, useSessionProvider
propssession
: Rename togetSession
providers
: Rename togetProviders
csrfToken
: Rename togetCsrfToken
signin
: Rename tosignIn
signout
: Rename tosignOut
Provider
: Rename toSessionProvider
3.
Provider
changes.Provider
is renamed toSessionProvider
options
prop is now flattened as the props ofSessionProvider
.clientMaxAge
has been renamed tostaleTime
.keepAlive
has been renamed torefetchInterval
.An example of the changes:
4. It is now required to wrap the part of your application that uses
useSession
into aSessionProvider
.Usually, the best place for this is in your
pages/_app.jsx
file: