This guide explains how to build the React Flow JavaScript bundle that powers the visualization component of dplyneage.
Note for users: The bundle should be pre-built when you install the package. You typically only need to build it if:
With your working directory at the root of the dplyneage repository:
From the package source directory in a terminal:
The build process creates:
inst/htmlwidgets/lib/reactflow/reactflow-bundle.min.js
- Complete React Flow bundleThis bundle includes:
The bundle exposes everything the widget binding consumes on
window.ReactFlowBundle: the React runtime, the
ReactFlow component with Background,
Controls, ControlButton, MiniMap,
and Panel, the custom TableNode and
LineageEdge components, the
getNodesBounds/getViewportForBounds viewport
helpers, and toPng. The binding guards each optional
export, so a browser holding an older cached bundle degrades by omission
(no minimap, no export button) rather than failing to render.
srcjs/package-lock.json is committed so a rebuild from a
fresh clone resolves the same dependency versions that produced the
committed bundle.
srcjs/patches/@xyflow+system+0.0.74.patch changes one
function in the library, updateNodeInternals. React Flow
measures each handle’s offset inside its node with
getBoundingClientRect() and divides by its own viewport
zoom, which ignores any CSS scale applied by an ancestor of the widget.
Inside a Quarto revealjs slide, which reveal fits to the window with
transform: scale(), every stored handle offset came out
inflated by that scale and the edges detached from the columns. The
patch folds the ancestor scale (the container’s bounding-rect width over
its offsetWidth) into the zoom used for that measurement.
Upstream has the same code as of @xyflow/react 12.11.6, so
a version bump does not replace the patch.
patch-package applies it from the
postinstall script, so a plain npm install is
enough, and the install fails if the patch no longer applies. When
bumping @xyflow/react, re-apply the change by hand in
node_modules/@xyflow/system/dist/esm/index.js and run
npx patch-package @xyflow/system, which rewrites the patch
file for the new version.
For active development with auto-rebuild:
This will watch for changes and rebuild automatically.
devtools::load_all()
lineage_flow(
nodes = list(
list(id = "1", position = list(x = 0, y = 0),
data = list(label = "Source")),
list(id = "2", position = list(x = 250, y = 100),
data = list(label = "Transform")),
list(id = "3", position = list(x = 500, y = 0),
data = list(label = "Output"))
),
edges = list(
list(id = "e1-2", source = "1", target = "2"),
list(id = "e2-3", source = "2", target = "3")
)
)If the bundle loads successfully, you’ll see an interactive React Flow diagram with draggable nodes, pan/zoom controls, and a grid background.
If the bundle doesn’t load, it will fall back to the SVG visualization.
Bundle not found: Make sure the build completed
successfully and check that
inst/htmlwidgets/lib/reactflow/reactflow-bundle.min.js
exists.
Build fails:
node --version (should be
v18+)cd srcjs && rm -rf node_modules && npm install && npm run buildWidget shows SVG instead of React Flow: Check browser console for errors. The widget will fall back to SVG if React Flow fails to load.
If you’re modifying the React Flow bundle:
srcjs/src/index.jsnpm run dev in the srcjs
directorydevtools::load_all()The webpack configuration in srcjs/webpack.config.js
handles bundling all dependencies into a single minified file.
The bundle is created using webpack and includes:
The bundle is optimized for production with minification and tree-shaking to reduce file size.