Skip to content

Conversation

@flt3150sk
Copy link
Contributor

🐛 Bug Fix: Fix upsert not working after external end() call

Description

This pull request fixes a bug where calling upsert() after ending the previous upsert instance externally via MyCallable.end() fails to create a new instance.

The issue occurred because the internal $upsertPromise variable was not being cleared when end() was called externally, causing subsequent upsert() calls to attempt updating a non-existent instance instead of creating a new one.

Root Cause

When an upsert instance is created, it stores the promise in $upsertPromise. This variable is used to determine whether to create a new instance or update an existing one.

The problem:

  • When ending via the component's internal call.end()$upsertPromise is cleared ✅
  • When ending via external MyCallable.end()$upsertPromise was not cleared ❌

This caused the next upsert() call to:

  1. Find $upsertPromise still exists
  2. Try to update the existing instance
  3. Fail to find it in the stack (because it was already removed)
  4. Return the old promise without creating a new instance

Solution

Modified the end() method to clear $upsertPromise when:

  • Ending all calls (no specific promise target), OR
  • Ending a specific promise that matches $upsertPromise

Changes

  • Fixed: react-call/src/createCallable/index.tsx - Clear $upsertPromise in end() method
  • Added: tests/src/upsert.test.tsx - Test case to reproduce and verify the fix

All tests now pass: ✅ 5 passed (including the new test case)

Related Issues

Fixes #71

Checklist

  • Bug fix implemented
  • Test case added to prevent regression
  • All existing tests still pass
  • No breaking changes

Notes for Reviewers

  • The fix is minimal and focused on the root cause
  • Fully backward compatible - no API changes
  • All 5 upsert tests pass, including the new regression test

@vercel
Copy link

vercel bot commented Dec 20, 2025

@flt3150sk is attempting to deploy a commit to the desko27's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Dec 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
react-call Ready Ready Preview, Comment Dec 22, 2025 9:11am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue while calling *.upsert() after *.end()

2 participants