@@ -2512,6 +2512,112 @@ describe('DOMModernPluginEventSystem', () => {
25122512 // <button>, which is actually outside the scope.
25132513 expect ( clickEvent ) . toBeCalledTimes ( 0 ) ;
25142514 } ) ;
2515+
2516+ it ( 'handle stopPropagation (inner) correctly between scopes' , ( ) => {
2517+ const buttonRef = React . createRef ( ) ;
2518+ const outerOnClick = jest . fn ( ) ;
2519+ const innerOnClick = jest . fn ( e => e . stopPropagation ( ) ) ;
2520+ const TestScope = React . unstable_createScope ( ) ;
2521+ const TestScope2 = React . unstable_createScope ( ) ;
2522+
2523+ function Test ( ) {
2524+ const click = ReactDOM . unstable_useEvent ( 'click' ) ;
2525+ const scopeRef = React . useRef ( null ) ;
2526+ const scope2Ref = React . useRef ( null ) ;
2527+
2528+ React . useEffect ( ( ) => {
2529+ click . setListener ( scopeRef . current , outerOnClick ) ;
2530+ click . setListener ( scope2Ref . current , innerOnClick ) ;
2531+ } ) ;
2532+
2533+ return (
2534+ < TestScope ref = { scopeRef } >
2535+ < TestScope2 ref = { scope2Ref } >
2536+ < button ref = { buttonRef } />
2537+ </ TestScope2 >
2538+ </ TestScope >
2539+ ) ;
2540+ }
2541+
2542+ ReactDOM . render ( < Test /> , container ) ;
2543+ Scheduler . unstable_flushAll ( ) ;
2544+
2545+ const buttonElement = buttonRef . current ;
2546+ dispatchClickEvent ( buttonElement ) ;
2547+
2548+ expect ( innerOnClick ) . toHaveBeenCalledTimes ( 1 ) ;
2549+ expect ( outerOnClick ) . toHaveBeenCalledTimes ( 0 ) ;
2550+ } ) ;
2551+
2552+ it ( 'handle stopPropagation (outer) correctly between scopes' , ( ) => {
2553+ const buttonRef = React . createRef ( ) ;
2554+ const outerOnClick = jest . fn ( e => e . stopPropagation ( ) ) ;
2555+ const innerOnClick = jest . fn ( ) ;
2556+ const TestScope = React . unstable_createScope ( ) ;
2557+ const TestScope2 = React . unstable_createScope ( ) ;
2558+
2559+ function Test ( ) {
2560+ const click = ReactDOM . unstable_useEvent ( 'click' ) ;
2561+ const scopeRef = React . useRef ( null ) ;
2562+ const scope2Ref = React . useRef ( null ) ;
2563+
2564+ React . useEffect ( ( ) => {
2565+ click . setListener ( scopeRef . current , outerOnClick ) ;
2566+ click . setListener ( scope2Ref . current , innerOnClick ) ;
2567+ } ) ;
2568+
2569+ return (
2570+ < TestScope ref = { scopeRef } >
2571+ < TestScope2 ref = { scope2Ref } >
2572+ < button ref = { buttonRef } />
2573+ </ TestScope2 >
2574+ </ TestScope >
2575+ ) ;
2576+ }
2577+
2578+ ReactDOM . render ( < Test /> , container ) ;
2579+ Scheduler . unstable_flushAll ( ) ;
2580+
2581+ const buttonElement = buttonRef . current ;
2582+ dispatchClickEvent ( buttonElement ) ;
2583+
2584+ expect ( innerOnClick ) . toHaveBeenCalledTimes ( 1 ) ;
2585+ expect ( outerOnClick ) . toHaveBeenCalledTimes ( 1 ) ;
2586+ } ) ;
2587+
2588+ it ( 'handle stopPropagation (inner and outer) correctly between scopes' , ( ) => {
2589+ const buttonRef = React . createRef ( ) ;
2590+ const onClick = jest . fn ( e => e . stopPropagation ( ) ) ;
2591+ const TestScope = React . unstable_createScope ( ) ;
2592+ const TestScope2 = React . unstable_createScope ( ) ;
2593+
2594+ function Test ( ) {
2595+ const click = ReactDOM . unstable_useEvent ( 'click' ) ;
2596+ const scopeRef = React . useRef ( null ) ;
2597+ const scope2Ref = React . useRef ( null ) ;
2598+
2599+ React . useEffect ( ( ) => {
2600+ click . setListener ( scopeRef . current , onClick ) ;
2601+ click . setListener ( scope2Ref . current , onClick ) ;
2602+ } ) ;
2603+
2604+ return (
2605+ < TestScope ref = { scopeRef } >
2606+ < TestScope2 ref = { scope2Ref } >
2607+ < button ref = { buttonRef } />
2608+ </ TestScope2 >
2609+ </ TestScope >
2610+ ) ;
2611+ }
2612+
2613+ ReactDOM . render ( < Test /> , container ) ;
2614+ Scheduler . unstable_flushAll ( ) ;
2615+
2616+ const buttonElement = buttonRef . current ;
2617+ dispatchClickEvent ( buttonElement ) ;
2618+
2619+ expect ( onClick ) . toHaveBeenCalledTimes ( 1 ) ;
2620+ } ) ;
25152621 } ) ;
25162622 } ) ;
25172623 } ,
0 commit comments