Skip to content

feat(config): add screenBreakpoints config option - #31502

Open
brandyscarney wants to merge 5 commits into
FW-7285-1-xxlfrom
FW-7285-2-config
Open

brandyscarney wants to merge 5 commits into
FW-7285-1-xxlfrom
FW-7285-2-config

Conversation

@brandyscarney

Copy link
Copy Markdown
Member

Adds a shared breakpoints utility that resolves the screen breakpoints from config, validating each value and falling back to the default per key.

@brandyscarney
brandyscarney added this pull request to stack #31503 September 29, 2026 20:47
@vercel

vercel Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-framework Ready Ready Preview Oct 9, 2026 6:01pm UTC

Request Review

@github-actions github-actions Bot added the package: core @ionic/core package label Sep 29, 2026
Comment thread core/src/utils/media.ts Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@brandyscarney
brandyscarney marked this pull request as ready for review October 2, 2026 13:49
@brandyscarney
brandyscarney requested a review from a team as a code owner October 2, 2026 13:49
@brandyscarney
brandyscarney requested review from ShaneK and removed request for a team October 2, 2026 13:49

@ShaneK ShaneK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, great work! Just a couple of optional nits, no worries if you'd rather leave them.

Comment thread core/src/utils/config.ts
Comment thread core/src/utils/test/breakpoints.spec.ts Outdated
Comment thread core/src/index.ts Outdated
Comment thread core/src/utils/breakpoints.ts Outdated
Comment on lines +244 to +255
export const getScreenBreakpoints = (): ScreenBreakpoints => {
const configValue = config.get('screenBreakpoints');

if (cachedBreakpoints !== undefined && configValue === lastConfigValue) {
return cachedBreakpoints;
}

lastConfigValue = configValue;
cachedBreakpoints = resolveScreenBreakpoints(configValue);

return cachedBreakpoints;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Returning the cached object lets any caller change it, so getScreenBreakpoints().md = 600 moves the md breakpoint for every component on the page
  • Typing the return as Readonly only covers TypeScript callers, while Object.freeze also covers plain JS apps
Suggested change
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;
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +363 to +369
if (breakpointQueries === undefined) {
breakpointQueries = SCREEN_BREAKPOINT_NAMES.map((breakpoint) =>
window.matchMedia(getScreenBreakpointMediaQuery(breakpoint)!)
);

breakpointQueries.forEach((query) => query.addEventListener('change', notifyBreakpointSubscribers));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch was successfully deployed

1 active deployment
Preview — aff0e7b6 Deployed Oct 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants