Repository navigation
Conversation
…perty to error state
Contributor
|
@aradhyacp is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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
The Mermaid
errorComponentonly received the error message string, so the original thrown error (for example a Jison parse error with itshash) was discarded inrenderChart. Consumers who wanted structured parser details had to callmermaid.parse(chart)a second time. That is wasted work, and the second parse may not reproduce the original failure, for example when parsing succeeds but rendering fails.This PR adds an optional
cause?: unknownprop toMermaidErrorComponentPropsand forwards the original thrown value to the custom error component.Type of Change
Related Issues
Fixes #720
Changes Made
cause?: unknowntoMermaidErrorComponentProps(packages/streamdown/index.tsx)renderChartnow returns the original thrown value ascausein the failure outcome, including non-Errorvalues (packages/streamdown/lib/mermaid/index.tsx)errorCausestate and pass it toErrorComponenterrorCausewhen a new render starts and when the plugin is missing, so a stale cause never pairs with a newer errorErrorwith a Jison-stylehashand a non-Errorthrown valuecausein the Mermaid docs page and the skill API referencepatch)Testing
How I tested it locally:
I linked the local build into a test React app and used the component below with two invalid diagrams, one Jison-based (flowchart) and one Langium-based (
architecture-beta).Test component
Results
causeis the original error, andcause.hashexposestoken,line,locandexpected(15 expected tokens). No secondmermaid.parseis needed.architecture-beta):causeis forwarded, but it has nohash(cause.hash === undefined). The error shape differs per parser, which is why the prop is typedunknown. The docs tell consumers to check the shape before reading properties.error,chartandretryprops are unchanged.Test Coverage
Two new unit tests in
packages/streamdown/__tests__/mermaid-component.test.tsx:Errorcarrying a Jison-stylehashreaches theerrorComponentas the same objectErrorthrown value is forwarded ascauseScreenshots/Demos
Before (
causenot available)After, Jison error (
cause.hashavailable)After, Langium error (
causeforwarded, nohash)Checklist
pnpm changeset)Changeset
Additional Notes
causeis optional, so existing custom error components keep working.causeis typedunknownbecause it is whatever Mermaid threw. Jison errors exposehash, Langium errors do not, and a non-Errorvalue can be thrown.