-
Notifications
You must be signed in to change notification settings - Fork 158
fix: set default breakpoint without computing #1821
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
Conversation
🦋 Changeset detectedLatest commit: 6620ba5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ PR title follows Conventional Commits specification. |
BundleMonFiles updated (2)
Unchanged files (12)
Total files change +173B +0.03% Final result: ✅ View report in BundleMon website ➡️ |
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.
Looks good. Can you just check if it is working correctly for scenario where we do want mobile to be detected after initial load.
Also should we call those functions in useIsomorphicLayoutEffect now to detect it a bit earlier before layout shifts?
expect(result.current.matchedBreakpoint).toBe('base'); | ||
expect(result.current.matchedDeviceType).toBe('mobile'); |
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.
It should continue to detect mobile and base no? just not detect it on the initial client render 🤔
matchedDeviceType, | ||
}; | ||
const [breakpointAndDevice, setBreakpointAndDevice] = useState<BreakpointAndDevice>({ | ||
matchedBreakpoint: undefined, |
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.
Now that we're not calling those functions here, are we sure they are getting called somewhere in useEffect or useLayoutEffect to make sure correct device is set on load?
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6620ba5:
|
…nto fix-breakpoint-defaults
Let's add SSR test for useBreakpoint? Not sure why this mismatch wasn't caught in other components. also can you link the slack thread that sumit raised? |
It wasn't caught because the target changes from SSR(desktop because node) to client(mobile). doesn't happen when you open the SSR app on desktop itself. I've mentioned that in the description. adding SSR test won't help either here. Can't change the breakpoints from node(desktop) to client(mobile) in the jest |
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.
Looks good to me. Tiny change in test description I guess?
packages/blade/src/utils/useBreakpoint/useBreakpoint.web.test.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: rzpcibot <tools+cibot@razorpay.com>
This was a nasty bug and can be discovered when we do SSR and open the application on mobile device. There was a class mismatch between server and client leading to mismatch in DOM trees between server and client
The above code will compute
matchedBreakpoint: undefined
andmatchedDeviceType: 'desktop'
when run on server and now since the useState is a function it gets evaluated again on the client side and now if the client side is being opened on mobile device the useState will returnmatchedBreakpoint: s
andmatchedDeviceType: 'mobile'
so the initial render if it had anything that changes because the screensize eg: typography the DOM tree will be different between server and client