Open ieedan opened 7 months ago
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.
This is still a problem.
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.
This is still a problem.
Do you think svgdom will help? @junedchhipa I mean, how hard would it be to add the use of this library?
still a problem
This is also an issue with tests. I have a dependency that uses apexcharts, so when I import my dependency, Apex immediately tries to access window. I can only mock out the entire dependency, but then I'm mocking more than I'd like
Summary
When using Apex Charts with SSR when importing the module Apex Charts tries to access
window
immediately because it uses top level calls in other imported modules. This causes apps using SSR to break when using the library becausewindow
is not accessible on the server. Components using the library have to be client rendered to work.I am not super familiar with the library but I have just skimmed over to try and find any top level window calls.
Here are a few I found:
/modules/helpers/InitCtxVariables.js
./svgjs/svg.js
./libs/Treemap-squared
There are other issues open for SSR users already like:
4176
API Changes
init
method wrapping the window calls so that users can determine when the code is loadedIntended Use Case
Anyone using Sveltekit / Next.js / Remix or any other SSR framework
Current Work Around
+page.server.ts
file to client render components that use Apex Charts"use client"
at the top of their componentsIssue recreation
https://github.com/ieedan/apex-charts-ssr
Steps:
Should see 500 error now
If you uncomment the CDN from
app.html
and commentimport ApexCharts from "apexcharts"
at the top of +page.svelte then it should render the chart with no issues.