Repository navigation
feat(config): add screenBreakpoints config option - #31502
brandyscarney wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
matchBreakpoint was moved to breakpoints.ts since that file name makes it more clear, but I can re-add this file if you think it makes more sense here.
ShaneK
left a comment
There was a problem hiding this comment.
Looks good to me, great work! Just a couple of optional nits, no worries if you'd rather leave them.
6c03b65 to
6ac0035
Compare
6ac0035 to
b59c31d
Compare
| export const getScreenBreakpoints = (): ScreenBreakpoints => { | ||
| const configValue = config.get('screenBreakpoints'); | ||
|
|
||
| if (cachedBreakpoints !== undefined && configValue === lastConfigValue) { | ||
| return cachedBreakpoints; | ||
| } | ||
|
|
||
| lastConfigValue = configValue; | ||
| cachedBreakpoints = resolveScreenBreakpoints(configValue); | ||
|
|
||
| return cachedBreakpoints; | ||
| }; |
There was a problem hiding this comment.
- Returning the cached object lets any caller change it, so
getScreenBreakpoints().md = 600moves themdbreakpoint for every component on the page - Typing the return as
Readonlyonly covers TypeScript callers, whileObject.freezealso covers plain JS apps
| export const getScreenBreakpoints = (): ScreenBreakpoints => { | |
| const configValue = config.get('screenBreakpoints'); | |
| if (cachedBreakpoints !== undefined && configValue === lastConfigValue) { | |
| return cachedBreakpoints; | |
| } | |
| lastConfigValue = configValue; | |
| cachedBreakpoints = resolveScreenBreakpoints(configValue); | |
| return cachedBreakpoints; | |
| }; | |
| export const getScreenBreakpoints = (): Readonly<ScreenBreakpoints> => { | |
| const configValue = config.get('screenBreakpoints'); | |
| if (cachedBreakpoints !== undefined && configValue === lastConfigValue) { | |
| return cachedBreakpoints; | |
| } | |
| lastConfigValue = configValue; | |
| cachedBreakpoints = Object.freeze(resolveScreenBreakpoints(configValue)); | |
| return cachedBreakpoints; | |
| }; |
| if (breakpointQueries === undefined) { | ||
| breakpointQueries = SCREEN_BREAKPOINT_NAMES.map((breakpoint) => | ||
| window.matchMedia(getScreenBreakpointMediaQuery(breakpoint)!) | ||
| ); | ||
|
|
||
| breakpointQueries.forEach((query) => query.addEventListener('change', notifyBreakpointSubscribers)); | ||
| } |
There was a problem hiding this comment.
getScreenBreakpoints picks up a config that arrives late, but these listeners are only built once, so they keep the default widths. With { md: 720 }, a grid that subscribed before the config arrived won't update at 720. Could we rebuild them when getScreenBreakpoints re-resolves and notify subscribers? The spec doesn't catch this because no onBreakpointChange test sets a custom config.
Adds a shared breakpoints utility that resolves the screen breakpoints from config, validating each value and falling back to the default per key.