Skip to content

Feat/update node style api#7745

Open
greydove749 wants to merge 2 commits into
mermaid-js:developfrom
greydove749:feat/update-node-style-api
Open

Feat/update node style api#7745
greydove749 wants to merge 2 commits into
mermaid-js:developfrom
greydove749:feat/update-node-style-api

Conversation

@greydove749
Copy link
Copy Markdown

Note: first issue submitted; coauthored agentically; project uses mermaid to viz graphs specifying networks of agentic inference/execution.

📑 Summary

Brief description about the content of your PR.

Resolves #

📏 Design Decisions

Describe the way your implementation works or what design decisions you made if applicable.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

greydove749 and others added 2 commits May 12, 2026 15:56
Exposes a closure-based API on RenderResult that allows consumers to
update individual node SVG styles after render, without fragile DOM
queries. The closure captures the internal nodeElems map at render time.

API: updateNodeStyle(nodeId: string, style: Record<string, string>) => boolean

- Returns true if node found and styled, false if unknown (no throw)
- Closure scoped to render instance; re-render invalidates previous closure
- Shape fallback order: rect, polygon, circle, ellipse, path
- getNodeElements() returns snapshot copy, not live map (re-render safe)

Closes mermaid-js#7517

Related: mermaid-js#5883 (highlight interaction), mermaid-js#3241 (programmatic interaction)

AI-Assisted-By: Claude (Anthropic) — session 74cab98e
Adds packages/mermaid/src/__tests__/updateNodeStyle.spec.ts covering the
public contract surfaced in 938b1f9e5 → amended as f9d69e5:

- T1: updateNodeStyle is present on RenderResult and is a function
- T2: valid node ID returns true and applies CSS properties
- T3: unknown node ID returns false without throwing
- T4: re-render produces independent closures — each closure only knows
       its own node IDs (snapshot semantics invariant)

T4 directly exercises the snapshot-vs-live-map design decision from the
PR description: getNodeElements() returns `new Map(nodeElems)` so each
render's closure has its own frozen view that survives subsequent
render()/clear() cycles on the live nodeElems.

Cypress E2E counterpart (red-fill imgSnapshotTest) is referenced in the
T2 comment but lives in a separate commit when added.

Refs mermaid-js#7517

AI-Assisted-By: Claude (Anthropic) — session 74cab98e (original WIP),
                                     session 9f7359c9 (capture commit)
@netlify
Copy link
Copy Markdown

netlify Bot commented May 12, 2026

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 3bebc5b
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/6a03b1af241a6100080d8cf7
😎 Deploy Preview https://deploy-preview-7745--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2026

⚠️ No Changeset found

Latest commit: 3bebc5b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added the Type: Enhancement New feature or request label May 12, 2026
Copy link
Copy Markdown
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

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

Hi @greydove749, can you please update your PR description and title with what the PR is supposed to be doing?

But, from having a quick look at your code and ticket linked only in your commit, I think it's unlikely a feature like this would be added to Mermaid's API, since:

  1. We're very careful not to make implementation details like how the diagram renders public, since it might make future updates to mermaid very difficult!
  2. There are many diagram types that don't use nodes.
  3. We may in the future introduce rendering methods (e.g. ASCII/canvas) that don't use HTML elements.
  4. Styling nodes after they're rendered is usually dangerous, as it could potentially break the size/layout of boxes.

You may want to instead open an issue requesting this feature. There could be a better way to do what you want to do (e.g. using themeCSS).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants