Repository navigation
feat(widgets): bundle mathjs and uPlot for graphing widgets - #842
posthog[bot] wants to merge 1 commit into
Conversation
Widget sandboxes could only reach KaTeX, so a function graph meant hand-rolling axes, ticks, and an expression parser in raw SVG per widget. Bundle two CSP-safe browser builds the frame can load: - mathjs (`math`) parses and evaluates the plotted expression. - uPlot (`uPlot`) draws the axes, grid, ticks, and lines. Both ship ready browser builds copied verbatim through the existing scripts/copy-widget-libs.mjs path, and neither uses eval, so the frame keeps its strict CSP with no script-src 'unsafe-eval'. The libraries load only when a widget references them. Add a `references/graphing.md` skill reference so the author uses the bundled globals instead of hand-rolling a plot. Add two client events so the feature is measurable: `widget_rendered` on first render and `widget_render_failed` on a sandbox runtime error, each flagged with the libraries the widget uses. Generated-By: PostHog Desktop Task-Id: e8edff41-57c7-4a05-b321-8b022dd46bb2
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
React Doctor found 1 new issue in 1 file · 1 warning · score 93 / 100 (Great) · 1 fixed · vs 1 warning
Reviewed by React Doctor for commit |
Problem
Changes
math(mathjs) parses and evaluates the expression,uPlotdraws the axes, grid, ticks, and lines.script-srckeeps'unsafe-inline'only and never gains'unsafe-eval'. The bundled URLs join the allow list; the<script>/<link>tags inject only when a widget references the library.scripts/copy-widget-libs.mjsnow copies KaTeX, mathjs, and uPlot verbatim. The output stays generated and gitignored.references/graphing.mdshows a theme-aware function plot built from the bundled globals;SKILL.mdpoints the model to it.widget_renderedon first render andwidget_render_failedon a sandbox runtime error — each carryuses_katex/uses_mathjs/uses_uplot, so a graph widget is countable apart from an ordinary one.katexmathuPlotTesting
vitestwidget suites cover the CSP allow list, the conditional tag injection,detectWidgetLibraries, and the first-render / runtime-error callbacks.tsc --noEmit,vp lint, andvp fmtare clean.Not in scope
WORKSPACE_ITEM_TYPESmember plus a database migration) is a deliberate follow-up. This PR delivers graphs inside notes.Refs #841
Agent context
function-plot, which draws and parses in one library, but it ships CommonJS only and compiles expressions withnew Function, which would force'unsafe-eval'and a bundler step. mathjs and uPlot both ship eval-free browser builds that copy verbatim, so the sandbox keeps its threat model.Created with PostHog Desktop from this inbox report, addressing #841.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.