Skip to content

Redefinition of prototypes introduce side effects in Stories #418

Description

@tbouffard

Describe the bug

There are several stories that redefine the prototype of maxGraph classes to change their default behavior.
However, after navigating to such a story, the behavior of such story is applied to any story visited afterwards.

To Reproduce

Steps to reproduce the behavior:

  1. Go to the 'PerimeterLabelBounds' story
  2. Go to the 'SecondLabels' story, a second label is displayed on top of the rectangle, displaying the id of the cell
  3. Go back to the 'PerimeterLabelBounds' story
  4. The second label is now displayed in the first story

Expected behavior

The specific behavior of a story must not impact other stories.

Screenshots

Impact_of_usage_of_prototype_in_stories

Environment

The problem is present in all environment

Additional context

The code of the stories originally comes from mxGraph examples which where provided as independent pages. So, the changes of the prototype only the page itself.
The stories in maxGraph are run in a Single Page Application, so any change of prototypes impact the rest of the application, so the other stories.

This problem was mentioned long ago in #1 (comment)

Alternatives to the usage of prototype

Most of the time, there are alternatives to prototype change, for example

There are currently some existing limitations to the alternatives, for example when dealing with VertexHandler: #83. So, changes should done in the maxGraph code to provide working alternatives

Possible fix for the SecondLabel story

Instead of directly modifying the prototype of RectangleShape, a new class can be created to override the methods.
Then, the default style can be updated to use this shape instead of the RectangleShape (it may be required to register the shape in CellRenderer with a dedicated name to use it in the default style configuration).

https://github.com/maxGraph/maxGraph/blob/v0.10.2/packages/html/stories/SecondLabel.stories.js#L55-L75

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions