The framer-motion component is seen numerous times throughout

Looking for Guidance & Context?

Currently in the process of developing my personal website, I encountered a challenge with centering this particular container. For reference, you can view a similar example on Aceternity. Upon attempting to modify this centered container, an issue arose where the container would jump unexpectedly.

To address this issue, I have crafted a solution which is available on Replit. This code includes detailed comments explaining how it operates.

The Challenge at Hand

Intermittently (approximately every 1-7 cycles), the animation appears to malfunction by creating two instances of itself momentarily, as depicted below:

View image of bug

Despite numerous attempts to pinpoint the root cause, the glitch persists for just one frame. I am genuinely puzzled and have been grappling with this issue for some time now.

File Location Affected

./src/app/ui/title-section/vanishing-words.tsx
Alternatively, access it through this link.

Possible Explanations

  1. It is plausible that multiple nested motions are inadvertently impacting each other - Although I verified if onExitComplete is being triggered multiple times, there was no evidence supporting this.
  2. Enabling b1 exacerbates the situation. Assessment of secondary bug
  3. Testing conducted on Chrome and Safari browsers yielded consistent results.

Suspected Code Fragment

I have condensed the code to its essential form but continue to encounter issues.

<AnimatePresence
        onExitComplete={() => {
          // 5. The animation loops
          setIsAnimating(false);
        }}
      >
        <motion.div
          key={`${currentWord}-${xOffSet}`}
          style={{
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center'
          }}
          ref={divRef}
          transition={{ duration: 1 }}
          initial={{ x: xOffSet }}
          animate={{ x: 0 }}
        >
          <p>{relativeClause}</p>

          <motion.div
            key={currentWord}
          >
          {/* b1: Swapping out the div above with the one below seems to make it worse */}
          {/* <motion.div
            key={currentWord}
            initial={{
              opacity: 0,
              y: 10,
            }}
            animate={{
              opacity: 1,
              y: 0,
            }}
            transition={{
              duration: 0.4,
              ease: "easeInOut",
              type: "spring",
              stiffness: 100,
              damping: 10,
            }}
            exit={{
              opacity: 0,
              y: -40,
              x: 40,
              filter: "blur(8px)",
              scale: 2,
              position: "absolute",
            }}
          > */}
            
            {currentWord.split("").map((letter, index) => (
              <motion.span
                key={currentWord + index}
                initial={{
                  opacity: 0,
                  y: 10,
                  filter: "blur(8px)",
                }}
                animate={{
                  opacity: 1,
                  y: 0,
                  filter: "blur(0px)",
                }}
                transition={{
                  delay: index * 0.08,
                  duration: 0.3,
                }}
                className={clsx("inline-block", letter === " " && "w-1")}
              >
                {letter}
              </motion.span>
            ))}
          </motion.div>
        </motion.div>
      </AnimatePresence>

Answer №1

  • It is recommended to update the key prop for the motion.div element to ensure proper handling of re-renders in React. By changing keys, React may unmount and remount components, potentially resolving any glitches present.
  • If there are multiple nested motion.div elements with animations, conflicts or unexpected behavior may arise. Simplifying the structure and animations could help mitigate these issues.

The codebase appears to be functioning correctly on my end. Feel free to reach out if you have any questions.

<AnimatePresence
  onExitComplete={() => {
    setIsAnimating(false);
  }}
>
  <motion.div
    key={`${currentWord}-${xOffSet}`}
    style={{
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
    }}
    ref={divRef}
    initial={{ x: xOffSet }}
    animate={{ x: 0 }}
    exit={{ x: -xOffSet }} // Adding an exit animation ensures smooth removal
    transition={{ duration: 1 }}
  >
    <p>{relativeClause}</p>

    <motion.div key={currentWord}>
      {currentWord.split("").map((letter, index) => (
        <motion.span
          key={`${currentWord}-${index}`}
          initial={{
            opacity: 0,
            y: 10,
            filter: "blur(8px)",
          }}
          animate={{
            opacity: 1,
            y: 0,
            filter: "blur(0px)",
          }}
          transition={{
            delay: index * 0.08,
            duration: 0.3,
          }}
          className={clsx("inline-block", letter === " " && "w-1")}
        >
          {letter}
        </motion.span>
      ))}
    </motion.div>
  </motion.div>
</AnimatePresence>

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 a more efficient way to differentiate a group of interfaces using an object map instead of using a switch statement?

As someone still getting the hang of advanced typescript concepts, I appreciate your patience. In my various projects, I utilize objects to organize react components based on a shared prop (e.g _type). My goal is to automatically determine the correct com ...

Tips for configuring environment variables across multiple test files within Jenkins

In my random.test.ts file I am utilizing an environment variable: test.beforeAll(async () => { new testBase.BaseTest(page).login(process.env.EMAIL, process.env.PASSWORD); }) I want to execute my tests using Jenkins, but I am unsure of how to pass m ...

Obtaining data from a TypeScript decorator

export class UploadGreetingController { constructor( private greetingFacade: GreetingFacade, ) {} @UseInterceptors(FileInterceptor('file', { storage: diskStorage({ destination: (req: any, file, cb) => { if (process.env ...

Error message: Issue with TypeScript and cleave.js - 'rawValue' property is not found on type 'EventTarget & HTMLInputElement'

I am encountering an error with the onChange event while implementing cleave in typescript. TypeScript is throwing an error indicating that 'rawValue' is not present in event.target. Here is my code: import React, { useCallback, useState, useEff ...

Utilize JQuery to choose the angular element

Can Angular tags be selected using JQuery? I am currently utilizing the ui-select Angular component, which is integrated into the HTML page as shown below: <ui-select ng-model="rec.currencyCode" on-select="ctrl.selectCurrencyCode(rec, $item)"> & ...

Struggling to fix TypeScript error related to Redux createSlice function

Here is the code snippet I am working on: import { Conversation } from "@/types/conversation"; import { PayloadAction, createSlice } from "@reduxjs/toolkit"; const initialState: Conversation | null = null; export const conversationSli ...

Can a React component be injected from Next.js?

In React, targeting specific elements based on their ids and rendering components within them is a common practice. For example: if(document.getElementById('root')) { const root = createRoot(document.getElementById('root')); roo ...

How to verify in HTML with Angular whether a variable is undefined

When it comes to the book's ISBN, there are instances where it may not be defined. In those cases, a placeholder image will be loaded. src="http://covers.openlibrary.org/b/isbn/{{book.isbn[0]}}-L.jpg?default=false" ...

Encountering an issue during Angular upgrade from version 8 to 11: Error message stating that the class extends value is undefined,

I am currently in the process of upgrading my Angular application from version 8 to 11, but I encountered the following error: Uncaught TypeError: Class extends value undefined is not a constructor or null at Module.4lR8 (main.js:sourcemap:59) at _ ...

Navigating nested data structures in reactive forms

When performing a POST request, we often create something similar to: const userData = this.userForm.value; Imagine you have the following template: <input type="text" id="userName" formControlName="userName"> <input type="email" id="userEmail" ...

The feature in Next.js flickers during conditional rendering

Looking for a way to have a component render based on the availability of a token, similar to jwt local storage authentication. The problem arises when I refresh the page with the token still available, as the component conditionally flashes or renders bef ...

Extract HTML content using CKEditor

Hey there! I'm in need of some help with getting user-entered data from a textarea. I've already attempted using CKEDITOR.instances.editor1.getData() and CKEDITOR.instances.ckeditor.document.getBody.getHtml(), but unfortunately both only return ...

Is it necessary to utilize the next.js Html component in _document.js, or can plain HTML be used instead?

While delving into the next documentation, I came across an interesting tidbit: The utilization of Html, Head, Main, and NextScript is imperative for the proper rendering of a webpage. For quite some time now, we have relied on a straightforward <ht ...

Enhancing menu item visibility with Typescript and Vue.js 3: A step-by-step guide

How can I dynamically highlight the active menu item in my menu? I believe that adding v-if(selected) and a function might be the way to go in the first template. <template> <MenuTreeView @selected='collapsedMenuSelected' :items=&apo ...

Tips for distributing a Vue plugin on NPM

I developed a straightforward plugin for Voca.js using Typescript. The source code can be found here. index.ts import VueVoca from './vue-voca'; export { VueVoca }; vue-voca.ts import vue from 'vue'; export default { install( ...

Typescript Error: The object doesn't recognize the property 'files' as part of the HTMLElement type

I am trying to implement an upload feature for my Apps using IONIC. Below is the HTML code snippet I have written: <input ion-button block type="file" id="uploadBR"> <input ion-button block type="file" id="uploadIC"> <button ion-button blo ...

Ways to access UserProfile in a different Dialogio

For the implementation of a chatbot, I am utilizing Microsoft's Bot Builder framework. However, upon implementing an alternative path to the dialog flow, I noticed that the user's Profile references are getting lost. Here is the code snippet fr ...

Retrieving data in Next.js

Exploring various techniques to retrieve information from APIs in next.js. Options include getServerSideProps, getStaticPaths, getStaticProps, Incremental Static Regeneration, and client-side rendering. If I need to send requests to the backend when a s ...

Leverage the power of NextJS to create a seamlessly persistent layout featuring the

Currently, I am in the process of transitioning a project from React to NextJS. The project's layout includes a common component which is a Leaflet Map. In Next JS, I utilize "next/dynamic" to load the map. Previously, React used react-router-dom@v6. ...

Tips on implementing computed properties in Vue.js while using TypeScript

There is a significant amount of documentation on how to utilize Vue.js with JavaScript, but very little information on using TypeScript. The question arises: how do you create computed properties in a vue component when working with TypeScript? According ...