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

What is the best way to vertically center a caption when an image is being hovered over

I'm facing an issue with aligning my caption vertically inside a div when hovering. The image within the div is larger than the div, and I want the caption to be at the center of the div. HTML <div class="container-fluid"> <div id="pag ...

Styling <Link> component with styled-components: A step-by-step guide

Utilizing the Link component from @material-ui/core/Link in my TypeScript code was initially successful: <Link href="#" variant="body2"> Forgot? </Link> However, I am exploring the transition to styled-components located in a separate file. ...

Accessing the current window dimensions using CSS

I'm experimenting with a way to set the background of the entire body element. <html> <head><head/> <body> <div class="wrapper"></div> </body> </html> How can I determine the height and width of the cu ...

The element 'x' is implicitly bound with a type of 'any'

I've been exploring the world of Nextjs and TypeScript in an attempt to create a Navbar based on a tutorial I found (). Although I've managed to get the menu items working locally and have implemented the underline animation that follows the mou ...

The updated version of Angular from 13 to 16 has implemented a new default value for primary colors

I recently upgraded my angular (+material-ui) system from version 13 to 16, and encountered an issue with the primary color of my custom theme. It seems that the value is no longer being recognized and defaults to blue. After updating the angular version, ...

`On mobile devices, the Bootstrap button no longer displays focus changes once clicked.`

When clicking a primary bootstrap button, it changes its background color to blue on mobile devices. For example, the first button appears normal and the second one turns blue after clicking. However, this background effect disappears when clicking anywhe ...

How can I eliminate the border from the last child in a row within a responsive framework?

Put simply, I am trying to target not only the last child in a parent div, but also the last item in a row that adjusts based on screen size. I have a row of 4 elements (divs) with borders on all but the last one using :last-child. However, when the screen ...

Create an input box with a designated class

When I click the button in my HTML and JavaScript code below, I am able to dynamically add a text field and radio button. This functionality is working properly. However, I also want the newly generated text field to have the same font size and appearance ...

Issue: 502: {“errorMessage”: ” The process exceeded the time limit of 10.01 seconds”} on nextJS website hosted on Netlify

Hello there, I've got a setup with Strapi CMS running on Heroku for the backend, and a NextJS frontend hosted on Netlify. I've been encountering a frustrating issue where my website sometimes displays a 502 error message like this: {“errorMess ...

Initiate the React project by executing the command to start React Native development

Typically, I start my projects using npm start, but one time I accidentally ran npx react-native start and all the installation process for React Native completed. Now, I'm not sure if I need to worry about this or if I should remove React Native. If ...

To determine the class of an element and reveal its parent if the class is present

Typically, the parent element remains hidden by default. However, upon clicking a specific element, its child might gain a class called "selected". How can I check for this class and then display the entire list if it is present? <ul style="display: ...

How can Swipe support help you slide a menu back in?

For implementing swipe support on my landing page carousel, I included jquery.mobile.custom.min.js. However, I am facing a challenge with adding swipe support to "close" the menu. Essentially, swiping left should have the same effect as clicking the butto ...

What is the best way to stop a jQuery function from applying titles extracted from the first row th's in thead's to multiple tables in a document?

My circumstances: I am new to jQuery and Stack Overflow, seeking assistance for my website project. The challenge: Building a website using Bootstrap 3.3.6 with intricate data tables that need to be stacked dynamically on mobile devices using CSS. It is c ...

Using separate video sources for mobile and desktop devices causes issues

I am currently seeking a solution that allows me to play two different video files on each device (desktop and mobile). I have created a function using react hooks that determine whether the viewport is desktop or mobile. Below is the code snippet for the ...

Aligning text vertically to the top with material UI and the TextField component

Seeking guidance on adjusting vertical alignment of text in <TextField /> const styles = theme => ({ height: { height: '20rem', }, }); class Foo extends React.component { ... <TextField InputProps={{ classes: ...

What is the best method to retrieve the current time in minutes using the Timer component?

I have integrated the react-timer-hook library into my Next.js application to display a timer. The timer is functioning correctly, but I am encountering an issue where I cannot retrieve the current elapsed time in minutes during the handle form event. My g ...

Step-by-step guide on building native modules for creating react-native android applications

I was eager to develop a Redis client from React Native and decided to explore some tutorials. After successfully building it, I am now inquiring about how to package it as a service on npm. I'm looking to understand the key files in my project and ...

Position the Bootstrap Modal at the start of the designated DIV

When using a Bootstrap Modal to display larger versions of thumbnails in a photo gallery, there can be some challenges. The default behavior of Bootstrap is to position the modal at the top of the viewport, which may work fine in most cases. However, if th ...

What is the method for displaying the value of a textarea?

I am relatively new to the world of coding, but I have already delved into HTML, CSS, and basic DOM scripting. My goal is simple - I want to create a comment box where people can leave messages like in a guestbook. However, when I input text and click on ...

The mysterious height phenomenon when setting the width of a list item with jQuery

Consider a basic ul and li setup similar to this: <div id="middle"> <ul> <li> <a> bridal </a> </li> //.... </ul> </div ...