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

Support SSR #3703

Closed
cythrawll opened this issue Mar 13, 2023 · 14 comments
Closed

Support SSR #3703

cythrawll opened this issue Mar 13, 2023 · 14 comments
Labels

Comments

@cythrawll
Copy link

cythrawll commented Mar 13, 2023

Summary

SSR is becoming more and more popular way to handle rendering, and having charts that can render both server and client side is really appealing for a number of reasons. While most SSR frameworks allow you to load client only libraries without SSR, apex in theory should be able to be used still client side only. (however in the case of react18s example, react-apexcharts seems to currently be broken as dynamic esm import seems to be broken there is a ticket for that already). However, making libs client side only is kinda a painful work around that isn't apparent when first using the library as docs don't mention anything about this gotcha.

API Changes

Make apex SSR friendly.

Intended Use Case

Better DX and UX when using apex charts in SSR frameworks like NEXT and Remix. Taking advantage of SSR frameworks caching and time to first render as well as other server side rendering benefits. I love using Apex, but this is probably going to cause me to abandon this in favor of other libraries.

@cythrawll cythrawll added the feature-request New feature or request label Mar 13, 2023
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@rakirox
Copy link

rakirox commented May 28, 2023

+1

1 similar comment
@oleg-savenok
Copy link

+1

@bf
Copy link

bf commented Jul 4, 2023

@cythrawll can you share what other libraries are like apexcharts but support SSR with frameworks like nuxt3?

@apexcharts apexcharts deleted a comment from cythrawll Jul 4, 2023
@vignesh-gupta
Copy link

Guys, I think first @apexcharts Please reopen the issue. and Any updates on this @bf @cythrawll. Because I'm using Next13 and I've added "use client" on top the file but still throws this error in my vs console-

- error node_modules/apexcharts/dist/apexcharts.common.js (6:379433) @ eval
- error ReferenceError: window is not defined
    at __webpack_require__ (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/webpack-runtime.js:33:42)
    at __webpack_require__ (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/webpack-runtime.js:33:42)
    at eval (./app/survey/result/page.tsx:9:74)
    at (ssr)/./app/survey/result/page.tsx (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/app/survey/result/page.js:457:1)
    at __webpack_require__ (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/webpack-runtime.js:33:42)
null

@robert-nash
Copy link

+1

@machour
Copy link

machour commented Oct 30, 2023

Would love to get SSR support on apex

@codesjedi
Copy link

+1

@sannajammeh
Copy link

Guys, I think first @apexcharts Please reopen the issue. and Any updates on this @bf @cythrawll. Because I'm using Next13 and I've added "use client" on top the file but still throws this error in my vs console-

- error node_modules/apexcharts/dist/apexcharts.common.js (6:379433) @ eval
- error ReferenceError: window is not defined
    at __webpack_require__ (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/webpack-runtime.js:33:42)
    at __webpack_require__ (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/webpack-runtime.js:33:42)
    at eval (./app/survey/result/page.tsx:9:74)
    at (ssr)/./app/survey/result/page.tsx (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/app/survey/result/page.js:457:1)
    at __webpack_require__ (/home/vignesh/Desktop/Code it/projects/hcl-form-proto/.next/server/webpack-runtime.js:33:42)
null

Next always renders "use client" on the server too, its just a way to tell Next to ship the JS to the client as well.
You need to use Next.js dynamic import combined with {ssr: false}.

@abdulrehmanaxa1
Copy link

It create problem in Angular side as well, Got this issue

5:59:58 PM [vite] Error when evaluating SSR module /chunk-JAU2AQNA.mjs:
|- ReferenceError: window is not defined
at node_modules/apexcharts/dist/apexcharts.common.js

@Creative-Difficulty
Copy link

@apexcharts REOPEN

@daviddavid
Copy link

As @sannajammeh said, you can use apexcharts in NextJS by importing it like this:

import dynamic from "next/dynamic";
const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });

@BeSaRa
Copy link

BeSaRa commented Feb 27, 2024

any update for Angular Side ?? how to use it ApexChart with SSR ???? really it is very important feature

@ts-ben
Copy link

ts-ben commented Mar 19, 2024

I am able to render and build react-apexcharts on the server in one route, but get a build error in another route.

for app/[[...analytics]] react-apexcharts is rendered on the server. I do get an error, but still able to build and render on the server.
In another route app/dashboard, I get a build error and the build crushes. In this route, I have to use
const ReactApexCharts = dynamic(() => import('react-apexcharts'))
It makes the build work, but when I load the page, everything is rendered on the server, but the chart take a second to render, because it is rendered on the client. And it looks not very good.

It's weird because on the route app/[[...analytics]] the chart is rendered on the server together with the whole page, and I don't have to use dynamic loading.

What the hell is going on?

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

No branches or pull requests