2

I'm trying to implement meilisearch api in React native and it is working fine with my simulator and after I publish the app some of the users cannot see the data returning from meilisearch, the error is

{"name":"Invariant Violation","framesToPop":1} 

This is my code

Meilisearch.js

import axios from 'axios';

import { meilisearchConfig } from '../Config';

const MeilisearchApi = async (payload, success, failed) => {
  try {
    const response = await axios({
      method: 'post',
      url: `${meilisearchConfig?.host}indexes/activities/search`,
      data: payload,
      headers: {
        'X-Meili-API-Key': meilisearchConfig?.apiKey,
      },
    });
    success?.(response?.data);
  } catch (err) {
    failed?.(err);
  }
};

export default MeilisearchApi;

This is the normalizer for returning data

import moment from 'moment';
import { IActivity, IByDateGroupFilter } from 'reducers/types';

export const activityNormalizer = (state, { hits, offset }) => {
  const {
    melisearchActivityData: { byDate, dates, all },
  } = state;
  const isRefreshing = offset === 0;

  const newAll = isRefreshing ? hits : [...all, ...hits];
  const datesNew: string[] = isRefreshing ? [] : dates;
  const byDateNew: any = isRefreshing ? {} : byDate;
  const byDateGroup: IByDateGroupFilter[] = [];

  hits.forEach((activity: IActivity) => {
    const date = getFormattedDate(activity.created_at);

    if (byDateNew[date]) byDateNew[date].push({ ...activity });
    else {
      byDateNew[date] = [{ ...activity }];
      datesNew.push(date);
    }
  });

  Object.keys(byDateNew).forEach((key) => {
    byDateGroup.push({
      title: key,
      data: byDateNew[key],
    });
  });

  return {
    dates: datesNew,
    byDate: byDateNew,
    byDateGroup,
    all: newAll,
  };
};

This is how i call my Meilisearch API method

MeilisearchApi(
      {
        q: search,
        filters: filters,
        offset: newOffset,
        limit: PAGE_SIZE,
      },
      ({ hits }: { hits: any[] }) => {
        setDataLoaded(true);
        setMelisearchActivitiesToRedux({ hits, offset: newOffset });
        if (newOffset === 0) {
          sectionList?.current?.scrollToLocation({
            itemIndex: 1,
          });
        }
      },
      (err: any) => {
        setDataLoaded(true);
        log(err)
      },
    );

No Idea how this error happens, when users kill the app and logging again this works fine

Dileepa Chandima
  • 389
  • 4
  • 14

0 Answers0