You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
v8.x
Current Behavior
currently if we try to access the content instance in the constructor (ie: before ionic initializes) it breaks with TypeError: Cannot read properties of undefined (reading 'scrollToBottom')
this error happens because content is null at that point
Expected Behavior
to not break cause this messes up with CI, even though it might be developer's fault trying to access it before initialization.
After reviewing your reproduction case and issue, I do not believe this is a concern of Ionic Framework. Accessing an ElementRef in Angular before the view has rendered will always produce undefined.
In your reproduction you should be checking that content is defined before accessing the method on it.
this.content?.scrollToBottom();
In your test spec, due to the conditions of your app, you would need to mock the state of the class that you are testing for:
test('increment and scroll to bottom',async()=>{constmockScrollToBottom=jest.fn();instance.content={scrollToBottom: mockScrollToBottom}asany;instance.increment();fixture.detectChanges();expect(instance.value()).toBe(421);expect(mockScrollToBottom).toHaveBeenCalled();});
I believe with these considerations we can close: #29410.
Prerequisites
Ionic Framework Version
v8.x
Current Behavior
currently if we try to access the
content
instance in the constructor (ie: before ionic initializes) it breaks withTypeError: Cannot read properties of undefined (reading 'scrollToBottom')
this error happens because
content
is null at that pointExpected Behavior
to not break cause this messes up with CI, even though it might be developer's fault trying to access it before initialization.
Steps to Reproduce
https://github.com/stewones/ionic-content-scroll-issue
nx serve app
nx test app
Code Reproduction URL
https://github.com/stewones/ionic-content-scroll-issue
Ionic Info
Additional Information
a workaround would be checking for the scroll element existence from the client, but IMO this should be baked into the core.
The text was updated successfully, but these errors were encountered: