What causes images to unexpectedly expand to fill the entire screen upon switching routes in Next.js?

I'm in the process of creating a website using Next and Typescript, with some interesting packages incorporated:

  1. Framer-motion for smooth page transitions
  2. Gsap for easy animations

One issue I encountered was when setting images like this:

<Link>
    <div className={`figureContainer ${styles.figureContainer}>
        <Image layout="fill" objectFit="contain" src={lockIcon} alt="scx figure" priority={index === 0? true : false } />
        <div className={styles.menuTitle}>{item}</div>
     </div>
</Link>

and having a base style set in the CSS for the figure container class:

.figureContainer{
  width: 50%;
  height: 100%;
  position: relative;
  transition: filter 0.4s;
}

Upon testing my site locally, everything seemed fine. However, upon deploying it to Vercel and navigating to a different route, I noticed that the images suddenly jumped to fill the screen. It appeared as if the image was positioned absolutely and the body relatively without any other parent elements being tentatively set as relative.

This unexpected behavior only occurred when changing routes on the deployed app at: . Why is this happening and how can it be resolved?

Answer №1

Hello there! I recently encountered a similar issue while using next/image and FramerMotion. However, I managed to resolve it by organizing all the content in my pages/index.tsx file into a separate IndexScreen.tsx file, which I then imported dynamically like this:

import dynamic from 'next/dynamic';

const IndexScreen = dynamic<IndexScreenProps>(() => import('@/screens/indexScreen').then(mod => mod.IndexScreen), {
    ssr: false,
});

I'm not entirely sure if it's the most optimal solution, but it did the trick for me!

If you're interested, here are some helpful resources that guided me through this process: Next.js Dynamic Import Documentation For those using TypeScript: Handling Next.js Dynamic Import Issue

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

Effortlessly Styling Children Elements in Emotion JS When Parent Element is Hovered

This particular query seems to have been posed and resolved in various ways, but the solutions I've come across either do not pertain to Emotion or the responses related to Emotion haven't yielded results for me. I am currently using @emtion/[ema ...

Expanding the input focus to include the icon, allowing it to be clicked

Having trouble with my date picker component (v-date-picker) where I can't seem to get the icon, a Font Awesome Icon separate from the date-picker, to open the calendar on focus when clicked. I've attempted some solutions mentioned in this resour ...

Challenges with Type Casting in TypeScript

Upon reviewing a specific piece of code, I noticed that it is not producing any compile time or run time errors even though it should: message: string // this variable is of type string -- Line 1 <br> abc: somedatatype // lets assume abc is of some ...

`switch tabs visibility based on checkbox selection`

There are 4 tabs available on a JSP page: Tab 1, Tab2, Tab3, and Tab4. Initially, only Tab1 is enabled, allowing users to freely work within that tab. However, Tabs 2, 3, and 4 are disabled, preventing users from accessing their contents. A checkbox is lo ...

Which specific files do I have to edit in order for Laravel to acknowledge a new data type?

Currently, I am honing my skills in Laravel by working on a Laravel Breeze application. One task that I have set for myself is to incorporate a postal code field into the existing User model, including the registration form. To tackle this challenge, I dec ...

Assistance with HTML and CSS to position an image in the corner

I need assistance with positioning a corner image on top of another image. I want the span, which has a small background image, to be in the top left corner of the main image. Below is my code: <div id="wrapkon"> <span style="width: 4px; height: ...

Switch between input and the input is not displayed inline

I've been struggling to align the Toggle button with the input box for quite some time now. I really need them to be inline so that they form a grid properly as everything is dynamic. I have experimented with using a Div on its own instead of a label ...

Stripe: What are the methods available to collect data for storage in my platform?

I'm in the process of integrating Stripe into my platform, which is built using Next.js and Laravel. I'm struggling to understand how I can retrieve the data from a transaction and store it in MY Platform's database. For instance, when a us ...

Utilizing Hooks to extract and nest multiple objects, then transferring them to a fresh list for efficient data manipulation in a React App/Redux setup

Hi all, I am new to Stackoverflow and a Junior Developer seeking assistance. Our team has developed an application for managing Webforms. Each user has multiple Accounts/Departments, with each account/department having its own set of users and manager ...

Having trouble getting TypeScript to install using npm on a Mac?

My goal is to use Typescript as a local dependency by checking it into my devDependencies and using it via an npm script after installing it with 'npm install'. However, when I try this on my machine, I find that Typescript (and webpack-cli as w ...

Ways to modify the appearance of the button within ion-calendar

Looking to customize the styling of ion-calendar classes Attempting to add styles to the ion-calendar-month class, but not seeing any changes take effect. ...

Different approach to handling overflow without using the hidden property in CSS

Having trouble with my CSS layout I've created a form within a fixed 500 pixel width div that is centered on the page using margin auto; To create a table-like structure within the div, I used div elements as rows. Due to varying heights of these ro ...

What is the best way to adjust and filter an array based on a single value?

Here is an array that needs to be modified: [ {name: "test", value: "test", group: 0}, {name: "test1", value: "test2", group: 0}, {name: "test3", value: "test3", group: 1}, {name: "te ...

What is the most effective way to reduce the number of http requests caused by onChange events in Material UI Slider?

Is there a way to optimize my request handling? In my React project, I am currently utilizing Material UI's slider. With the onChange property, I am making HTTP POST requests whenever the slider is moved. Here is a snippet of the code: <Slider ...

Understanding the functionality of imports within modules imported into Angular

I have been scouring through the documentation trying to understand the functionality of the import statement in JavaScript, specifically within the Angular framework. While I grasp the basic concept that it imports modules from other files containing expo ...

What could be causing my CSS code to not function properly within Vue.js?

Having trouble with css in VueJs. I can't seem to figure out what I'm doing wrong. Generally, my scoped style css works fine in vuejs, I can target ids and classes without any issues. The problem arises when trying to change the internal css va ...

How to Extract a Link from JSON Data in React Native

My JSON data is formatted like this: orderData:"<p>Key VVV: 6326233</p> <p>Download link <a title=\"Movie\" href=\"https://play.google.com/store/movies/details/The_Angry_Birds_Movie_2?id=O_RbjOHHpIs&hl=en\" t ...

What is the best way to center the image on a page?

How can I center an image on the screen with a caption? <div id="team-area"> <div class="container"> <div class="row"> <div class="col-12"> <h3 class="main-title">Our Team</h3> < ...

Issues with updating values in Angular form controls are not being resolved even with the use of [formControl].valueChanges

[formControl].valueChanges is not triggering .html <span>Test</span> <input type="number" [formControl]="testForm"> .ts testData: EventEmitter<any> = new EventEmitter<any>(); testForm: FromCo ...

Assist me in temporarily altering the color of menu items in a sequential manner upon the page's loading

Currently, I'm working on a website that features a subtle dark grey menu at the top of every page. The menu is built using HTML and CSS with a list structure. To highlight the corresponding menu item based on the current page, I am utilizing the ID a ...