Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/1294_exhaustive-clear-sequenceDb-variables #4941

Conversation

rflban
Copy link
Contributor

@rflban rflban commented Oct 12, 2023

📑 Summary

Reason of bugs like one in issue are global variables cached between renders. I've made exhaustive cleanup of sequenceDb.

You can reproduce the bug in mermaid live editor with these diagrams:

sequenceDiagram
    Alice->>Bob: Hello Bob, how are you ?
    Bob->>Alice: Fine, thank you. And you?
    create participant Carl
    Alice->>Carl: Hi Carl!
    create actor D as Donald
    Carl->>D: Hi!
    destroy Carl
    Alice-xCarl: We are too many
    destroy Bo
    Bob->>Alice: I agree
sequenceDiagram
    Alice->>Bob: Hello Bob, how are you ?
    Bob->>Alice: Fine, thank you. And you?
    create participant Carl
    Alice->>Carl: Hi Carl!
    create actor D as Donald
    Carl->>D: Hi!
    destroy Carl
    Alice-xCarl: We are too many
    destroy Bob
    Bob->>Alice: I agree

Resolves #1294

📏 Design Decisions

I've added imperative state. It's simple structure, that is created from init function and provides reset method, that recalls init function to restore initial values of state's fields. This approach ensures that newly added state fields are cleared.

Also I've added two identity functions, that help specify type of state initial values for typescript.

📋 Tasks

Make sure you

@netlify
Copy link

netlify bot commented Oct 12, 2023

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 1b20fe9
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/659f6b421d64d70008b24152
😎 Deploy Preview https://deploy-preview-4941--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@github-actions github-actions bot added the fix label Oct 12, 2023
@rflban rflban changed the title fix/1294_exhaustive-clear-sequenceDb-variables Draft: fix/1294_exhaustive-clear-sequenceDb-variables Oct 12, 2023
@rflban rflban changed the title Draft: fix/1294_exhaustive-clear-sequenceDb-variables fix/1294_exhaustive-clear-sequenceDb-variables Oct 12, 2023
@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (34e0942) 43.04% compared to head (1b20fe9) 79.70%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #4941       +/-   ##
============================================
+ Coverage    43.04%   79.70%   +36.65%     
============================================
  Files           23      167      +144     
  Lines         5018    13873     +8855     
  Branches        21      707      +686     
============================================
+ Hits          2160    11057     +8897     
+ Misses        2857     2663      -194     
- Partials         1      153      +152     
Flag Coverage Δ
e2e 85.60% <96.22%> (?)
unit 43.04% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/mermaid/src/utils/imperativeState.ts 100.00% <100.00%> (ø)
...ckages/mermaid/src/diagrams/sequence/sequenceDb.js 84.03% <96.00%> (ø)

... and 161 files with indirect coverage changes

@rflban rflban marked this pull request as draft October 12, 2023 21:50
@rflban rflban marked this pull request as ready for review October 13, 2023 10:41
Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

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

This is splendid, and long overdue!
@Yokozuna59 has been doing related work in other diagrams, so their review would be good to have.

Few minor issues only, great job!

packages/mermaid/src/docs/syntax/sequenceDiagram.md Outdated Show resolved Hide resolved
packages/mermaid/src/utils/imperativeState.ts Outdated Show resolved Hide resolved
packages/mermaid/src/utils/imperativeState.ts Outdated Show resolved Hide resolved
packages/mermaid/src/utils/imperativeState.ts Outdated Show resolved Hide resolved
cypress/helpers/util.ts Show resolved Hide resolved
Copy link
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.

This looks awesome :)

I love how you've managed to change the code in a way that should prevent a bug like #1294 from happening again too!

The only thing I don't 100% love is the syntax, which is a bit unusual to me. I feel like using something like the following would more closely match the rest of the JavaScript eco-system:

state = new ImperativeState(() => {
 // default state
});

I've already even got a commit for it: aloisklink@35191a6 that I could push to this branch.

packages/mermaid/src/utils/imperativeState.ts Outdated Show resolved Hide resolved
packages/mermaid/src/utils/imperativeState.ts Outdated Show resolved Hide resolved
@sidharthv96
Copy link
Member

@rflban can you integrate the suggestions and update the PR? Would love to merge this soon.

Copy link
Contributor

@nirname nirname left a comment

Choose a reason for hiding this comment

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

I love this PR. My general thoughts about DB is that instead of "cleaning" function we have to recreate DB as an object, so our overall flow would be

  • create db
  • populate it with data from parser
  • render it

Every call of "clean" basically equals object destruction. So I love the overall approach and I think it have to be pushed further than that.

I agree on the comments from other reviewers, it's better to address them. Lets wait for those minor fixes, and this is good to go. Just comment from me this time, not approve, neither reject.

@sidharthv96 sidharthv96 added this to the v10 milestone Nov 28, 2023
@sidharthv96
Copy link
Member

@rflban Do you have time to address the review comments, or can we push the changes and merge it? Would like to include this in the next release.

@rflban
Copy link
Contributor Author

rflban commented Dec 4, 2023

@rflban Do you have time to address the review comments, or can we push the changes and merge it? Would like to include this in the next release.

Sorry, I haven't notice the new comments. I will fix the comments today

@sidharthv96
Copy link
Member

@rflban sorry to bother you. This is an excellent candidate for what might be the last v10 release (which we're hoping to do by next week). Otherwise we would've moved it out of the queue.

@github-actions github-actions bot added the Type: Bug / Error Something isn't working or is incorrect label Dec 7, 2023
@rflban
Copy link
Contributor Author

rflban commented Dec 7, 2023

@rflban sorry to bother you. This is an excellent candidate for what might be the last v10 release (which we're hoping to do by next week). Otherwise we would've moved it out of the queue.

It's my fault, I did not have time to commit changes. But this pr is ready to check now

Copy link
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.

Looks good to me! Thanks for making those changes!

@sidharthv96, do you want to double-check that all of your "Requested changes" have been dealt with before merging this PR? GitHub is blocking me from merging until all conversations have been resolved.

* develop: (200 commits)
  chore(deps): update all minor dependencies
  adds corresponding change in docs/ecosystem
  Adds Unison programming language to community integrations list
  Fixed parser/tests
  Update docs
  Update classDiagram.md
  Update classDiagram.md
  Update docs
  Update packages/mermaid/src/diagrams/class/classDb.ts
  Update packages/mermaid/src/docs/syntax/classDiagram.md
  Update packages/mermaid/src/diagrams/class/classDb.ts
  chore(deps): update all minor dependencies
  Update generics docs
  Update docs
  Address potential undefined
  refactor: Move maxEdges out of flowchart config.
  refactor: Move maxEdges out of flowchart config.
  chore: Add maxEdges to secure list
  Update docs
  Update NiceGuy.io links in integrations-community.md
  ...
@sidharthv96 sidharthv96 added this pull request to the merge queue Jan 11, 2024
Merged via the queue into mermaid-js:develop with commit 54446f1 Jan 11, 2024
18 checks passed
Copy link

mermaid-bot bot commented Jan 11, 2024

@rflban, Thank you for the contribution!
You are now eligible for a year of Premium account on MermaidChart.
Sign up with your GitHub account to activate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Graph: Sequence Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using the Create Particpant function fails and can't get rid of the error
4 participants