Skip to content

Extract sanitizeHtml into a standalone module#8726

Open
manzt wants to merge 1 commit intomainfrom
push-wttsnrykrttx
Open

Extract sanitizeHtml into a standalone module#8726
manzt wants to merge 1 commit intomainfrom
push-wttsnrykrttx

Conversation

@manzt
Copy link
Collaborator

@manzt manzt commented Mar 17, 2026

sanitize.ts mixes a pure DOMPurify wrapper with React/jotai state that transitively imports the full editor/codemirror/SQL panel tree, including .svg/.png database icon assets added in #8528.

This breaks the marimo-lsp VS Code extension build — esbuild bundles transitionCell from core/cells/cell.ts, which reaches sanitize.ts via outline.ts, pulling in assets it has no loader for. This has blocked upgrading the frontend dependency in marimo-lsp since 0.20.2.

No logic changes. sanitizeHtml and its DOMPurify hooks move to sanitize-html.ts, outline.ts imports from there directly, and sanitize.ts re-exports for backward compat.

`sanitize.ts` mixes a pure DOMPurify wrapper with React/jotai state that
transitively imports the full editor/codemirror/SQL panel tree,
including `.svg`/`.png` database icon assets added in #8528.

This breaks the marimo-lsp VS Code extension build — esbuild bundles
`transitionCell` from `core/cells/cell.ts`, which reaches `sanitize.ts`
via `outline.ts`, pulling in assets it has no loader for. This has
blocked upgrading the frontend dependency in marimo-lsp since 0.20.2.

No logic changes. `sanitizeHtml` and its DOMPurify hooks move to
`sanitize-html.ts`, `outline.ts` imports from there directly, and
`sanitize.ts` re-exports for backward compat.
@manzt manzt requested a review from Light2Dark as a code owner March 17, 2026 01:18
Copilot AI review requested due to automatic review settings March 17, 2026 01:18
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 17, 2026 1:19am

Request Review

@manzt manzt added the internal A refactor or improvement that is not user facing label Mar 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR decouples HTML sanitization from React/jotai state so non-UI consumers (notably the marimo-lsp VS Code extension bundle) don’t transitively pull in the editor tree and its static assets.

Changes:

  • Moved the pure DOMPurify wrapper (sanitizeHtml + hooks) into a new standalone module sanitize-html.ts.
  • Updated core/dom/outline.ts to import sanitizeHtml from the standalone module to avoid dragging in editor-related dependencies.
  • Kept backward compatibility by re-exporting sanitizeHtml from the existing sanitize.ts.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
frontend/src/plugins/core/sanitize.ts Removes DOMPurify implementation and re-exports sanitizeHtml from the new standalone module.
frontend/src/plugins/core/sanitize-html.ts New standalone module containing DOMPurify hooks + sanitizeHtml implementation.
frontend/src/core/dom/outline.ts Swaps import to use the standalone sanitize-html module directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

tagNameCheck: /^(marimo-[A-Za-z][\w-]*|iconify-icon)$/,
attributeNameCheck: /^[A-Za-z][\w-]*$/,
},
// This flag means we should sanitize such that is it safe for XML,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing marimo-lsp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants