Why won't NextJS Image elements render on iOS 16 when they are not in the viewport initially?

I opted to implement NextJS for enhanced routing capabilities and image optimization. However, I encountered an issue with certain images failing to load properly on iOS devices. The problem arises within a scrollable horizontal container featuring Product Images.

Some of the images extend beyond the visible area, requiring scrolling to view them.

While everything functions smoothly on web browsers, testing it on Safari on my iPhone (iOS 16) revealed that images outside the visible area remain unrendered. Let me illustrate this further.

Expected result in Chrome Device Tool:

Actual outcome experienced on iOS 16:

An interesting observation is that rotating the phone triggers the rendering of the images.

My implementation involves using the Image/Next component with priority and unoptimized props set to true. I have experimented with both configurations but saw no improvement.

The frontend utilizes the latest version of NextJS exclusively, without additional libraries. The backend consists of an express server solely responsible for providing image pathways. This server operates with Nginx and reverse proxy settings.

This is the provided React code snippet:

import styles from "../styles/ProductItem.module.css";
import priceFormat from "../Helpers/priceFormat";
import Image from "next/image";
import Percentage from "./icons/Percentage";
import { useRouter } from "next/router";

function ProductItem(props) {
  const router = useRouter();

  let marginStyle = {};

  if (props.noLeftMargin) marginStyle.marginLeft = 0;
  if (props.noRightMargin) marginStyle.marginRight = 0;

  return (
    <div
      className={`${styles.itemContainer} ${props.className}`}
      style={marginStyle}
      onClick={() => router.push("/product/" + props.data.id)}
    >
      <div className={styles.imageContainer}>
        <Image
          className={styles.productImg}
          src={props.data.imgSmall}
          width={160}
          height={160}
          alt={props.data.name}
          priority={true}
          unoptimized={true}
        />
        {props.data.salePercentage > 0 && (
          <div className={styles.percentageContainer}>
            <Percentage className={styles.percentageSvg} />
            <div className={styles.percentageOffText}>
              {`%${props.data.salePercentage}`}
              <br />
              OFF
            </div>
          </div>
        )}
      </div>
      <div className={styles.priceLabel}>
        {props.data.salePercentage
          ? `$${priceFormat(
              props.data.price * ((100 - props.data.salePercentage) / 100)
            )}`
          : `$${priceFormat(props.data.price)}`}
      </div>
      {props.data.salePercentage > 0 && (
        <div className={styles.oldPrice}>{`$${priceFormat(
          props.data.price
        )}`}</div>
      )}
      <div className={styles.productName}>
        {props.data.brand} {props.data.name}
      </div>
    </div>
  );
}

export default ProductItem;

Below is the {data} data structure provided via props:

{
    id: "ca629a01-7c58-49f1-949e-fad574c28b3e",
    imgLarge: "/images/products/electronics_smartphone_1.jpg",
    imgSmall: "/images/products/electronics_smartphone_1_small.jpg",
    brand: "Chip",
    options: [
      {
        name: "Storage",
        values: ["64GB", "128GB", "256GB"],
        affectsPrice: 1,
      },
      {
        name: "Color",
        values: ["black", "white", "gray", "red", "gold", "silver"],
        affectsPrice: 0,
      },
    ],
    name: "Smartphone",
    price: 684,
    salePercentage: 0,
    saleReason: "",
    viewCount: 10438,
    soldCount: 4706,
    maincategory: "electronics",
    rating: "3.60",
    warranty: 2,
    availableColors: ["silver", "gold", "red", "white"],
    subcategory: "electronics_smartphone",
    sellers: [....]
}

To test the application, visit: Ertuway.com

Answer №1

When enclosing the Image/Next in a div and applying the filter:drop-shadow effect to the div element, it unexpectedly causes rendering issues on Safari browsers. To resolve this problem, just eliminate the filter: drop-shadow property from the CSS styling.

Answer №2

After implementing the width attribute, the image problem was successfully resolved. You can also give it a try by following this example:

<Image src={photo} alt="profile photo" height={300} width={300} />

Answer №3

Eliminate any adjustments made to the overflow-x property in the body,html,#__next elements (or any of their parent elements).

I'm not sure what caused this issue, but it seems like Apple may have made changes in the latest iOS update that led to this problem. (The same website was functioning correctly before.)

Regardless, removing overflow-x: clip from these elements resolved the issue for me.

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

Merging double borders in a div using CSS is essential for creating

Upon examining this sample, it's evident that the borders do not blend together. css: div{ float:left; background-color:moccasin; width:100px; height:100px; border:1px solid tomato; } The number of divs is arbitrary, and only on ...

Is there a way to make Bootstrap 5 load its jQuery plugins right away, rather than waiting for DOMContentLoaded?

After migrating to Bootstrap 5, I noticed that the following code is broken: <script src="https://code.jquery.com/jquery-3.6.0.js"></script> <script src="https://cdn.jsdelivr.net/npm/@popperjs/<a href="/cdn-cgi/l/email-prot ...

