The compatibility issue between Tailwind CSS and Material UI has been identified in the latest version of Next, version 14.0

Currently, I am working with Next 14.0.2 alongside Material UI and Tailwind CSS for my Frontend development tasks. However, I've run into some challenges regarding styling components. One specific issue I faced was when setting a button to navigate to the sign-up form using the Link (next/link) component.

https://i.sstatic.net/IOEEj.png

https://i.sstatic.net/xLTR2.png

<Link
  href={"/user/register"}
  className="transition-all text-gray-200 hover:text-white"
>
  Register
</Link>

Upon clicking the button, it successfully navigated me to the Register page. However, I noticed that when navigating using the Link component, the Register page did not render all Tailwind CSS styles, particularly margin styles like my-2, mx-4, and so on. This behavior can be observed in the first screenshot attached below. On the other hand, if I directly visit the Register page by typing the URL in the browser or refreshing the page after navigation, everything renders correctly as shown in the second screenshot.

The desired outcome is for the Register page to fully compile all Tailwind CSS styles even when accessed via the Link component, not just when visited directly through the URL input. Below is a snippet of my code for the register page:

<TextField
   label="First Name"
   variant="outlined"
   className="w-full md:w-44 my-2"
   {...register("firstName")}
   error={errors.firstName ? true : false}
   helperText={errors.firstName?.message}
 />

 <TextField
  label="Middle Name"
  variant="outlined"
  className="w-full md:w-40 md:mx-4 my-2"
  {...register("middleName")}
  error={errors.middleName ? true : false}
  helperText={errors.middleName?.message}
/>

<TextField
  label="Last Name"
  variant="outlined"
  className="w-full md:w-44 my-2"
  {...register("lastName")}
  error={errors.lastName ? true : false}
  helperText={errors.lastName?.message}
/>

Additionally, here is an excerpt from my tailwind.config.ts file:

import type { Config } from "tailwindcss";

const config: Config = {
  content: [
    "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/client/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {
      backgroundImage: {
        "gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
        "gradient-conic":
          "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
      },
    },
  },
  plugins: [],
};

export default config;

To provide better context, I have shared a link to the CodeSandbox showcasing this issue: https://codesandbox.io/p/sandbox/relaxed-jang-5vhkd4

If anyone could offer their assistance on resolving this encountered issue, it would be greatly appreciated.

Answer №1

The issue has been successfully addressed by enclosing the theme in

<StyledEngineProvider injectFirst>{children}</StyledEngineProvider>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the need to restart the server every time a style change is made?

I'm currently developing a NextJS application that utilizes PurgeCSS. It's quite frustrating because every time I tweak the classname of a component, I have to restart the server. Here is a snippet from my postcss.config.js: plugins: [ [ ...

To fill the remaining white space, add an underline after the last line of text

I'm struggling to implement a SCSS/CSS styling concept where I need to add a solid line before or after the last line of a heading. The challenge is that the width of the last line varies based on the screen size. I am open to any suggestions. Here&a ...

Utilize API within an array to enable Ionic to display a PDF in a document viewer

Recently diving into the world of Angular and Ionic, I've come across some interesting API data: [{"ID":"1","Title":"Maritime Safety","File_Name":"9c714531945ee24345f60e2105776e23.pdf","Created":"2018-11-07 17:36:55","Modified":"2018-11-07 17:36:55"} ...

In Angular, make a call to a second API if the first API call times out after a specified period

In the event that my API does not return data within 5 seconds, I need to call a different one. Attempted implementation: this.service.returnData1(param1, param2) .pipe(timeout(5000), finalize(() => this.callSecondApi())) .subscribe( data => { ...

Is it possible to store a JWT token in local storage when working with Next.js?

We are considering using Next.js for our application, with a focus on client-side rendering for data fetching. The API we will be interacting with is external and requires authentication to access specific user dashboard content. While the homepage will ...

What is the process for setting up 127.0.0.1 with port 127.0.0.1:8000 in the .httaccess file?

Is there a way to set up a sub domain in Node.js while running on port 127.0.0.1:8000? Here is the .httaccess code: RewriteEngine On RewriteRule ^$ http://127.0.0.1:8080/ [P,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Rewrit ...

How to toggle visibility of child elements in an HTML template using Angular 4+

I'm currently working on incorporating a basic "hover over a comment to display a reply button" feature in my angular application. Is it possible to create this effect using template reference variables exclusively? Something like this... <mat-l ...

Tips for ensuring that images fully occupy my carousel slides

I am struggling to make my images fit properly within the slides. Here is the code snippet I have tried along with some screenshots: <div className="relative h-24 w-20 sm:h-44 sm:w-100 md:h-44 md:w-60 flex-shrink-0"> <Carousel showThu ...

Unable to display notifications within the modal using Notistack MUI in React JS

Hey there, I'm currently utilizing react in combination with MUI. To display notifications, I've integrated a library called notistack. My goal is to show an error message in a dialog if there's a failure in the API response. Here's the ...

The current issue I am facing is that the option disabled with value="null" selected is not being shown on the screen. Instead, it should display as "Choose User Types"

https://i.sstatic.net/JqZ7O.png <select class="form-control" id="ddSelectaTopic" onchange="if(this.value==='') {this.style.color='#999'} else {this.style.color='#333'}" [(ngModel)]="us ...

Implementing a dependent <select> within an HTML table is a useful feature to enhance user experience and organization of

I have set up a table with editable columns where values can be selected from a drop-down menu. I achieved this by using HTML select. The options in the 'Category tier 2' column are based on the selection made in the 'Category tier 1' c ...

Step-by-step guide to successfully loading the MUI Material-UI Blog template in Vite

I inserted the Material MUI example into StackBlitz using ViteJS. After that, following the README.md for the Templates > Blog section, it stated: Copy the provided files into your project, or one of the sample projects. Ensure that your project has t ...

Troubleshooting error in Angular 5 with QuillJS: "Parchment issue - Quill unable to

I've been working with the primeng editor and everything seems fine with the editor itself. However, I've spent the last two days struggling to extend a standard block for a custom tag. The official documentation suggests using the quilljs API fo ...

The error message "Multiple children error occurs when an empty link in Next.js

Is there a way to successfully implement a <Link /> element without any content inside it in my application? Surprisingly, when I don't provide any content, I encounter the multiple children error, even though the opposite seems to be happening. ...

Error: The hook call is invalid and can only be made within the body of a function component in ReactJS

Hello everyone, I am currently facing an issue with saving the lat and lng variables in the state within a hook. When trying to do so, I encounter the following error message: "Error: Invalid hook call. Hooks can only be called inside the body of a functio ...

Warning: ReactJS has detected a transition in the input type of TextField from uncontrolled to controlled

I encountered the following error message: Warning: TextField is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontr ...

Is there a way to change the color of a checkbox (both the box and font) in the disabled state using material ui

When using Material UI v4.9.12, it is possible to create a customized checkbox with a specific color that remains fixed: const GreenCheckbox = withStyles({ root: { color: green[400], '&$checked': { color: green[600], }, ...

Exploring the functionality of Next.js with Bootstrap 5 modals

Greetings, I have been trying to implement Bootstrap 5 without using react-bootstrap or reactstrap for my modal creation. However, I keep encountering this error: TypeError: undefined is not an object (evaluating 'this._element.classList') I ha ...

The TypeScript extension of a type from an npm package is malfunctioning

I am utilizing the ws package to handle WebSockets in my Node.js project. I aim to include a unique isHealthy attribute to the WebSocket class. The approach I have taken is as follows: // globals.d.ts import "ws" declare module "ws" { ...

Tips on creating a responsive material-ui for reactjs applications

Can you recommend a tool to use for designing react components based on the material used? You might want to check out http://www.material-ui.com - it's great for reactjs, although it lacks a responsive grid feature You could also consider https://g ...