The CSS module is disappearing before the Framer Motion exit animation finishes when the path changes

Source Code Repository: https://github.com/qcaodigital/cocktail_curations
Live Site:

I recently deployed my NextJS project to Netlify and everything seems to be working fine, except for one issue. Each page has an exit animation (currently set to change opacity from 1' to '0' in 1000ms). To test, I reduced the exit animation time for the "Contact Page" to 0ms.

It appears that the SCSS.module is being removed before the animation completes, as you can still see the markup on the page during the time when the animation should be happening without any styles applied.

Answer №1

Fix Module: import this to your main component

import Router from 'next/router'

export const resolveTransitionIssue = (delay: number): void => {
  Router.events.on('beforeHistoryChange', () => {
    const nodes = document.querySelectorAll('link[rel=stylesheet], style:not([media=x])')
    const copies = [...nodes].map((el) => el.cloneNode(true) as HTMLElement)

    for (let copy of copies) {
      copy.removeAttribute('data-n-p')
      copy.removeAttribute('data-n-href')

      document.head.appendChild(copy)
    }

    const handler = () => {
      Router.events.off('routeChangeComplete', handler)

      window.setTimeout(() => {
        for (let copy of copies) {
          document.head.removeChild(copy)
        }
      }, delay)
    }

    Router.events.on('routeChangeComplete', handler)
  })
}

Use the resolveTransitionIssue function with a parameter indicating how long you want the css/scss.module (in ms) to last before removal (e.g., duration of page transitions).

resolveTransitionIssue(1000)

This code is sourced, so apologies if it doesn't suit your requirements.

Answer №2

Encountered a similar issue that was also discussed on GitHub. To resolve it (luckily, my project is small), I deleted all files [name].module.css and transferred the styles to a global stylesheet

Answer №3

Opt for inline CSS rather than opting for CSS Modules.

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

Position a div element on top of Google Maps to create a floating

Currently working on a website and attempting to add shadows over Google Maps by using a <div> element for a shadow effect: Unfortunately, the desired effect is not being achieved. This is the current CSS code in use: html { height: 100% } body ...

Show an error notification if the mobile device does not meet the requirements for jquery mobile version

Currently, I am in the process of creating a website using HTML5, CSS3, and jquerymobile. My goal is to have an error message appear saying "Your mobile browser does not support this application" if the page is not rendering correctly or if the jquery mobi ...

Combining Django Bootstrap input-group-addon with Model Form for seamless field integration

Currently, I am displaying my Django form in the following manner: <form action="/student/" method="post"> {% csrf_token %} {% bootstrap_form form %} <input type="submit" value="Launch" class="btn btn-primary"/> </form> I ha ...

We encountered a sudden termination of JSON data while parsing near '...w2BfLygJAO9ZBvYIqZTld'

Encountered an error when trying to initialize a new React App. command: $npx create-react-app yourblog Node --version v12.16.2 npx --version 6.14.4 Click here to view the error ...

Browsing through dual snap points simultaneously on Google Chrome

I'm currently developing a website that incorporates scroll snapping for 3 viewport-sized <section> elements set up like so: html, body { scroll-behavior: smooth; scroll-snap-type: mandatory; scroll-snap-points-y: repeat(100vh); scrol ...

The popup is unable to remain in the center of the screen because the background page keeps scrolling back to the top

Whenever I click a button to open a popup window, the page unexpectedly scrolls to the top. It's frustrating because if I'm at the bottom of the page and press the 'submit' button, the popup doesn't display in the center as intende ...

The CSS transition duration is not being applied properly on the initial transition effect

Looking to create a dynamic set of sliding divs that can be triggered with the press of a button. Each div will contain a thumbnail image and accompanying text. The goal is to enable the user to navigate through the content by clicking the left or right bu ...

Guide to incorporating checkboxes and onChange events in React applications

I need some clarification on these codes as I am a bit confused. Can you please let me know if my understanding is correct? I have listed them out below. The state variable isChecked initially has the value of false. This means that the checkbox is cu ...

Using the $.get() method within a loop of .each(), retrieve the specific $(this) value within the $.get function

Apologies for the poorly worded question, but I'm struggling to find a better way to phrase it. I'm currently working with a .each() loop where I need to update a specific css() parameter of each item in the loop. However, I can't seem to g ...

Apologies, we are experiencing a server error. TypeError: Unable to access the 'map' property of an undefined

I'm struggling to grasp the concept of fetching external data using server-side rendering with the getServerSideProps method. In particular, I am facing difficulties with the search functionality and how to handle the returned data. As someone who is ...

Guide on crafting a scrollable and touch-responsive grid using CSS and JavaScript

I am seeking guidance on creating a grid with a variable number of columns and rows. It should be contained within a separate div and should not interfere with other objects or alter the parent's size. The grid needs to be square and I am currently u ...

What is the best way to create a stylish outward curve effect for an active sidebar item using just CSS

After spending a week learning frontend designs, I attempted to replicate a design from Dribble. However, I've been struggling with recreating the active style on the sidebar due to the outward curve. If anyone could provide guidance on achieving thi ...

Utilizing NextJS and localstorage: Best practices for seamless integration

"use client"; import { usePathname } from "next/navigation"; import Image from "next/image"; import i18n from "../../app/i18n"; import styles from "./styles.module.css"; import BR from "../../assets/im ...

New to CSS/Ruby - What causes two adjacent buttons to have varying sizes?

The varying sizes of my search and login buttons located beside each other are puzzling me. Could it be due to the fact that the search button is enclosed within a submit_tag argument while the login button is not? If this is indeed the case, how can I mak ...

Combining multiple dictionaries into one single dictionary array using JavaScript

In my JavaScript code, I am working with an array that looks like this: arr = [{"class":"a"},{"sub_class":"b"},{"category":"c"},{"sub_category":"d"}] My goal is to transform t ...

Converting a DataFrame to a JSON series using Python

I have a Python Dataframe that looks like this: My goal is to convert it into the JSON object format below, so I can send it to the frontend for plotting on highcharts: name: 'netflix', data: [ [1579996800, 67], [1580601600, 70], ...

How can I implement the `withAuth` design using `iron-session` in Next.js?

I really appreciate the design pattern used in next-auth → https://next-auth.js.org/getting-started/client#custom-client-session-handling The main concept is to set .auth = true and then verify it in _app.tsx like this: export default function App({ C ...

Is Next.js API considered a back-end technology?

Even though Next.js is typically considered a front-end framework, I have found that when I use its API it is able to handle responses and manage routes similar to what a traditional back-end would do. This has led me to question whether Next.js's API ...

What's the best way to show floating point numbers in a concise format while also maintaining the ability to perform calculations within this Vue app?

I'm currently developing a compact calculator application using Vue 3 and implementing some custom CSS. For the most part, everything seems to be functioning correctly, except for when the results are long numbers that extend beyond the display limit ...

Remove the underline from a link in Next.js

Is there a way to locate the line beneath the word within the link? <Link style={{ textDecoration: "none", color: "white" }} href={`/products/${id}`} > More Details </Link ...