mui / mui/material-ui

[system] Wrong order of media queries with custom values.

Open
#36,714 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: system type: bug
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Steps to reproduce 🕹

Link to live example: https://codesandbox.io/s/brave-wilson-fz8zzg

Steps:

  1. In the demo change window size to see the described bug
  2. Check the inspector that media queries are in fact in wrong order. Media query with custom value has higher order.
Current behavior 😯

Media query with custom breakpoint value has higher order.

Expected behavior 🤔

Using breakpoint in this way:

const Styles = (theme) => ({
    [theme.breakpoints.up(750)]: {
       width: '75vw',  // style N1
    },
    [theme.breakpoints.up('md')]: {
       width: '50vw',  // style N2
    },
})

I am expecting, that for device with width more than md (900px) (growing from mobile to desktop) will be applied style N2. But it is overridden by style N1.

Context 🔦

The similar issue was reported in #16528, but it has different context. Here I use function in order to build styles.

Your environment 🌎
System: OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish) CPU: (8) x64 Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz Memory: 6.60 GB / 15.51 GB Container: Yes Shell: 5.1.16 - /bin/bash Binaries: Node: 18.7.0 - ~/.nvm/versions/node/v18.7.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v18.7.0/bin/yarn npm: 8.15.0 - ~/.nvm/versions/node/v18.7.0/bin/npm Managers: Apt: 2.4.6 - /usr/bin/apt pip3: 22.2.2 - ~/.local/bin/pip3 Utilities: Make: 4.3 - /usr/bin/make GCC: 11.3.0 - /usr/bin/gcc Git: 2.34.1 - /usr/bin/git Virtualization: Docker: 20.10.17 - /usr/bin/docker IDEs: Nano: 6.2 - /usr/bin/nano VSCode: 1.70.1 - /usr/bin/code Languages: Bash: 5.1.16 - /usr/bin/bash Perl: 5.34.0 - /usr/bin/perl Python: 3.10.6 - /usr/bin/python Python3: 3.10.6 - /usr/bin/python3 Browsers: Chrome: 104.0.5112.79 Firefox: 111.0.1
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox and reproduce the behavior by changing the window size, then inspect the generated media queries in the browser inspector. Trace the theme.breakpoints.up(750) and theme.breakpoints.up('md') entry points to determine why their order is wrong. Done means the md query overrides the 750px query above 900px.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.