-
Notifications
You must be signed in to change notification settings - Fork 19.7k
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
[RFC] Server-Side Render and Light Client Hydration Runtime #18334
Comments
feat(ssr): add emphasis style in ssr css apache/echarts#18334
feat(ssr): server-side rendering and client hydration #18334
Hi there, this appears to have been merged a few months ago and released in 5.5 a couple of weeks ago. Perhaps it should be closed? More importantly, I'm excited to use this but I don't see any documentation related to this. Am i missing something? https://echarts.apache.org/handbook/en/how-to/cross-platform/server/ Also, the examples in that page don't work. Nor does the demo here - unless you log in and fork it. Thanks! |
Problem
Apache ECharts's package size is about 300KB to 1MB after minification, which is sometimes unacceptable for mobile users. ECharts's Server Side Rendering (SSR) solution can solve this problem to a great extent. But users cannot interact directly with the server-rendered image (with Canvas SSR) or SVG (with SVG SSR).
To solve this problem, Client Side Hydration is usually used (see Vue and React Client Side Hydration document). But for Apache ECharts, this means we still need to load the 300KB to 1MB package, which is still undesired for some situations. So a light runtime is probably needed to enable user interaction.
Goal
SVG SSR seems to be a more promising solution because the shapes are preserved in the result, not to mention a lot of other benefits. Currently, the SVG rendering result consists of primary shapes like rectangles with position and size attributes, but we have no idea if it's a bar of a bar series or a legend item and thus the client runtime has no idea how to bind the interaction.
So we need to perserve some meta data when doing SSR, e.g., which series or components this shape belongs to. The meta data is a seperate JSON string.
Scope
The client side runtime should provide the abilities to enable the interaction of:
And the following are the advanced features that may NOT be supported (at least for now):
If these interactions are required for some cases, the developer should consider using the regular Apache ECharts library to do the hydration after SSR.
Design
Attributes in The SVG Node
Aim: Shape styles may change when interacting. For example, when hovering on a bar in a bar series, the color of the bar series may change to be
emphasis.itemStyle.color
. So we need to add this information to the CSS style of each SVG node representing aDisplayable
. In order to constrain the SVG size, we create CSS classes to reuse the same style.Generation stage: When in _paintList of the SVG painter, each Displayable should be checked if is special (e.g., part of series item or legend item), and add the hovering style with CSS names.
Extra SVG Attributes:
Client Hydration
The Client hydration runtime code size is very small. It binds the events of the SVG nodes and triggers events that we care about (clicking the legend items, or clicking the series items).
Examples
I made a complete demo of SSR and Client Runtime. I think this demo can better illustrate the usage.
Discussion
This client hydration runtime can solve the package size issue, especially for mobile conditions. Although it has many limitations as compared to loading a full ECharts code on the client side, I do believe this can offer great help for many cases.
The client runtime is currently including in the test file of this PR. In the future, I think it can be put in a seperate repo under Apache on GitHub.
Any discussion is welcomed! :)
The text was updated successfully, but these errors were encountered: