-
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
feat(ssr): server-side rendering and client hydration #18334 #18381
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c1a157e
WIP(ssr): add meta-data and test case #18334
Ovilia ed1c176
WIP
Ovilia 8fb7ed0
Merge branch 'master' into ssr
Ovilia f8b25f5
style(ssr): remove console.log
Ovilia 27cc769
test(ssr): add test cases
Ovilia 0e7eac7
feat(ssr): improve code
Ovilia b2ff198
feat(ssr): call registerSSRDataGetter instead of metaData
Ovilia a632970
chore(ssr): update building ssr client
Ovilia 6bca132
chore(ssr): update building of ssr client
Ovilia c8ba77c
chore: merge
Ovilia 01df82a
fix(ssr): remove unnecessary code
Ovilia 7dd9b37
chore: merge
Ovilia badfd0f
chore: use zrender nightly build
Ovilia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ jobs: | |
index.d.ts | ||
src/ | ||
extension-src/ | ||
ssr/client/src/ | ||
licenses/ | ||
theme/ | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,7 @@ todo | |
/index.blank.js | ||
/extension-esm | ||
/extension | ||
/ssr/client/lib | ||
/core.js | ||
/core.d.ts | ||
/charts.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export interface ECSSRClientEventParams {} | ||
|
||
export interface ECSSRClientOptions { | ||
on?: { | ||
mouseover?: (params: ECSSRClientEventParams) => void, | ||
mouseout?: (params: ECSSRClientEventParams) => void, | ||
click?: (params: ECSSRClientEventParams) => void | ||
} | ||
} | ||
|
||
export type ECSSREvent = 'mouseover' | 'mouseout' | 'click'; | ||
|
||
export function hydrate(dom: HTMLElement, options: ECSSRClientOptions) { | ||
const svgRoot = dom.querySelector('svg'); | ||
if (!svgRoot) { | ||
console.error('No SVG element found in the DOM.'); | ||
return; | ||
} | ||
|
||
const children = svgRoot.children; | ||
|
||
function getIndex(child: Element, attr: string) { | ||
const index = child.getAttribute(attr); | ||
if (index) { | ||
return parseInt(index, 10); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
|
||
const events = options.on; | ||
if (events) { | ||
for (let eventName in events) { | ||
if (typeof events[eventName as ECSSREvent] === 'function') { | ||
for (let i = 0; i < children.length; i++) { | ||
const child = children[i]; | ||
const type = child.getAttribute('ecmeta_ssr_type'); | ||
const silent = child.getAttribute('ecmeta_silent') === 'true'; | ||
if (type && !silent) { | ||
child.addEventListener(eventName, e => { | ||
(events[eventName as ECSSREvent] as Function)({ | ||
type: eventName, | ||
ssrType: type, | ||
seriesIndex: getIndex(child, 'ecmeta_series_index'), | ||
Ovilia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dataIndex: getIndex(child, 'ecmeta_data_index'), | ||
event: e, | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will suggest returning an object in this method to ensure it will be typesafe. To avoid the situation that we change the key here and forget to change where reads it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean we should define the type in ZRender? But ZRender should not know the structures like seriesIndex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use generic type
Just like what
getECData
do