-
Notifications
You must be signed in to change notification settings - Fork 785
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(renderer): prevent infinite loops for NaN #3254
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rwaskiewicz
added a commit
that referenced
this pull request
Feb 24, 2022
this commit adds tests to `src/runtime/parse-property-value.ts`. specifically it adds tests to the case where we parse numbers using the `parsePropertyValue` function. these tests were originally a part of #3254, but were removed from the pull request. the reason for which is the fix implementation in 3254 ultimately went on a different layer of abstraction then `parse-property-value`. these tests were originally written with a different fix in mind; rather than scraping them, they've been updated to fit the current implementation of the function under test
14 tasks
rwaskiewicz
added a commit
that referenced
this pull request
Feb 24, 2022
this commit adds tests to `src/runtime/parse-property-value.ts`. specifically it adds tests to the case where we parse numbers using the `parsePropertyValue` function. these tests were originally a part of #3254, but were removed from the pull request. the reason for which is the fix implementation in 3254 ultimately went on a different layer of abstraction then `parse-property-value`. these tests were originally written with a different fix in mind; rather than scraping them, they've been updated to fit the current implementation of the function under test the intent with this pull request is not to cover every corner case of `parseFloat`, which is the underlying implementation for this section of the code. rather it is to document how the function under test will respond to inputs across different types and of different numeric values
rwaskiewicz
force-pushed
the
rwaskiewicz/fix-nan-inf-loop
branch
from
February 24, 2022 22:58
15092d7
to
8114b43
Compare
this commit is intended to prevent infinite loops when rendering the following specific scenario: - the prop is of type "number" - the prop is reflected (`@Prop({reflect: true})` - the value received by the prop is NaN in this commit, we add an additional safeguard to `set-value` to validate that both the previous and new values on the prop are not NaN. this check is required as equality checks in javascript where NaN is on both the left and right hand side of the operator will always return false. this change is intentionally placed as this layer of abstraction in order to handle cases where a value may be set on a prop from different places in the code base. for instance, we must consider cases where: - a reflected camelCase prop 'myProp' is reflected as 'my-prop' - a reflected single word prop 'val' is reflected as 'val' (no transformation)
rwaskiewicz
force-pushed
the
rwaskiewicz/fix-nan-inf-loop
branch
from
February 24, 2022 23:00
8114b43
to
a03a847
Compare
ltm
approved these changes
Feb 28, 2022
rwaskiewicz
added a commit
that referenced
this pull request
Feb 28, 2022
this commit adds tests to `src/runtime/parse-property-value.ts`. specifically it adds tests to the case where we parse numbers using the `parsePropertyValue` function. these tests were originally a part of #3254, but were removed from the pull request. the reason for which is the fix implementation in 3254 ultimately went on a different layer of abstraction then `parse-property-value`. these tests were originally written with a different fix in mind; rather than scraping them, they've been updated to fit the current implementation of the function under test the intent with this pull request is not to cover every corner case of `parseFloat`, which is the underlying implementation for this section of the code. rather it is to document how the function under test will respond to inputs across different types and of different numeric values
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm test
) were run locally and passednpm run test.karma.prod
) were run locally and passednpm run prettier
) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
GitHub Issue Number: N/A
What is the new behavior?
this commit is intended to prevent infinite loops when rendering the
following specific scenario:
@Prop({reflect: true})
in this commit, we add an additional safeguard to
set-value
tovalidate that both the previous and new values on the prop are not NaN.
this check is required as equality checks in javascript where NaN is on
both the left and right hand side of the operator will always return
false.
this change is intentionally placed as this layer of abstraction in
order to handle cases where a value may be set on a prop from different
places in the code base. for instance, we must consider cases where:
transformation)
Does this introduce a breaking change?
Testing
The karma tests added to this PR should suffice as tests (as they emulate the original reproduction in #2828). To run them:
npm ci && npm run build
cd test/karma && npm run build.app
to build the testsnpm start
within the karma directory to spin up the local webserverwww
, then select any of the tests we added hereOther information
I ran into some issues mocking out (specifically spying on) certain methods to add unit tests here. I need to do a little research, as I'm pretty sure it's related to how we use tsconfig paths in our source and that not mapping back correctly to the test transpilation steps. For now, I think the new Karma tests should suffice. Added this research to the backlog as STENCIL-385