Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Count Up library causes props to be undefined #8497

Closed
1 task
Albertyhu opened this issue Sep 11, 2023 · 4 comments
Closed
1 task

React Count Up library causes props to be undefined #8497

Albertyhu opened this issue Sep 11, 2023 · 4 comments
Labels
needs triage Issue needs to be triaged

Comments

@Albertyhu
Copy link

Astro Info

I got the following message from running astro info:

astro : The term 'astro' is not 
recognized as the name of a cmdlet, 
function, script file, or operable 
program. Check the spelling of the 
name, or if a path was included, 
verify that the path is correct and 
try again.
At line:1 char:1
+ astro info
+ ~~~~~
    + CategoryInfo          : Objec  
   tNotFound: (astro:String) [], C   
  ommandNotFoundException
    + FullyQualifiedErrorId : Comma  
   ndNotFoundException

If this issue only occurs in one browser, which browser is a problem?

firefox, chrome

Describe the Bug

I am using the React package called 'React CountUp".

It works fine in development mode, but on production mode, it crashes the entire app.

Here is where the library is used:

import CountUp from 'react-countup';

const CounterComponent = (props: CounterType) => {
	console.log("props.number: ", props.number)
	return props.number ? 
		<div className="count-outer relative block text-4xl text-[70px] leading-none text-white">
			<CountUp end={100} /> 
		</div>
		:
		<div>
		</div>
}

On production mode, the following error is thrown

"Runtime.UnhandledPromiseRejection - TypeError: Cannot read properties of undefined (reading 'number') "

If I get rid of the component, the app works just fine.

Also, I made sure that the component utilized client:visible directive in the Astro file.

The following Github link is the directory that has all the files responsible for rendering the component that uses React CountUp:

https://github.com/Albertyhu/uthan-template/tree/main/src/components/Home/funfact_section

What's the expected result?

React CountUp allows for an animated number to count up.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-eicrch?file=src%2Fpages%2Findex.astro,src%2Fcomponents%2Ffunfact_section%2Findex.astro,package.json,src%2Fcomponents%2Ffunfact_section%2Fcounter.tsx

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 11, 2023
@bluwy
Copy link
Member

bluwy commented Sep 11, 2023

It's a Vite bug: vitejs/vite#2139

As a workaround, you can do this:

// @ts-expect-error
const CountUpComponent = CountUp.default ?? CountUp

// ...

			<CountUpComponent end={props.number} /> 

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
@Albertyhu
Copy link
Author

@bluwy Thanks for the suggestion, but unfortunately, it didn't work for me. I still got the same error.

@Albertyhu
Copy link
Author

@bluwy I ended up just creating the counter from scratch on my own:
https://idyllic-crumble-facf8a.netlify.app/#FunFactSection

@dest92
Copy link

dest92 commented Jan 11, 2024

Same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants