Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Reactive variables and HMR (hot module reloading) / fast-refresh #15

Open
caycecollins opened this issue Jun 16, 2020 · 3 comments
Open

Comments

@caycecollins
Copy link

caycecollins commented Jun 16, 2020

I have a project (not publicly available) that's using the same patterns shown in the apollo-local-state example. During development with HMR setup, components using the useQuery hook fail to receive updates when the mutation function is ran after an HMR update. Everything works fine before the HMR update, and a page reload fixes it after the update, but that defeats the purpose of HRM of course... is this a known issue? I haven't been able to find anything regarding this yet.

I haven't had a chance to create a simple example repo or codesandbox to show the issue, but wanted to ask here just in case it's a known issue.

@stemmlerjs
Copy link
Contributor

@caycecollins, I know we were running into a few snags earlier last month with UI reactivity and getting reactive variables hooked up. I would love to hear how it's working for you now that we've tightened up AC3 with the official release.

@caycecollins
Copy link
Author

caycecollins commented Jul 16, 2020

@stemmlerjs thanks for the response. I just updated to 3.0.1 today and it doesn't appear to be resolved. It should be noted that I am using gatsby for this project, which I'm hoping isn't causing any additional issues here.

Here's some code about my specific implementation:

I have a modal component that uses a reactive variable to control it's open/close state:

const { data: { loginModal } = {} } = useQuery(GET_LOGIN_MODAL)
const { isOpen } = loginModal
const [showModal, setModalVisibility] = React.useState(false)

React.useEffect(() => {
  setModalVisibility(isOpen)
}, [isOpen])

const handleModalClose = () => {
  updateLoginModal({ isOpen: false })
}

Query:

import { gql } from "@apollo/client"

export const GET_LOGIN_MODAL = gql`
  query GetLoginModal {
    loginModal @client {
      isOpen
    }
  }
`

Mutation:

import { loginModalVar } from "../cache"

export const updateLoginModal = ({ isOpen }) => loginModalVar({ isOpen })

I am unable to open/close the modal after an HMR update. I added a log statement before and after the update in the mutation and it does properly change the variable, but the query in my modal component no longer receives update about it's change.

@caycecollins
Copy link
Author

caycecollins commented Dec 7, 2020

I'm still unable to resolve the issue but wanted to reference the open issues in the apollo-client repository which have some better explanations, examples, and outline efforts being taken to resolve the issue(s):
apollographql/apollo-client#6661
apollographql/apollo-client#5870

@caycecollins caycecollins changed the title Reactive variables and hot module reloading Reactive variables and HMR (hot module reloading) & Fast Refresh Dec 7, 2020
@caycecollins caycecollins changed the title Reactive variables and HMR (hot module reloading) & Fast Refresh Reactive variables and HMR (hot module reloading) & fast-refresh Dec 7, 2020
@caycecollins caycecollins changed the title Reactive variables and HMR (hot module reloading) & fast-refresh Reactive variables and HMR (hot module reloading) / fast-refresh Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants