-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
bug: ion-range throws: Cannot read properties of undefined. #29667
Comments
@averyjohnston It seems that this bug was introduced with your change in #27375. With this change the component will always throw an error if set via JS, which includes frameworks like Angular. Because you cannot set all required properties in one shot. You'll always have and should handle Reviewers: @liamdebeasi @sean-perkins |
Thank you for reporting the issue! Could you please reproduce the problem in a StackBlitz example for us? I've created one that you can use: https://stackblitz.com/edit/angular-wx2c3i?file=src%2Fapp%2Fmodal-example.component.ts In the top left of the StackBlitz example, you can |
Thanks for the issue! This issue has been labeled as Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed. If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue. For a guide on how to create a good reproduction, see our Contributing Guide. |
Here is a demo on Stackblitz to reproduce the error: In this case, I would use a type guard like this to make sure you can safely use the value as a number. export const isSafeNumber = (input: unknown): input is number => {
return typeof input === 'number' && !isNaN(input) && isFinite(input);
}; Seriously, these invalid values need to be handled for input. Otherwise it will throw errors like the following or causes to unexpected behavior. Btw, this is the first time in many years that I get such error behavior in Ionic.
Btw, it's weird that when the modal is first opened, no error is thrown. Although it is undefined. Maybe an Angular input thing? Because of the default value. But whatever... It doesn't matter. Handling such invalid values is the right solution. For my case, I'll ensure that step has an safe number in ngOnInit. But this can happen to all values (min, max, step, etc). A value like undefined should be handled as not exist. MVC frameworks like Angular bind properties to HTML attributes whose value can be "undefined". It seems that the default value of Stencil (step = 1) is overriden in this case. |
Again a short explanation: |
Prerequisites
Ionic Framework Version
v8.x
Current Behavior
Since the latest Ionic version v8 (coming from Ionic 6), the ion-range throws errors.
This error occurs at least on Angular. I think it's because following:
updateRatio
: min/max possible undefinedupdateRatio
: max/value possible undefinedupdateRatio
: min/value possible undefinedThis results in runtime error and invisible range component. It's maybe because a framework like Angular creates the attibutes for binding even if the value is not yet ready. In this case, it's undefined first. But idk. Anyway, it would be a good practice to treat undefined, wouldn't it?
Expected Behavior
Handle
undefined
. It's possible that one value can be undefined.Steps to Reproduce
All values are inputs (
Input
Angular decorator). ThehasRange
method returns true if both values (min, max) are available (not undefined) and not equal (min !== max).In my case I created a modal with componentProps which goes to Angular component inputs.
NOTE: I already catch undefined values. It seems that this problem comes from Ionic framework.
Code Reproduction URL
https://codepen.io/fudom/pen/ZENZxdq
But not really good reproducible in a playground. Just handle undefined values!
Ionic Info
Ionic Angular 8.2.3
Additional Information
The text was updated successfully, but these errors were encountered: