-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[PWA-586] Country/Region Occasionally Resets initialValue #2456
Conversation
|
Performance Test Results The following fails have been reported by WebpageTest. These numbers indicates a possible performance issue with the PR which requires further manual testing to validate. https://pr-2456.pwa-venia.com : LH Performance Expected 0.85 Actual 0.52, LH Best Practices Expected 1 Actual 0.92 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically speaking loading
is the only change right? At first, I thought you removed the initialValue
and validate
props but they are fed into the same component inside ...inputProps
or ...regionProps
. Nice.
Would it be possible to add snapshot tests to the country and region components?
Using
Absolutely! Since we do tests in QA, is this code approved to get started on those? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved. Awaiting snapshot tests for Country and Region components.
@revanth0212 - Added tests that are a bit coupled to these form input components, but wanted to put out a challenge, maybe you've solved this problem before. I really really tried to mock the jest.mock('../../Field', () => props => <mock-Field {...props} />);
jest.mock('../../Select', () => 'Select'); I don't know what's different about the |
|
QA Pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding tests @tjwiebell. A couple of comments, you can ignore them if you feel you have addressed those already.
tree.update(<Component {...props} />); | ||
}); | ||
|
||
expect(mockSetValue).toHaveBeenCalledWith(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(mockSetValue).toHaveBeenCalledWith(); | |
expect(mockSetValue).toHaveBeenCalled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in ab0adc9.
|
||
const { data, error, loading } = useQuery(getRegionsQuery, { | ||
variables: { countryCode: country } | ||
}); | ||
|
||
let formattedRegionsData = []; | ||
let formattedRegionsData = [{ label: 'Loading Regions...', value: '' }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a test for this? Looks like it is being manipulated in multiple places. A set of tests can be of help.
I see you have added snapshot tests but more verbal ones can be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in ab0adc9
useEffect(() => { | ||
if (country) { | ||
if (hasInitialized.current) { | ||
regionFieldApi.setValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe indicate this is a reset with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reset()
from the fieldApi
had the behavior I wanted, so I made that change in ab0adc9, which should be more self documenting. Thanks for pointing out there was much more to that API than the docs lead you to believe.
Re-verified after changes, looks good. |
Description
There's an empty cache state for these components where the form they are attached to renders before the backend results for the list of available options in these dropdown components is returned. When that backend response arrives, the components re-render with those options, but the initialValue from the parent context doesn't apply, and the component renders an empty selection. I've more commonly seen this in the Region component, where State will be cleared out after an initial flash of the component.
Once this component has loaded once in the app, it's not reproducible, since the components first render now uses that immediate cached response.
Repro:
/cart
apollo-cache-persist
entryExpected: State data entered is selected in dropdown
Actual: State is empty
Related Issue
Acceptance
Verification Stakeholders
Specification
Verification Steps
⬆️ Repro steps can be used for verification above ⬆️
Screenshots / Screen Captures (if appropriate)
Checklist