Skip to content

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

@catamphetamine

Description

@catamphetamine

🐛 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageIssues to be categorized by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions