feat(joint-react): server-side rendering + new @joint/svg-shim package#3343
Open
samuelgja wants to merge 3 commits into
Open
feat(joint-react): server-side rendering + new @joint/svg-shim package#3343samuelgja wants to merge 3 commits into
samuelgja wants to merge 3 commits into
Conversation
…g across various examples - Updated Paper component style properties to use single quotes for consistency. - Replaced usePaperEvents with direct event handlers for onLinkMouseEnter, onLinkMouseLeave, onElementMouseEnter, and onElementMouseLeave in multiple examples. - Added eslint-disable comments for performance-related rules in several files. - Cleaned up unused imports and improved code readability in various components.
… removed redundant code blocks and optimized function calls.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds server-side rendering for JointJS and a new reusable package that makes it possible.
New package:
@joint/svg-shimA headless DOM + SVG-geometry shim so
@joint/core's Vectorizer /dia.Paperruns in Node, with no browser. It plugs exactly the holes a headless DOM leaves:getBBox,SVGMatrix/SVGPoint/SVGTransform, transform lists, font-size coercion,HTMLImageElement.@napi-rs/canvas, so server-measured labels match the browser pixel-for-pixel.Production-ready: ESM/CJS/types build, Jest tests, shared
@joint/eslint-config, README,.gitignore. Exports.,./install(side-effect entry), and a client-safe./flagsubpath (zero Node imports) so the browser bundle never pulls the Node-only shim. It is reusable by both@joint/core(pure) and@joint/reactvia an injectable text-style resolver.@joint/reactserver renderingimport '@joint/react/server'installs the shim and registers a server paper renderer, so a plain<GraphProvider><Paper renderElement={…}/></GraphProvider>rendered withrenderToStringemits the full diagram SVG inline, which then hydrates into the live, interactive paper on the client.jsdom/@napi-rs/canvasmoved to optional peers on@joint/svg-shim, so client-only consumers install nothing extra.Examples (
packages/joint-svg-shim/examples)react-ssr— Vite + Express: server-render the interactive diagram, ship it as SVG, hydrate on the client. Styled. Works with JavaScript disabled.core-static— pure@joint/core: build a diagram in Node, serialize withpaper.svg.outerHTML, serve as static HTML. No React, no client JS.Motivation and Context
JointJS builds diagrams from real SVG DOM and measures geometry through it (
getBBox, matrices, text width). In Node there is no DOM, and even a headless DOM implements no SVG layout — so a server-rendered paper collapses (labels lose size, links lose geometry).@joint/svg-shimmakes server rendering work and correct, unlocking SEO-friendly first paint, emailable diagrams, and@joint/reactSSR + hydration. The shim is isolated as its own package so@joint/corecan reuse it later without depending on React.Screenshots (if appropriate):
@joint/coreon the server — pure@joint/core+@joint/svg-shim: the diagram is built in Node, serialized withpaper.svg.outerHTML, and shipped as static SVG in the HTML. No browser, no client JavaScript, not interactive.@joint/reacton the server —renderToStringships the full diagram as SVG in the HTML (works with JavaScript disabled), then hydrates into the live, interactive JointJS paper on the client.