Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/react-devtools-shared/src/__tests__/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,19 @@ describe('utils', () => {
]);
});

it('should strip the async prefix from a frame name', () => {
expect(
extractLocationFromComponentStack(
' at async Comments (https://react.dev/_next/static/chunks/848-122f91e9565d9ffa.js:5:9236)',
),
).toEqual([
'Comments',
'https://react.dev/_next/static/chunks/848-122f91e9565d9ffa.js',
5,
9236,
]);
});

it('should support Firefox stack', () => {
expect(
extractLocationFromComponentStack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function parseStackTraceFromChromeStack(
if (name === '<anonymous>') {
name = '';
} else if (name.startsWith('async ')) {
name = name.slice(5);
name = name.slice(6);
isAsync = true;
}
let filename = parsed[2] || parsed[5] || '';
Expand Down
5 changes: 4 additions & 1 deletion packages/react-dom-bindings/src/events/DOMEventNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export type DOMEventName =
| 'abort'
| 'afterblur' // Not a real event. This is used by event experiments.
// These are vendor-prefixed so you should use the exported constants instead:
// 'animationcancel' |
// 'animationiteration' |
// 'animationend |
// 'animationend' |
// 'animationstart' |
| 'beforeblur' // Not a real event. This is used by event experiments.
| 'beforeinput'
Expand Down Expand Up @@ -115,6 +116,8 @@ export type DOMEventName =
| 'waiting'
| 'wheel';

export const ANIMATION_CANCEL: DOMEventName =
getVendorPrefixedEventName('animationcancel');
export const ANIMATION_END: DOMEventName =
getVendorPrefixedEventName('animationend');
export const ANIMATION_ITERATION: DOMEventName =
Expand Down
2 changes: 2 additions & 0 deletions packages/react-dom-bindings/src/events/DOMEventProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {DOMEventName} from './DOMEventNames';

import {registerTwoPhaseEvent} from './EventRegistry';
import {
ANIMATION_CANCEL,
ANIMATION_END,
ANIMATION_ITERATION,
ANIMATION_START,
Expand Down Expand Up @@ -135,6 +136,7 @@ export function registerSimpleEvents() {
registerSimpleEvent(domEventName, 'on' + capitalizedEvent);
}
// Special cases where event names don't match.
registerSimpleEvent(ANIMATION_CANCEL, 'onAnimationCancel');
registerSimpleEvent(ANIMATION_END, 'onAnimationEnd');
registerSimpleEvent(ANIMATION_ITERATION, 'onAnimationIteration');
registerSimpleEvent(ANIMATION_START, 'onAnimationStart');
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom-bindings/src/events/TopLevelEventTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
export type TopLevelType =
| 'abort'
// Dynamic and vendor-prefixed at the usage site:
// 'animationcancel' |
// 'animationiteration' |
// 'animationend |
// 'animationend' |
// 'animationstart' |
| 'canplay'
| 'canplaythrough'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function makePrefixMap(styleProp, eventName) {
* A list of event names to a configurable list of vendor prefixes.
*/
const vendorPrefixes = {
animationcancel: makePrefixMap('Animation', 'AnimationCancel'),
animationend: makePrefixMap('Animation', 'AnimationEnd'),
animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
animationstart: makePrefixMap('Animation', 'AnimationStart'),
Expand Down Expand Up @@ -58,6 +59,7 @@ if (canUseDOM) {
// style object but the events that fire will still be prefixed, so we need
// to check if the un-prefixed events are usable, and if not remove them from the map.
if (!('AnimationEvent' in window)) {
delete vendorPrefixes.animationcancel.animation;
delete vendorPrefixes.animationend.animation;
delete vendorPrefixes.animationiteration.animation;
delete vendorPrefixes.animationstart.animation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '../../events/SyntheticEvent';

import {
ANIMATION_CANCEL,
ANIMATION_END,
ANIMATION_ITERATION,
ANIMATION_START,
Expand Down Expand Up @@ -133,6 +134,7 @@ function extractEvents(
case 'touchstart':
SyntheticEventCtor = SyntheticTouchEvent;
break;
case ANIMATION_CANCEL:
case ANIMATION_END:
case ANIMATION_ITERATION:
case ANIMATION_START:
Expand Down
17 changes: 17 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ describe('ReactDOMEventListener', () => {
}

describe('bubbling events', () => {
it('onAnimationCancel', async () => {
await testNativeBubblingEvent({
type: 'div',
reactEvent: 'onAnimationCancel',
reactEventType: 'animationcancel',
nativeEvent: 'animationcancel',
dispatch(node) {
node.dispatchEvent(
new Event('animationcancel', {
bubbles: true,
cancelable: false,
}),
);
},
});
});

it('onAnimationEnd', async () => {
await testNativeBubblingEvent({
type: 'div',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/

'use strict';

let React;
let ReactDOMClient;
let act;

describe('SyntheticAnimationEvent', () => {
let container;
let root;

beforeEach(() => {
React = require('react');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;

// The container has to be attached for events to fire.
container = document.createElement('div');
document.body.appendChild(container);
root = ReactDOMClient.createRoot(container);
});

afterEach(() => {
document.body.removeChild(container);
container = null;
});

it('should normalize properties from the AnimationEvent interface for onAnimationCancel', async () => {
const events = [];
const onAnimationCancel = event => {
event.persist();
events.push(event);
};
await act(async () => {
root.render(<div onAnimationCancel={onAnimationCancel} />);
});

const event = new Event('animationcancel', {bubbles: true});
// jsdom doesn't implement AnimationEvent so we add the fields manually.
Object.assign(event, {
animationName: 'fade',
elapsedTime: 0.5,
pseudoElement: '::before',
});
container.firstChild.dispatchEvent(event);

expect(events.length).toBe(1);
expect(events[0].type).toBe('animationcancel');
expect(events[0].animationName).toBe('fade');
expect(events[0].elapsedTime).toBe(0.5);
expect(events[0].pseudoElement).toBe('::before');
});
});
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactFlightStackConfigV8.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export function parseStackTrace(
if (name === '<anonymous>') {
name = '';
} else if (name.startsWith('async ')) {
name = name.slice(5);
name = name.slice(6);
isAsync = true;
}
let filename = parsed[2] || parsed[5] || '';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';

let parseStackTrace;

describe('ReactFlightStackConfigV8', () => {
beforeEach(() => {
jest.resetModules();
parseStackTrace =
require('react-server/src/ReactFlightStackConfigV8').parseStackTrace;
});

// @gate __DEV__
it('strips the async prefix from a frame name in an already formatted stack', () => {
const error = new Error();
// Assigning the stack means V8 never calls prepareStackTrace, so the
// parser has to fall back to reading the formatted string.
error.stack =
'Error: boom\n' +
' at inner (/tmp/app.js:1:44)\n' +
' at async outerName (/tmp/app.js:2:30)';

expect(parseStackTrace(error, 1)).toEqual([
['inner', '/tmp/app.js', 1, 44, 0, 0, false],
['outerName', '/tmp/app.js', 2, 30, 0, 0, true],
]);
});
});
Loading