layer5 icon indicating copy to clipboard operation
layer5 copied to clipboard

[Bug] Invalid CSS selector prevents responsive styling in Buf Protocols article

Open vedant21-ctr opened this issue 3 weeks ago • 1 comments

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: flex
  • margin: auto
  • float: none

Steps to Reproduce

  1. Visit https://layer5.io/blog/cloud-native/rethinking-protocol-buffers-with-buf/
  2. Open browser DevTools.
  3. Inspect the .problem-image element (<img class="problem-image" src="..." />) and its computed styles.
  4. Inspect the generated stylesheet for the invalid .hcbQMB if(mediaQuery.matches) .problem-image selector.
  5. 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;
    }
}

vedant21-ctr avatar Nov 13 '26 14:11 vedant21-ctr

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!

ayushbuilds-code avatar Nov 13 '26 14:11 ayushbuilds-code