Skip to content

fix: getData function should only change when getOptions changes - #166

Merged
mcnulty-fp merged 6 commits into
mainfrom
fix/INTER-1277-stable-getdata
Jun 16, 2025
Merged

fix: getData function should only change when getOptions changes #166
mcnulty-fp merged 6 commits into
mainfrom
fix/INTER-1277-stable-getdata

Conversation

@mcnulty-fp

Copy link
Copy Markdown
Contributor

Updates the useVisitorData hook to only return a new getData
function when the getOptions parameter is semantically different.
Previously, the getData function would be recreated if the
getOptions parameter was a different object instance but otherwise
equivalent to the last invocation.

The fix stores the getOptions parameter as a property of the state to
ensure that the value used as a dependency in the getCallback call
only changes when the semantics of the options for the get call
change. The state is updated using a pattern to update the state of
a component during a render by guarding that state update with a
conditional. More information about this pattern can be found in the
React docs:

https://react.dev/reference/react/useState#storing-information-from-previous-renders

The usePrevious utility was no longer used so it was removed.

A new unit test is also added that validates the expected behavior of
the getData function returned by useVisitorData.

Fixes #132
Fixes INTER-1277

Updates the `useVisitorData` hook to only return a new `getData`
function when the `getOptions` parameter is semantically different.
Previously, the `getData` function would be recreated if the
`getOptions` parameter was a different object instance but otherwise
equivalent to the last invocation.

The fix stores the `getOptions` parameter as a property of the state to
ensure that the value used as a dependency in the `getCallback` call
only changes when the semantics of the options for the `get` call
change. The state is updated using a pattern to update the state of
a component during a render by guarding that state update with a
conditional. More information about this pattern can be found in the
React docs:

https://react.dev/reference/react/useState#storing-information-from-previous-renders

The `usePrevious` utility was no longer used so it was removed.

A new unit test is also added that validates the expected behavior of
the `getData` function returned by `useVisitorData`.

Fixes #132
Fixes INTER-1277
@mcnulty-fp mcnulty-fp self-assigned this Jun 3, 2025
@github-actions

github-actions Bot commented Jun 3, 2025

Copy link
Copy Markdown
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
91.71% (-0.16% 🔻)
188/205
🟢 Branches
81.48% (-0.66% 🔻)
44/54
🟡 Functions
70.59% (-1.11% 🔻)
36/51
🟢 Lines
91.67% (-0.27% 🔻)
165/180

Test suite run success

20 tests passing in 5 suites.

Report generated by 🧪jest coverage report action from 65d4946

Show full coverage report
St File % Stmts % Branch % Funcs % Lines Uncovered Line #s
🟢 All files 91.7 81.48 70.58 91.66
🟢  src 94.44 90.32 60 93.61
🟢   detect-env.ts 92.3 86.66 100 91.3 15,85
🟢   env.ts 100 100 100 100
🟢   env.types.ts 100 100 100 100
🟡   fpjs-context.ts 80 100 0 80 38
🟡   get-env.ts 75 0 100 75 9-10
🟢   index.ts 100 100 0 100
🟢   ssr.ts 100 100 100 100
🟢   use-visitor-data.ts 97.82 100 87.5 97.29 81
🟢  src/components 90.66 75 86.66 92.75
🟢   fpjs-provider.tsx 88.52 69.23 83.33 91.22 112,118-123,142-144
🟢   with-environment.tsx 100 100 100 100
🟢  src/utils 81.81 57.14 83.33 76.47
🟡   assert-is-truthy.ts 66.66 0 100 66.66 3
🟡   to-error.ts 75 100 100 75 6
🟢   wait-until.ts 86.66 60 75 80 10-12
Comment thread src/use-visitor-data.ts Outdated
Comment thread src/use-visitor-data.ts Outdated
JuroUhlar
JuroUhlar previously approved these changes Jun 4, 2025

@JuroUhlar JuroUhlar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR! Appreciate the detailed explanatory comments in the test
Posted one nit, feel free to disregard and merge

TheUnderScorer
TheUnderScorer previously approved these changes Jun 4, 2025

@TheUnderScorer TheUnderScorer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left one nit-pick comment 🙂

Comment thread src/use-visitor-data.ts Outdated
@mcnulty-fp
mcnulty-fp dismissed stale reviews from TheUnderScorer and JuroUhlar via 1eed663 June 4, 2025 12:33
TheUnderScorer
TheUnderScorer previously approved these changes Jun 4, 2025
Comment thread src/use-visitor-data.ts Outdated
JuroUhlar
JuroUhlar previously approved these changes Jun 4, 2025
Co-authored-by: Juraj Uhlar <juro.uhlar@gmail.com>
@github-actions

github-actions Bot commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

This PR will create a minor release 🚀

2.7.0 (2025-06-04)

Features

  • bump @fingerprintjs/fingerprintjs-pro-spa to ^1.3.2 (d477427)

Bug Fixes

  • getData function should only change when getOptions changes (d02eac0), closes #132

Performance Improvements

  • use Object.is comparison before doing deep equals (cd1f70d)

Documentation

  • README: mention immediate: false explicitly, improve formatting (f1d03e2)

Build System

@mcnulty-fp
mcnulty-fp requested a review from necipallef June 11, 2025 15:06
@necipallef

Copy link
Copy Markdown
Contributor

I like the solution and tests that cover it. Great job and great first PR!

@mcnulty-fp
mcnulty-fp merged commit 1b8bf2b into main Jun 16, 2025
@mcnulty-fp
mcnulty-fp deleted the fix/INTER-1277-stable-getdata branch June 16, 2025 18:59
@fingerprint-dx-team

Copy link
Copy Markdown

🎉 This PR is included in version 2.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

4 participants