Skip to content

React StrictMode does not work #216

Open

Description

@easbar

see: 40238bf

For example when StrictMode is enabled the maps context menu no longer works and the positioning of the custom model editor is broken.

Activity

  1. easbar commented on Oct 7, 2022

    @easbar
    MemberAuthor

    I think the reason the context menu does not open in strict mode is that the context menu listener is removed here:

    map.getTargetElement().removeEventListener('contextmenu', openContextMenu)

    but it is only added via the map.once('target:change') callback here:

    map.once('change:target', () => {

    Since StrictMode runs the useEffect multiple times the listener is removed but not added again. And the reason we add the listener in this strange way, is that the useEffect is called for the map before it has a target element. Maybe we should do this another way, but currently I don't really know how. The target element is attached here at the moment:

    map.setTarget(mapElement.current!)

  2. changed the title [-]Our app does not work in React StrictMode[/-] [+]React StrictMode does not work[/+] on Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions