Skip to content

Hot Reload Issues #31

@ZachHaber

Description

@ZachHaber

Vite's hot reload/fast refresh/HMR/whatever term it uses doesn't work with the callable setup. I get the warning: Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react-swc#consistent-components-exports. This causes the callable to vanish every time the module is invalidated (any time the file is saved), which causes me to have to re-perform actions to open it to see my changes - which is not the best developer experience.

The best workaround I've found so far is to separate out the component and the callable into two separate files. The downside to that is that it ends up with an extra file that is basically a one-liner.
I don't know if this is something that is fixable, but if it's not, there should be a note about HMR (hot module reload) in the readme.


Example of the two file approach mentioned. Note that Confirm.tsx still can't be HMRed, but you can edit the ConfirmBase.tsx which will work without issue.

// ConfirmBase.tsx
import { ReactCall } from 'react-call'
export interface ConfirmProps{
  // props here
}
export const ConfirmBase: ReactCall.UserComponent<ConfirmProps,boolean|null,{}> = ({call,...props})=>{
// component here
return <div></div>
}
// Confirm.tsx
import { createCallable } from 'react-call';
export const Confirm = createCallable(ConfirmBase);

Metadata

Metadata

Assignees

No one assigned

    Labels

    3rd party toolsSupport or bugfixes for 3rd party toolshelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions