Skip to content

Commit

Permalink
[Flare] Adds support for hydrating host components with listeners (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Aug 6, 2019
1 parent ed49700 commit 7c838a6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,35 @@ describe('DOMEventResponderSystem', () => {
expect(output).toBe(`<div data-reactroot="">Hello world</div>`);
});

it('can render correctly with the ReactDOMServer hydration', () => {
const onEvent = jest.fn();
const TestResponder = createEventResponder({
targetEventTypes: ['click'],
onEvent,
});
const ref = React.createRef();

function Test() {
const listener = React.unstable_useResponder(TestResponder, {});

return (
<div>
<span listeners={listener} ref={ref}>
Hello world
</span>
</div>
);
}
const output = ReactDOMServer.renderToString(<Test />);
expect(output).toBe(
`<div data-reactroot=""><span>Hello world</span></div>`,
);
container.innerHTML = output;
ReactDOM.hydrate(<Test />, container);
dispatchClickEvent(ref.current);
expect(onEvent).toHaveBeenCalledTimes(1);
});

it('the event responders should fire on click event', () => {
let eventResponderFiredCount = 0;
let eventLog = [];
Expand Down
12 changes: 12 additions & 0 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,18 @@ function completeWork(
// commit-phase we mark this as such.
markUpdate(workInProgress);
}
if (enableFlareAPI) {
const instance = workInProgress.stateNode;
const listeners = newProps.listeners;
if (listeners != null) {
updateEventListeners(
listeners,
instance,
rootContainerInstance,
workInProgress,
);
}
}
} else {
let instance = createInstance(
type,
Expand Down

0 comments on commit 7c838a6

Please sign in to comment.