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

Issue: React cannot render objects directly. Received an object of objects instead of an array of objects

As someone who is fairly new to React, I am in the process of fetching data from my Jobly backend. Upon setting the company data received from the backend, I noticed that company.jobs is interpreted as an array of objects. However, when I attempted to assi ...

Icon from Material-UI embedded within internationalized text

Has anyone successfully integrated Material UI icons into i18n translated text? I've added the library and imported it to my parent file. I also included this line in my language JSON file, but unfortunately, it's not working as expected: { &quo ...

Expansive variety of icon buttons in MUI React with a wide selection radius

Struggling to remove the oversized selections on icon buttons, as shown here: See large selection I discovered a solution by adding: component="span" Why does this method work? Is it a glitch? Even when the icon button is standalone without any ...

Closing the Bootstrap 5 Navbar on Click Event

I'm not very familiar with Bootstrap and I came across this code online that involves javascript in html, which I don't fully understand. I want to make the hamburger menu close automatically after selecting an item in the navigation bar, especia ...

Having trouble with applying a custom class to React Bootstrap tabs?

When utilizing the react bootstrap tabs component, I encountered an issue with implementing a custom CSS style for the nav-link element within it using a customized parent class indicator. <Tabs defaultActiveKey="signup_renter" i ...

Send the function with parameters, but do not pass its output

Within my component, there is a need property that holds a static function. This function is executed by middleware to handle asynchronous API calls before rendering the component. Here's an example: static need = [ myFunc(token) ] The issue arise ...

What is the reason for min-content not being compatible with auto-fill or auto-fit?

My confusion lies in the fact that this code snippet works: .grid { display: grid; grid-template-columns: repeat(4, min-content); } Whereas this one does not: .grid { display: grid; grid-template-columns: repeat(auto-fill, min-content); } I am ...

Angular - Enabling the next screen button only after completing multiple selections

Currently, I'm working on a screen where users can select multiple options from a table. The requirement is that they must select at least 3 options before they can proceed. However, I am facing difficulties in implementing this functionality and unsu ...

Aligning text in the middle of a div vertically

Visit the Satoshi Faucet Index here I'm attempting to vertically align the text within the four divs containing sat, bit, mBTC, and BTC. I have tried using display:table-cell; vertical-align:middle; on the divs but unfortunately it isn't havi ...

Naming convention for TypeScript accessors

Expanding on the previous solution When I convert the example object to JSON from the answer above: JSON.stringify(obj) The output is: {"_id":"3457"} If I intend to transmit this data over a service and store it in a database, I prefer not to use the ...

Arrangement of SVGs within one another

I am working on achieving a layout with multiple SVG elements arranged in a specific way. This layout involves a top-level gray box containing several orange boxes, each of which holds red boxes. The width and height of the top-level SVG are known. https: ...

Is there a way to utilize two onChange functions within one component?

I'm having trouble utilizing two onChange functions within the same component. I attempted to combine them, but I ran into an issue because one is using useState and the other is a const function. Below is my code snippet: const signup = () => { ...

Ways to ensure that the height of a div remains consistent across all scenarios

https://i.sstatic.net/6LY1C.png Below is the code snippet, which utilizes bootstrap. I need to set a fixed height for a div that is populated dynamically from a database. The goal is to maintain the height of the div regardless of the content length. If ...

Can the text inside a div be styled to resemble h1 without using an actual h1 tag?

Is it feasible to apply the h1 style to all text within a div without utilizing tags? For instance: <div id="title-div" style="h1">My Title</div> Or a potential solution could be: #title-div { style: h1; //Imports all s ...

A step-by-step guide to customizing MUI CSS within a React component that incorporates MUI elements

Here is a custom Reactjs component I created and used in various components: function CustomSearchBox({ handle, placeholder, inputType, ...props}) { return ( <Box sx={{ display: 'flex', ali ...

What could be the reason for the absence of displayed return data?

After using console.log, I noticed that the data is being displayed correctly. However, the main page is not showing the data as expected. I am unsure of what could be causing this issue. Any assistance would be greatly appreciated. Thank you in advance. ...

Ensure that the hook component has completed updating before providing the value to the form

Lately, I've encountered an issue that's been bothering me. I'm trying to set up a simple panel for adding new articles or news to my app using Firebase. To achieve this, I created a custom hook to fetch the highest current article ID, which ...

TypeScript does not properly validate the types of defaultProps

When working with TypeScript 3.0, I consulted the documentation at https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html The recommendation is to use static defaultProps: Pick<Props, "name"> as an explicit type annotation ...

dotdotdot.js is only functional once the window has been resized

For my website, I am attempting to add an ellipsis to multiline paragraphs that exceed a certain height. I have incorporated the dotdotdot jquery plugin from here. An odd issue arises when the page is refreshed, as the ellipsis does not appear until I res ...

Creating a personalized input field with automatic spacing for entering a vehicle license plate number

Currently working on creating an input field for vehicle number entry, but facing an issue where pressing the backspace breaks the logic. Any help would be appreciated. https://i.stack.imgur.com/uTK6N.png React.useEffect(()=>{ if(cardNumber.length===2) ...