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

[Bug]: Init event not fired in SSR (React / NextJS) #689

Closed
1 task done
StevenVerbiest opened this issue Jan 12, 2024 · 5 comments
Closed
1 task done

[Bug]: Init event not fired in SSR (React / NextJS) #689

StevenVerbiest opened this issue Jan 12, 2024 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@StevenVerbiest
Copy link

Bug is related to

  • embla-carousel-react

Embla Carousel version

  • v8.0.0-rc19

Describe the bug

The .on("init") event is not invoked when used in a useEffect in a SSR component.

CodeSandbox

https://stackblitz.com/edit/stackblitz-starters-syez5k?file=app%2FEmblaComponent.tsx
https://stackblitzstarterssyez5k-c0ir--3000--f7aa08df.local-credentialless.webcontainer.io/

const [emblaRef, emblaApi] = useEmblaCarousel();

useEffect(() => {
  if (!emblaApi) return;

  emblaApi.on('init', () => {
    console.log('init');
  });
}, [emblaApi]);

Steps to reproduce

  1. Open the Stackblitz webcontainer
  2. Open the console
  3. There is no 'init' log

The log is shown after a hot reload. If you see the init log, do a hard refresh.

Expected behavior

The init event should always fire.

@StevenVerbiest StevenVerbiest added the bug Something isn't working label Jan 12, 2024
@davidjerleke
Copy link
Owner

@StevenVerbiest I can't access the link you shared. Would you mind double checking it?

Best,
David

@davidjerleke davidjerleke added the missing test case or details Issue is missing important details or a test case that reproduces the problem label Jan 12, 2024
@StevenVerbiest
Copy link
Author

@davidjerleke I can't get the direct link to work for some reason, but do you have access to the source files?
If so, you could open the project in a new tab (available on the top right of the page) and connect the project then (if needed).

@davidjerleke
Copy link
Owner

@StevenVerbiest thanks for pointing me to the source files, that worked. I believe you should read this to better understand why it's happening:

Best,
David

@davidjerleke davidjerleke added awaiting response Issue is awaiting feedback and removed missing test case or details Issue is missing important details or a test case that reproduces the problem labels Jan 16, 2024
@StevenVerbiest
Copy link
Author

Thanks for the info. I'm also having some other issues related to SRR regarding to special layouts, but I won't go into detail since it's unrelated to this issue. I like Embla, but not supporting SSR is an issue for me, so I will sadly need to look for an alternative.
Will definitely try Embla for my CSR projects and wil try to keep an eye for SRR support in the future.
Cheers!

@davidjerleke
Copy link
Owner

davidjerleke commented Jan 16, 2024

@StevenVerbiest thanks. Although Embla doesn't run its script on the server, it still allows rendering the HTML and CSS on the server side.

@davidjerleke davidjerleke added duplicate This issue or pull request already exists not a bug This issue is not a bug and removed bug Something isn't working awaiting response Issue is awaiting feedback not a bug This issue is not a bug labels Jan 16, 2024
@davidjerleke davidjerleke changed the title Init event not fired in SSR (React / NextJS) [Bug]: Init event not fired in SSR (React / NextJS) Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants