instantsearch icon indicating copy to clipboard operation
instantsearch copied to clipboard

Custom filter's connector calls `dispose()` function right after the initial render.

Open catamphetamine opened this issue 7 months ago • 1 comments

🐛 Current behavior

For some weird reason, it calls the dispose() function of a custom filter connector right after the initial render. It's not supposed to do that.

Connector:

export const connectCustomFilter = (renderFn, unmountFn = noop) => {
  return function customFilter(widgetParams) {
    console.log('*** Custom Filter function called')
 
    ...

    return {
      ...,

      dispose({ state }) {
        console.log('*** Dispose')
        unmountFn();
      }
    }
  }
}

Hook:

export function useCustomFilter(props, additionalWidgetProperties = {}) {
  return useConnector(
    connectCustomFilter,
    props,
    additionalWidgetProperties
  );
}

Filter Component:

export default function CustomFilterComponent() {
  const { ... } = useCustomFilter({ attribute});

  useEffect(() => {
    console.log('*** Mounted filter component')
    return () => {
      console.log('*** Unmounted filter component')
    }
  }, [])
}

Console output:

*** Custom Filter function called
*** Mounted filter component
*** Custom Filter function called
*** Dispose

🔍 Steps to reproduce

The general code structure and the console output are described above.

Live reproduction

💭 Expected behavior

It shouldn't call the dispose() function at all because the Filter Component doesn't get unmounted at all.

Package version

react-instantsearch@^7.13.8

Operating system

No response

Browser

No response

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

catamphetamine avatar May 08 '25 11:05 catamphetamine