[Bug] Invalid CSS selector prevents responsive styling in Buf Protocols article
Description
The problem image in the Buf Protocols article does not receive its intended responsive styling on viewports 768px and wider.
Actual Behaviour
The styled-components CSS template in src/collections/blog/2021/2021-04-24-buf-protocols/BufProtocol.style.js contains JavaScript-like conditional statements directly inside the CSS template literal:
var mediaQuery = window.matchMedia('(min-width: 768px)');
if(mediaQuery.matches) {
.problem-image {
display: flex !important;
margin: auto !important;
float: none;
}
}
Because these statements are not interpolated as JavaScript (i.e. not wrapped in ${...}), styled-components emits invalid CSS selector syntax.
The production stylesheet on https://layer5.io/blog/cloud-native/rethinking-protocol-buffers-with-buf/ contains a rule:
.hcbQMB if(mediaQuery.matches) .problem-image {
display: flex !important;
margin: auto !important;
float: none;
}
The browser's CSS parser cannot recognize if(mediaQuery.matches) as a valid selector, so the entire rule is discarded.
Expected Behaviour
On screens 768px and wider, .problem-image should apply:
display: flexmargin: autofloat: none
Steps to Reproduce
- Visit https://layer5.io/blog/cloud-native/rethinking-protocol-buffers-with-buf/
- Open browser DevTools.
- Inspect the
.problem-imageelement (<img class="problem-image" src="..." />) and its computed styles. - Inspect the generated stylesheet for the invalid
.hcbQMB if(mediaQuery.matches) .problem-imageselector. - Resize the viewport above 768px and observe that the intended responsive styling is not applied.
Suggested Fix
Replace the JavaScript conditional in src/collections/blog/2021/2021-04-24-buf-protocols/BufProtocol.style.js with a standard CSS media query:
@media (min-width: 768px) {
.problem-image {
display: flex !important;
margin: auto !important;
float: none;
}
}
Opened PR #8400 with a clean fix replacing the raw JS conditional with standard CSS @media (min-width: 768px), along with adding accessible alt text to the image. Tests and formatting are all verified and green — ready for review!