Skip to content

Error: ReferenceError: processOptimistic is not defined #5

Open
@comlaterra

Description

What is the current behavior? The optimistic update seems to not be working properly for the mutate shared below Then, a false-positive error is triggered.

What is the expected behavior? Do not trigger any error if the operation actually finished and consolidated.

Which version of redux-firestore are you using? What about other dependencies? "@taraai/read-write": "^0.0.7-alpha.8",

Minimal demo to reproduce issue (using codesandbox or similar)

export const createAndPopulateSprint = createAsyncThunk(
  'CreateAndPopulateSprint',
  async ({ taskId }: createSprintPayload, { extra, getState }) => {
    const { getFirestore, getTeamId, getUserId, getOrgId } = extra as ExtraAPI;
    const state = getState() as RootStateWithProfile;
    const userId = getUserId(state);
    const teamId = getTeamId(state);
    const orgId = getOrgId();
    const firestore = getFirestore();
    const newSprintId = createFirestoreId(firestore);

    return firestore.mutate({
      reads: {
        uid: () => userId,
        newId: () => newSprintId,
        task: { path: `orgs/${orgId}/tasks`, id: taskId },
        previousSprints: {
          collection: `orgs/${orgId}/sprints`,
          where: [['teamId', '==', teamId]],
          orderBy: ['endDate', 'desc'],
          limit: 1,
        },
      },
      writes: [createSprint],
    });
  },
);

where createSprint is:

export const createSprint = ({ newId, uid, task, previousSprints }: CreateSprintReads): Write[] => {
  const previousSprint = previousSprints[0];
  const startDate = previousSprint.endDate;
  const duration = durationMilliseconds(previousSprint.endDate, previousSprint.startDate);
  const endDate = plusMilliseconds(startDate, duration);
  const sprintNumber = parseInt(getNumberAtEndAsString(previousSprint.sprintName) as string, 10);

  const writes = [] as Write[];
  const sprintWrite = decode<UI.UISprintCreation>(
    {
      id: newId,
      path: previousSprint.path,
      teamId: previousSprint.teamId,
      startDate: toTimestamp(startDate),
      endDate: toTimestamp(endDate),
      createdAt: ['::serverTimestamp'],
      updatedAt: ['::serverTimestamp'],
      sprintName: getNewSprintName(previousSprint, sprintNumber + 1),
      sprintNumber: previousSprint.sprintNumber + 1,
      orderedTaskIds: task ? [task.id] : [],
      totalTasksCount: task ? 1 : 0,
    },
    'UISprintCreation',
    CREATION_DEFAULTS,
  );

  writes.push(sprintWrite as unknown as Write);

  if (task && task?.path) {
    writes.push({
      id: task.id,
      path: task.path,
      sprint: newId,
      updatedBy: uid,
    });
  }

  if (task?.sprint && task?.path) {
    writes.push({
      id: task.sprint,
      path: task.path.replace('/tasks', '/sprints'),
      orderedTaskIds: ['::arrayRemove', task.id],
    });
  }

  return writes;
};

Error caught at cacheReducer.js L.730

Exception has occurred: ReferenceError: processOptimistic is not defined
  at http://localhost:3000/static/js/vendors~main.chunk.js:191751:23
    at Array.reduce (<anonymous>)
    at mutationReadFromCache (http://localhost:3000/static/js/vendors~main.chunk.js:191737:29)
    at translateMutationToOverrides (http://localhost:3000/static/js/vendors~main.chunk.js:190905:61)
    at http://localhost:3000/static/js/vendors~main.chunk.js:191245:36
    at produce (http://localhost:3000/static/js/vendors~main.chunk.js:256304:15)
    at mutation (http://localhost:3000/static/js/vendors~main.chunk.js:191236:39)
    at Object.cacheReducer [as cache] (http://localhost:3000/static/js/vendors~main.chunk.js:191306:10)
    at http://localhost:3000/static/js/vendors~main.chunk.js:198145:37
    at Array.reduce (<anonymous>)
    at http://localhost:3000/static/js/vendors~main.chunk.js:198144:34
    at combination (http://localhost:3000/static/js/vendors~main.chunk.js:449661:29)
    at dispatch (http://localhost:3000/static/js/vendors~main.chunk.js:449388:22)
    at http://localhost:3000/static/js/vendors~main.chunk.js:449067:16
    at http://localhost:3000/static/js/vendors~main.chunk.js:135969:32
    at http://localhost:3000/static/js/main.chunk.js:189686:12
    at http://localhost:3000/static/js/vendors~main.chunk.js:196611:5
    at new Promise (<anonymous>)
    at wrapInDispatch (http://localhost:3000/static/js/vendors~main.chunk.js:196596:22)
    at Object.mutate (http://localhost:3000/static/js/vendors~main.chunk.js:189598:38)
    at Object.mutate (http://localhost:3000/static/js/vendors~main.chunk.js:196659:17)
    at http://localhost:3000/static/js/main.chunk.js:195449:20
    at http://localhost:3000/static/js/vendors~main.chunk.js:137139:65
    at step (http://localhost:3000/static/js/vendors~main.chunk.js:135586:17)
    at Object.next (http://localhost:3000/static/js/vendors~main.chunk.js:135517:14)
    at http://localhost:3000/static/js/vendors~main.chunk.js:135660:61
    at new Promise (<anonymous>)
    at __async (http://localhost:3000/static/js/vendors~main.chunk.js:135639:10)
    at http://localhost:3000/static/js/vendors~main.chunk.js:137098:16
    at http://localhost:3000/static/js/vendors~main.chunk.js:137189:8
    at http://localhost:3000/static/js/vendors~main.chunk.js:449063:18
    at http://localhost:3000/static/js/vendors~main.chunk.js:135969:32
    at http://localhost:3000/static/js/main.chunk.js:189686:12
    at http://localhost:3000/static/js/main.chunk.js:43296:9
    at execute (http://localhost:3000/static/js/vendors~main.chunk.js:367588:3)
    at http://localhost:3000/static/js/vendors~main.chunk.js:367688:14
    at withTimings (http://localhost:3000/static/js/vendors~main.chunk.js:367562:3)
    at Object.drop (http://localhost:3000/static/js/vendors~main.chunk.js:367687:5)
    at http://localhost:3000/static/js/vendors~main.chunk.js:367739:21
    at http://localhost:3000/static/js/vendors~main.chunk.js:367855:9
    at http://localhost:3000/static/js/vendors~main.chunk.js:367446:7
    at http://localhost:3000/static/js/vendors~main.chunk.js:367892:11
    at http://localhost:3000/static/js/vendors~main.chunk.js:367914:7
    at http://localhost:3000/static/js/vendors~main.chunk.js:367799:7
    at http://localhost:3000/static/js/vendors~main.chunk.js:367764:9
    at http://localhost:3000/static/js/vendors~main.chunk.js:367277:9
    at http://localhost:3000/static/js/vendors~main.chunk.js:367063:11
    at http://localhost:3000/static/js/vendors~main.chunk.js:367836:9
    at http://localhost:3000/static/js/vendors~main.chunk.js:367127:9
    at Object.dispatch (http://localhost:3000/static/js/vendors~main.chunk.js:449793:28)

```<br />[Tara Task](https://app.tara.ai/tara-ai/*/tasks/5363)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions