Skip to content

optimisticData not working after upgrading to Expo 53 #4129

Open
@marcelofarias

Description

@marcelofarias

Bug report

Description / Observed Behavior

The same code that worked with Expo 52 is not working with Expo 53

Repro Steps / Code Example

void createPost({
  post: dto,
}, {
  optimisticData: data && [{
    ...dto,
    createdAt: now,
    updatedAt: now,
    userId: userId,
    id: 'optimistic-id',
  }, ...data],
  rollbackOnError: true,
  onError: (error) => {
    console.error('Error creating post:', error);
  },
});
export function useCreatePost(vacationId: string | null) {
  const { mutate } = usePosts(vacationId);
  return useSWRMutation(`/vacations/${vacationId}/posts`, createPost, {
    onSuccess: (post) => mutate(addTrailing(post), false),
    onError: (error) => console.error('Failed to create post:', error),
  });
}

A console.log in a component that depends on posts reveals that it is not re-rendered until after the server-side mutation completes.

const { data: posts } = usePosts(vacationId);
console.log('rendered', posts?.length);

Additional Context

SWR version 2.3.3

Metadata

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