Skip to content

[React 19] [bug] SVG with dangerouslySetInnerHTML content does not trigger first click #30994

Open
@zdravkov

Description

@zdravkov

Summary

Hi all,

Here is the scenario that we found out while testing with both the latest rc and the beta that works correctly with React 18.
We have an SVG element that does not trigger its first click if it is focusable (or positioned inside a focusable element) that changes some state on focus.

Steps to reproduce:
Open the Stackblitz example and open its console
Click 1 time on the triangle svg element
Expected:
'svg click' message is logged
Current:
no message is logged

(On the second and all next clicks the message is shown as expected - only the first click is not triggered)
Here are the stackblitz examples where the issue can be observed:
rc: https://stackblitz.com/edit/react-vsxt51-w3ktmp?file=app%2Fapp.tsx - not working
beta: https://stackblitz.com/edit/react-vsxt51-ssqptj?file=app%2Fapp.tsx - not working
And here is how it is working in React 18:
React 18: https://stackblitz.com/edit/react-vsxt51-xsg1yu?file=app%2Fapp.tsx - working

Code:

const App = () => {
  const [focused, setFocused] = React.useState(false);
  const handleFocus = () => {
    setFocused(true);
  };

  return (
    <svg
      onFocus={handleFocus}
      tabIndex={1}
      onClick={() => {
        console.log('svg click');
      }}
      viewBox="0 0 512 512"
      dangerouslySetInnerHTML={{
        __html: '<path d="M256 352 128 160h256z" />',
      }}
    ></svg>
  );
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions