React-Native-Web generates default classes for inline styles and erroneously applies them in a jumbled sequence

Currently working on a project involving react native web and NextJS. I have encountered an issue with inline styles in React that seems to be caused by RN-Web.

It appears that there is a mechanism within the framework that automatically generates classes for commonly used styles, such as:

.r-borderWidth-rs99b7 {
    border-width: 1px;
}

While this may optimize performance, it results in the styles being applied in the wrong order and occasionally duplicating them.

Take a look at my code snippet below:

<TouchableOpacity
            style={{
              width: '100%',
              padding: 8,
              borderRadius: 32,
              borderColor: '#aaa',
              flexDirection: 'row',
              alignItems: 'center',
              borderWidth: 1,
            }}
            onPress={() => console.log('pressed')}
          >
...
</TouchableOpacity>

Upon compilation by NextJS, the output HTML looks like this:

element.style {
    align-items: center;
    border-color: rgb(170, 170, 170);
    border-radius: 32px;
    flex-direction: row;
    padding: 8px;
    transition-duration: 0s;
    width: 100%;
    -webkit-box-align: center;
    -webkit-box-orient: horizontal;
... (additional styles) ...
}

.css-view-1dbjc4n {
... (default view styles) ...
}

.r-borderWidth-rs99b7 {
... (border-width style) ...
}

.css-view-1dbjc4n {
... (duplicate default view styles) ...
}

Some odd observations include:

  • Duplication of the default View style
  • The separate declaration of my border-width style into its own class
    • This behavior specifically occurs when using multiple elements with inline border-width styles, suggesting some form of optimization.
  • Incorrect order of applying the View style above the border width style

If anyone has insights or solutions regarding this peculiar issue before I reach out to the react-native-web and NextJS repositories, your input would be greatly appreciated.

Answer №1

Finally figured it out!

After scouring through the github issues for NextJS and react-native-web, I stumbled upon this problem that perfectly described what I was facing.

Although the problematic library had been fixed years ago, with some trial and error and heavy use of this resource,

https://gist.github.com/necolas/8ee958917db65542784b60323ca6c4bc

I managed to pinpoint the issue to a specific code snippet. Eliminating it from the application resolved all CSS issues.

import { SafeAreaProvider } from 'react-native-safe-area-context'
<SafeAreaProvider>...</SafeAreaProvider>

To be honest, I can't even remember why I initially added SafeAreaProvider at this point. It appears to be necessary for a non-native SafeAreaView, but the built-in SafeAreaView in RN + RN-Web is functioning perfectly fine for me.

If anyone else encounters similar setbacks, I hope this response guides you towards the right solution path.

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

Gitlab's Next.js build does not cache images from the public folder during the build process

Currently, I have set up a CI/CD pipeline on Gitlab. The process involves building a Next.js application and packaging the .next directory as well as the package.json file to create an artifact that can be uploaded to AWS S3. Everything seems to be worki ...

``There seems to be an issue with background size not functioning properly in

I have successfully implemented a body background image with full width following your previous questions and answers. However, I encountered an issue on Mozilla browser where the image is not scaling to full width. Here is the CSS code I am using: backgr ...

Styling images side by side with CSS in Internet Explorer

I've encountered a CSS dilemma. I have a collection of images that I want to present side by side using an unordered list within a fixed width container. The goal is to have 3 images per row before moving on to the next set of 3 images. Each list ite ...

The dropdown menu items spill out beyond the confines of the container

I'm currently facing some challenges and struggling to find a solution. Unfortunately, I haven't been able to find any guidance on this issue. Important: To view the output, click on "Run snippet" and make it full screen by clicking on the hamb ...

Arranging Bootstrap divs vertically and then horizontally in mobile view

My website layout is relatively straightforward. It consists of a header at the top, a navigation bar with an image inside a column on the left, and the main content displayed on the right side. https://i.stack.imgur.com/yYzaG.png For mobile responsive vi ...

Is there a way to prevent a link from activating when I click on one of its internal elements?

Within a div nested inside an "a" tag (specifically in Link within next.js), there is another div labeled as "like." When clicking anywhere within the main div, the intention is for it to redirect to the destination specified by the "a" tag. However, if th ...

How can I conceal text using css in specific situations without risking a penalty from search engines?

Currently, I'm developing an illustration tool that needs to be visually appealing to users, while also being accessible to screen readers and search engines. Below is the HTML code I'm working with: <span class="card">A new idea is presen ...

I'm working with Angular 12, Bootstrap 5, and ngPrime, and I'm looking to overlap a p-dialog with another element in my project

Is there a way in Angular 12 with Bootstrap 5 using ngPrime to overlap a p-dialog over any other element without using z-index and CSS, solely relying on PrimeNG? I have tried using z-index with: .my-class{ z-index: 2147483647 !important; } However, ...

Can someone please tell me how to see if the "do not disturb" feature is activated on either an iPhone or an Android app?

My current project involves developing mobile applications for both iOS and Android using React Native. One of the features I am looking to implement is the ability to check the status of the "do not disturb" setting in the user's phone settings. This ...

The Next.js build process encountered an error when building due to an issue with plotly.js (The build failed with a ReferenceError: self is

Whenever I attempt to build the Next.js app for production using the yarn build command, I encounter the following error. Strangely enough, everything works perfectly fine on the development server when using the yarn dev command. The app employs the react ...

Tips for customizing MUI PaperProps using styled components

I am trying to customize the width of the menu using styled components in MUI. Initially, I attempted the following: const StyledMenu = styled(Menu)` && { width: 100%; } `; However, this did not have any effect. After further research, I ...

Troubles with z-index: issues arise when combining relative and absolute positioned divs

Struggling with my z-index arrangement here. In a nutshell, I have an absolute div positioned beneath a relative div called container. Inside the container, there are three divs: left, center, and right, all with absolute positioning. I am trying to get ...

Tips for preventing CSS animation from reverting back to its initial position

After transforming 2 div tags into blocks, I created a code that causes the blocks to move outwards. The issue I'm facing is that they return to their original position after moving. I want the two blocks in the animation to move out to the sides and ...

Bootstrap - placement of label to the left of the checkbox

Here is an example of a checkbox I am working with: <div class="form-check"> <input class="form-check-input" type="checkbox" value="" id="defaultCheck1"> <label class="form-check-label" for="defaultCheck1"> Default checkbox < ...

defiant underscore refusing to function

I'm currently working on a text editor, but I'm facing an issue with the remove underline functionality that doesn't seem to be working as expected. For reference, you can check out a working code example here: jsfiddle Below is the part of ...

Copy the style of a chosen element and apply it to another element

One of the challenges I'm facing involves a dynamic span element that changes based on color selection: <span class="color checked" style="background-color: #ff0000">Red</span> In addition, I have an image element wit ...

Activate a Dropdown Menu by Clicking in a React Application

I have a collapsible feature where you can click to expand or collapse a dropdown. Currently, the dropdown can only be clicked on where the radio button is located. I want the entire area to be clickable so that users can choose the dropdown by clicking an ...

Tips for creating a navigation bar that bypasses body padding in HTML and CSS

I have set padding in my 'body' tag, but I want my top navigation bar to cover the entire page without being affected by it. I attempted to fix this by setting the width to 100% and using negative padding and margin values, but it did not work a ...

Deploying a NextJS blank page in production build exclusively within a Docker environment

Encountering a peculiar issue that surfaced unexpectedly on December 7th, 2021 around midday EST. The problem revolves around a NextJS application deployed within a Docker container. After deploying the app in production mode from inside the container, a b ...

What is the best way to set the date defaultValue to be empty?

I've developed a basic radio button to display an additional input field when the user chooses yes. I also created a function that will clear the fields if the user selects no. schema.ts: const formSchemaData = z.object({ doesHaveDryRun: z.enum( ...