Skip to content

Bug: React.StrictMode breaks component that manage global object to break dependency between 2 related contexts #21930

Closed
@Eliav2

Description

@Eliav2

I've just released v2.0 of a react-xarrows it breaks on apps that are wrapped with React.StrictMode. the component works perfectly fine on trees that are not wrapped with React.StrictMode

React version: 17.0.0

Steps To Reproduce

simple demo

code sandbox

ready to use dev enviroment

it takes about a minute to set up. this env will link react-xarrows to the running example on port 300, so any changes on ./src would immediately be reflected.

Open in Gitpod

  1. after entering to gitpod, wait to setup.
  2. explore the demos, they work fine.
  3. the index file of create-react-app should be opened. if not go to ./examples/src/index.jsx .
  4. on render function of react-dom replace <ExamplePage /> with <React.StrictMode><ExamplePage /></React.StrictMode>
  5. refresh the page(in the mini gitpod browser on the right, not the main page).
  6. explore demos. The component does not behave the same!

I've tested the lifecycle of react-xarrows in both mods and it appears to be identical, so I can't figure out why apps that use strictmode breaks react-xarrows. I could not figure out why react-xarrows is not printed in StrictMode,

related and possible cause

  • react-arrows v2 manage global object of references to update functions to break the dependency between 2 related contexts. details, Xwrapper code.
    In simple words - I use a global object in the module Xwrapper.tsx, I pass a reference to this object to both contexts, then one context assigning 'update function'(a function that will cause xarrow to rerender) as a property and the second context consumes that function, and then elements connected to xarrow can selectively rerender only xarrow without triggering renders on other boxes.
    I thought that maybe the fact that on StrictMode each render becomes 2 renders causing this issue, but it does not seem to be the problem.

The current behavior

react-xarrows does not work properly on react-trees wrapped with React.StrictMode

The expected behavior

the behavior should be identical in both cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions