Skip to content

Conversation

@Janpot
Copy link
Member

@Janpot Janpot commented Feb 17, 2025

Removes the default data-testid prop when in production. Adds a section to the migration guide and remove the docs that describe this behavior.

@Janpot Janpot added the scope: icons Changes related to the icons. label Feb 17, 2025
@mui-bot
Copy link

mui-bot commented Feb 17, 2025

Netlify deploy preview

@material-ui/core: parsed: -0.07% 😍, gzip: -0.13% 😍

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against dd6fa25

@EfstathiadisD
Copy link

EfstathiadisD commented Feb 18, 2025

Terrible! Terrible folks! What on earth are y folks doing over there?

@Janpot
Copy link
Member Author

Janpot commented Feb 18, 2025

What on earth are y folks doing over there?

@EfstathiadisD Trimming unnecessary bloat from production code, these test ids end up in server rendered html and potentially clash with user defined test ids.

The component still spreads props on the svg element, so a user defined testid will still end up there. Wouldn't that suffice for your use-case? Could you elaborate a bit more on why you think this should be kept?

@EfstathiadisD
Copy link

What on earth are y folks doing over there?

@EfstathiadisD Trimming unnecessary bloat from production code, these test ids end up in server rendered html and potentially clash with user defined test ids.

The component still spreads props on the svg element, so a user defined testid will still end up there. Wouldn't that suffice for your use-case? Could you elaborate a bit more on why you think this should be kept?

It was one of the most efficient ways to write tests!

We all had 1 way to test them, and now people are gonna start renaming it how they like.

I think options hurt the ecosystem more than strictness. I understand that it might not be beneficial but consider an approach where this Icons can have predefined data-testId.

Like a flag or something. And I suppose this goes to V7 as a breaking change. In our repo it about 35 instances of this.

And our apps aren't huge! Just IMHO!

@Janpot
Copy link
Member Author

Janpot commented Feb 18, 2025

Like a flag or something.

Would it work for you if we add the test id only when process.env.NODE_ENV is not 'production'?

@Janpot Janpot changed the title [icons] Remove default data-testid [icons] Remove SvgIcon data-testid in production Feb 18, 2025
@mnajdova
Copy link
Member

Add the test id only when process.env.NODE_ENV is not 'production'?

I think this is a good compromise, I can't imagine anyone wanting to have these in production.

@Janpot Janpot marked this pull request as ready for review February 18, 2025 14:00
@EfstathiadisD
Copy link

Like a flag or something.

Would it work for you if we add the test id only when process.env.NODE_ENV is not 'production'?

Yeah. That makes lots of sense! Thank You!!🙏

@zannager zannager requested a review from siriwatknp February 19, 2025 09:55
@Janpot Janpot merged commit 8da0670 into mui:master Feb 19, 2025
22 checks passed
NooBat pushed a commit to NooBat/material-ui that referenced this pull request Feb 20, 2025
@hbj
Copy link

hbj commented Mar 29, 2025

Hello! Removing it only for production is very confusing because if you run e2e tests with the production version as we do you might have your tests running locally when implementing them, because you use the dev version, but have your tests fail in CI that uses the prod version. If you forget about this point you might have to wait for the CI to finish to figure out the issue. This also makes debugging very difficult unless you're aware of this subtlety.

Is it possible to add some flag to opt out of removing the test-id?

@Janpot Janpot deleted the remove-icon-testid branch March 31, 2025 09:01
@AndyAlkhawand
Copy link

AndyAlkhawand commented Dec 5, 2025

Add the test id only when process.env.NODE_ENV is not 'production'?

I think this is a good compromise, I can't imagine anyone wanting to have these in production.

Add the test id only when process.env.NODE_ENV is not 'production'?

I think this is a good compromise, I can't imagine anyone wanting to have these in production.

Many companies use NODE_ENV = production for staging environments, such as QA, UAT etc.. This update can break cypress tests that validate MUI icons using the data-testid, that run on staging environments.

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

Labels

scope: icons Changes related to the icons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants