-
Notifications
You must be signed in to change notification settings - Fork 288
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
withAuthUser() HOC prevents Fast Refreshing / HMR #163
Comments
I confirmed this problem doesn't happen if you remove I tried breaking Very much welcome help on this! |
So this is interesting. HMR seems to work for my project I'm tinkering with: https://github.com/timfee/slot.fyi. Highlights:
<Layout>
<Component {...pageProps} />
</Layout>
import { FC } from 'react'
import { useAuthUser, withAuthUser } from 'next-firebase-auth'
const Layout: FC = ({ children }) => {
// snip
return (
<>
{ /* snip */ }
{!auth.firebaseUser && auth.clientInitialized && (
<button className="px-3 py-2 bg-yellow-300 rounded">
Sign in
</button>
)}
<main className="max-w-4xl px-6 mx-auto mt-8">{children}</main>
</>
)
}
export default withAuthUser({})(Layout)
import { Profile } from '@/components/settings/account/Profile'
import { CalendarList } from '@/components/settings/calendars/CalendarList'
import { useCollection } from '@/hooks/useCollection'
import { useDocument } from '@/hooks/useDocument'
import firebase from '@/lib/firebase'
import { UserType } from '@/types/user'
import {
AuthAction,
getFirebaseAdmin,
useAuthUser,
withAuthUser,
withAuthUserTokenSSR
} from 'next-firebase-auth'
import { FC } from 'react'
const Account: FC<any> = ({
meta
}: {
meta: {
uid: string
displayName: string
emailAddress: string
photoUrl: string
}
}) => {
const authUser = useAuthUser()
// snip
return (
<>
<Profile
data={typeof profileData === 'undefined' ? null : profileData.data()}
/>
</>
)
}
export const getServerSideProps = withAuthUserTokenSSR({
whenUnauthed: AuthAction.REDIRECT_TO_LOGIN
})(async ({ AuthUser }) => {
const UserRecord: UserType = (
await getFirebaseAdmin().firestore().doc(`/users/${AuthUser.id}`).get()
).data()
console.log(UserRecord)
const {
uid,
meta: { displayName, emailAddress, photoUrl }
} = UserRecord
return {
props: {
meta: {
uid,
displayName,
emailAddress,
photoUrl
}
}
}
})
export default withAuthUser({})(Account) I have no idea why this works, but wanted to share. |
Spent 5 hours on this, and while I don't have a solution, I think I've homed in on the issue (and it's a mega issue if I'm correct)... One of the oddest issues everBasically, if you reduce const withAuthUser = ({} = {}) => (ChildComponent) => {
/* 1 */ const WithAuthUserHOC = (props) => <ChildComponent {...props} /> // Doesn't work
/* 2 */ const WithAuthUserHOC = ChildComponent // Works
return WithAuthUserHOC
} Then Fast Refresh does not work with This is super odd. So odd, that my immediate suspicion was that something's wrong with the build/transpilation. So I've put webpack in Now this is the first library I see that exports a node distribution (specifically of React components) the way this one does (using webpack). Anyhow, if indeed someone confirms that Fast Refresh works when webpack is in And another oneAlso part of the investigation, I had |
OK. I know what the issue is. It is the fact that the library is split distributed with client methods under What I've done:
I'm going to create a new issue regarding how this library is built, with a proposal for a "uni-build", this will have many benefits, but it'll be a breaking change (change to import location for any server related functions). |
@Izhaki I've actually hit the same issue without even using this library. As you mentioned, anytime you use a HOC on a next.js page it doesn't work. Here is a quick demo: https://stackblitz.com/edit/nextjs-77e7qw?file=pages/index.js Any other thoughts or updates? Is this NextJS issue? Or there is a different way to a user be authenticated that might work better? |
This bug appears to be fixed on v1.x with peer dependencies:
I attempted to reproduce the problem here, but HMR is working as expected: It was fixed in v1.0.0-canary.12, possibly because of changing index.server.js to not import from index.js in #512—but we have not investigated the underlying reason. (Unintentional bug fix? We'll take it!) The bug persists on v0.x: Closing this! |
Description
When editing a
Component
that is wrapped withwithAuthUser({})
, React performs full-page refreshes; for example:Version
Using the example's version: "0.13.0-alpha.4"
To Reproduce
gladly-team/next-firebase-auth
repo as isexamples
directoryAdditional context
The warning in the console:
Expected behavior
If this is unavoidable without additional configuration, it'd be awesome to capture the necessary steps somewhere in the example or in the doc. And if it's totally unavoidable, it might be a good FAQ note :)
The text was updated successfully, but these errors were encountered: