Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Short-circuit File and Date constructor access in isObject #4413

Merged
merged 2 commits into from
Dec 13, 2024

Conversation

Hsifnus
Copy link
Contributor

@Hsifnus Hsifnus commented Dec 10, 2024

Reasons for making this change

This change refactors isObject to significantly reduce the frequency of accesses to File and Date by short-circuiting the function with several simple checks prior to running instanceof checks involving the two native classes. The motivation for making this change is explained within the issue this pull request fixes.

fixes #4409

Prior isObject logic

  • If File is defined and the value is an instance of File, return false
  • If Date is defined and the value is an instance of Date, return false
  • Return true if and only if the value is a non-null, non-array object

New isObject logic

  • If value is null or a non-object, return false
  • If value has a lastModified number property and File is defined and the value is an instance of File, return false
  • If value has a getMonth method and Date is defined and the value is an instance of Date, return false
  • Return true if the value if an only if the value is a non-array object

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@Hsifnus Hsifnus force-pushed the short-circuit-isobject branch from 369a526 to 930cfb6 Compare December 10, 2024 05:33
@heath-freenome heath-freenome merged commit 3c5539a into rjsf-team:main Dec 13, 2024
5 checks passed
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.

Performance hit from isObject when updating Form value within qiankun microapp
3 participants