When trying to use the `map: texture` with a new `THREE.Texture(canvas)

i'm trying to apply the texture from new THREE.Texture(canvas) to the PointsMaterial, but it's not working as expected. The canvas appears on the top right corner, however, only white points are visible in the CubeGeometry. var texture = new ...

Unable to deploy Firebase functions following the addition of an NPM package

Scenario: I recently tried integrating Taiko into my Firebase web application, similar to Puppeteer. It's worth mentioning that Taiko downloads Chromium for its operations. Challenge: Ever since then, none of my functions are deploying successfully. ...

Population of the global namespace in JavaScript without the need for the 'new'

After watching the Douglas Crockford video on JavaScript, one thing that caught my attention was his explanation of what happens when you forget to use new for a class. He mentioned that doing so would populate the global namespace, which in the browser is ...

Adapting JavaScript functions from IE to work on Firefox and Chrome: A comprehensive guide

I have encountered an issue with a function that retrieves the selected text range within a contenteditable div. While it works perfectly fine in Internet Explorer, it doesn't seem to work in Firefox and Chrome. Could someone kindly provide guidance ...

Image missing aria-label attribute

I am facing an issue with getting the aria-label to display on my image. Despite checking my code, I cannot figure out why it is not working. Any ideas on what might be missing? Here is the code from my NextJS app: The svg in my public folder. <?xml v ...

Package.json failing to enable NodeJS unsafe-perm functionality

Attempting to execute a npm install command with a preinstall script in my package.json. Despite being aware of it being considered an antipattern, I need to run certain scripts as root. The approach works when adding a .npmrc file with the content unsafe ...

Does the notion of "Execution context and the stack" only pertain to web browsers?

Does the concept of "Execution context and the stack" only apply to browsers, or is it also utilized in other environments such as NodeJS? I've crafted 2 statements but unsure if they are accurate: 1- "The environment for JavaScript is not solely the ...

Is it possible to develop a new application using Next.js version 13?

I'm trying to build a Next.js 13 app, but whenever I run the command npx create-next-app demo, it creates the app with Next.js v14 which is not what I want. I also attempted using npx create-next-app@13 demo but had no luck. I couldn't find any s ...

Leveraging an Array of Objects in JavaScript

Need help with my JavaScript code! I want to adjust the date in a Date object by adding specific days and then save it. Here is what I have so far: let orderIdDateCorrectionDict = [ { "orderId": "2020053100", "dayCorrection": -146 }, { "orderId" ...

Troubleshooting Limitation Problem with Bootstrap Multiselect

I recently created a multiselect dropdown menu using Bootstrap Multiselect. I successfully set a limit on the number of options that can be selected (in this case, 5), and once the limit is reached, the additional options become disabled. Everything works ...

Find the time interval between two timestamps and output the difference in UNIX timestamp format

Is there a way to determine the time difference between two dateTime values? One date is provided by the user, while the other is the current time: User-submitted time - current time = difference in Unix timestamp The format for the user-submitted time i ...

Update app content without requiring users to download a new APK

Hey there, I'm new to all of this so I appreciate your patience. I'm working on a video based app and I'm wondering how I can add new videos/content to the app without having users download a new apk. I know I need to host the app on a data ...

Cloudflare disregarding the Cache-Control directives

I have a unique express web server that serves highly dynamic images. These images are then utilized by various websites, which are protected by Cloudflare. On my website, the images are constantly refreshing, just as I intend, every time the page is loa ...

Accessing Facebook through the React create app login

I recently developed a React Webapp using the create-react-app module. My current challenge involves integrating Facebook login, but I'm encountering some obstacles. I am unsure about where to incorporate the Facebook JavaScript SDK asynchronously to ...

NextJS encounters a TypeError while using ChartJS due to its inability to read properties of null, specifically 'useRef'

Recently, I've been working on incorporating graphs using ChartJS into my NextJS application. However, I've encountered some difficulties with rendering them. Despite following several tutorials and articles, I keep encountering the same error. ...

Encountering a hiccup while following the Next.js basic example tutorial

Encountering an error while running the code provided in the Next JS starter tutorial: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1174:13) at Module.load (internal/modules/cjs/loader.js:1002:32) at Function.Module._load ( ...

What about numerical inputs lacking spinners?

Is there a more efficient way for users to input a decimal number like 64.32, and have it be two-way-bound to a property of type number? I attempted to use <input type="number" [(ngModel)]="size"> However, this displays a spinner which isn't ...

How can you deactivate the vue-router for specific routes? Is it possible to operate a single-page application backend while utilizing a non-single-page

I'm currently working on a website/webapp using Laravel 5.3 and Vue 2. Since SEO is crucial, I've decided to keep the frontend/crawlable part of the site in Laravel + Blade, with only minimal sections in Vue 2.0. This way, I can avoid using Ajax ...