-
Notifications
You must be signed in to change notification settings - Fork 313
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
NextJS Integration Solution - Avoiding setTimeout at all costs #270
Comments
@shanehoban Should I then just call the PrelineScript function from the App component? Anything I should think of if I'm using a regular react app? |
@Wigglor The solution above is specifically for NextJS based apps. If you are simply using react (not with NextJS) -> You should be able to follow the React docs here: https://preline.co/docs/frameworks-react.html and from the looks of it - you shouldn't have this issue if doing so. |
@shanehoban Hmm, weird. Been following the docs you referred. Still got the same issue 😢 |
It says that i need to install with NPM, but I'm using yarn. But I guess that could hardly be a reason. |
@Wigglor it would be better for you to create a new issue if you have a problem instead of using this one as this one is specific to NextJS. I'm not a maintainer of Preline either, just trying to help out. |
@shanehoban thank you for the script however when using this im seeing the following issue in nextjs
|
@insivika I suspect this is not related to this library, and the solution I provided is only 26 lines long. I'd suggest try commenting out all the preline stuff and see if that error is still present. It seems to be an error relating to parsing JSON somewhere in your project - check all areas you are performing JSON parsing etc. |
@shanehoban thank you for your input. You are correct, I had added something to the select component that seemed to introduce this issue. |
@shanehoban thanks for the Integration suggestion above. Unfortunately it does not seen to be working for me. I had to reintroduce the setTimeout and set it to 1000 milsec (yikes) to get the event listeners to attach. |
@insivika If you have your useEffect set up like below, it shouldn't be the case:
You see it's an inline async function that gets called whenever the path changes. The import is thus lazy and will only call the next line after it's done. Maybe show what your code looks like? |
Hey @shanehoban - thanks for the suggestions and sharing the workaround! We've updated our docs based on your suggestion. We've also added Preline JavaScript page with some samples and explanation how Preline JavaScript works: https://preline.co/docs/preline-javascript.html Cheers! |
The issue is that sometimes the setTimeout function is called before the preline script has been imported - so the
window.HSStaticMethods
call is not defined. This is reproducible when running lighthouse reports (although still doesn't occur every time).Proposed solution for the code on in your docs is below, utilizing an async wrapper function to ensure the preline script is imported before the
window.HSStaticMethods.autoInit()
is called.Solution below:
The text was updated successfully, but these errors were encountered: