Skip to content

Add regression test for resultEqualityCheck receiving a cleared WeakRef - #763

Open
veksa wants to merge 1 commit into
reduxjs:masterfrom
veksa:test/result-equality-cleared-weakref-750
Open

Add regression test for resultEqualityCheck receiving a cleared WeakRef#763
veksa wants to merge 1 commit into
reduxjs:masterfrom
veksa:test/result-equality-cleared-weakref-750

Conversation

@veksa

@veksa veksa commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Closes #750

The bug reported in #750 was actually fixed a while back in cea19b9, where the old lastResult?.deref?.() ?? lastResult line was replaced with the maybeDeref helper. Once that shipped in 5.2.0 the runtime error is gone.

What was still missing is a test that locks the behavior in, so we don't accidentally regress it again. The original reporter tried to write one but couldn't get garbage collection to trigger reliably.

This adds that test. It builds a memoized selector, produces one result and registers it with a FinalizationRegistry, then drops every strong reference so the result becomes collectible. Instead of a single global.gc() call (which was flaky and just timed out), it runs a few GC passes and yields to the event loop between them until the finalization callback fires. At that point lastResult is a cleared WeakRef, and the test asserts that a subsequent call never hands that raw WeakRef to resultEqualityCheck.

The test is skipped when global.gc isn't exposed. I confirmed it fails against the old ?? lastResult logic and passes with the current maybeDeref implementation, so it genuinely guards the fix.

@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy Preview for reselect-docs canceled.

Name Link
🔨 Latest commit 01f28f6
🔍 Latest deploy log https://app.netlify.com/projects/reselect-docs/deploys/6a67065000d321000825a529

@codesandbox-ci

codesandbox-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@aryaemami59 aryaemami59 changed the title Add regression test for resultEqualityCheck receiving a cleared WeakRef Add regression test for resultEqualityCheck receiving a cleared WeakRef Jul 26, 2026
@veksa
veksa force-pushed the test/result-equality-cleared-weakref-750 branch from a51decb to 01f28f6 Compare July 27, 2026 07:18
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.

resultEqualityCheck gets a WeakRef instead of derefed previous value.

1 participant