Skip to content

fix: replace :first-child with :first-of-type in mapbox-gl.css (fixes #13639)#13646

Open
ragini-pandey wants to merge 1 commit intomapbox:mainfrom
ragini-pandey:fix/css-first-child-ssr-warning
Open

fix: replace :first-child with :first-of-type in mapbox-gl.css (fixes #13639)#13646
ragini-pandey wants to merge 1 commit intomapbox:mainfrom
ragini-pandey:fix/css-first-child-ssr-warning

Conversation

@ragini-pandey
Copy link
Copy Markdown

@ragini-pandey ragini-pandey commented Mar 25, 2026

Launch Checklist

  • Make sure the PR title is descriptive and preferably reflects the change from the user's perspective.
  • Add additional detail and context in the PR description (with screenshots/videos if there are visual changes).
  • Manually test the debug page.
  • Write tests for all new functionality and make sure the CI checks pass.
  • Document any changes to public APIs.
  • Post benchmark scores if the change could affect performance.
  • Tag @mapbox/map-design-team @mapbox/static-apis if this PR includes style spec API or visual changes.
  • Tag @mapbox/gl-native if this PR includes shader changes or needs a native port.
  • Tag @mapbox/gl-native if this PR disables any test because it also needs to be disabled on their side.
  • Create a ticket for gl-native to groom in the MAPSNAT JIRA queue if this PR includes shader changes or features not present in the native side or if it disables a test that's not disabled there.

Description

Fixes #13639.

Emotion (a popular CSS-in-JS library) warns at runtime when it encounters CSS rules using the :first-child pseudo-class, because that selector is not safe for server-side rendering (SSR):

The pseudo-class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type".

Change

In src/css/mapbox-gl.css, the single occurrence of :first-child:

/* before */
.mapboxgl-ctrl-group button:first-child {
    border-radius: 4px 4px 0 0;
}

was replaced with :first-of-type:

/* after */
.mapboxgl-ctrl-group button:first-of-type {
    border-radius: 4px 4px 0 0;
}

Why this is safe

All direct children of .mapboxgl-ctrl-group are <button> elements, so :first-child and :first-of-type are semantically equivalent in this context. The change silences the Emotion SSR warning without any visual or behavioural difference.

The :first-child pseudo-class causes Emotion (a CSS-in-JS library) to log
a warning when doing server-side rendering:
  'The pseudo-class ":first-child" is potentially unsafe when doing
   server-side rendering. Try changing it to ":first-of-type".'

Replacing with :first-of-type is semantically equivalent here since
all children of .mapboxgl-ctrl-group are button elements, and also
resolves the SSR warning.

Fixes mapbox#13639
@ragini-pandey ragini-pandey requested a review from a team as a code owner March 25, 2026 11:02
@ragini-pandey ragini-pandey requested review from underoot and removed request for a team March 25, 2026 11:02
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 25, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The pseudo class ":first-child" is potentially unsafe when doing server-side rendering

2 participants