The Problem
Currently, UI Extensions only provide MaybeResponsiveConditionalStyle props for responsive behavior. This approach has major limitations:
Performance Issues: We’re forced to render multiple component trees just for simple changes:
// Current inefficient approach
<View display={{
default: 'block',
conditionals: [{ conditions: { viewportInlineSize: { min: 'small' } }, value: 'none' }]
}}>
<ComplexComponentTree />
</View>
<View display={{
default: 'none',
conditionals: [{ conditions: { viewportInlineSize: { min: 'small' } }, value: 'block' }]
}}>
<SlightlyDifferentComplexComponentTree />
</View>
No Programmatic Control: There’s no way to know which viewport we’re currently on, preventing:
- Device-specific navigation (app links on mobile, web links on desktop)
- Conditional logic based on screen size
- Different analytics/API behaviors per device
Proposed Solution
Add a useViewport() hook that works like window.matchMedia():
import { useViewport } from '@shopify/ui-extensions-react/customer-account';
function MyExtension() {
const { current } = useViewport();
// current: 'extraSmall' | 'small' | 'medium' | 'large'
if (current === 'extraSmall') {
return <MobileOptimizedComponent />;
}
return <DesktopComponent />;
}
Real Use Cases
Performance: Single render path instead of multiple trees
const config = current === 'extraSmall'
? { columns: 1, showImages: false }
: { columns: 2, showImages: true };
Smart Navigation: Route based on device
const handleClick = () => {
if (current === 'extraSmall') {
window.location.href = `some-native-app-link`; // Native app
} else {
window.location.href = `link-to-a-web-based`; // Web interface
}
};
Device-Aware Analytics: Track with device context
analytics.track('product_viewed', {
device_type: current,
viewport_category: current === 'extraSmall' ? 'mobile' : 'desktop'
});
Why This Matters
This would solve fundamental performance and UX limitations while providing familiar, web-standard APIs. The current MaybeResponsive system forces inefficient patterns and prevents building truly responsive, device-aware extensions.
Would love to see this prioritized - it’s a common pain point for anyone building complex responsive UI extensions!