0

Our team uses Google Tag Manager and Optimizely in our Nextjs application. Both of these tools use CSS selectors to target sections of the page. We are using CSS Modules

Every time we deploy code, our class name are hashed and will break the selectors because the classname has been changed.

<div class="Button_test__1iM5u">

How can I add a classname along side of the hash classname? Or something that allows me to have a class that does not get hashed every deployment.

<div class="ButtonTest Button_test__1iM5u">

1 Answer 1

1

TLDR: <div className={`constant-class ${styles.cssModuleClass}`} /> or use aria or data attributes to query.

I figured this would be a common problem as things like e2e/webdriver tests would have a hard time with it too.

This is a similar question, and it seems you can configure either webpack to handle the styles or add a 'constant' className prefix (which you can still query with CSS selectors), which points to this discussion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.