yahoo/react-i13n

[Version v3.0.0-alpha.8] get an unexpected root i13nNode in `created` event handler in existing plugins (ex. Rapid Plugin)

caa1211 opened this issue · 3 comments

Description

After setup an i13nAnchor component by using react-i13n@3.0.0-alpha8, get an unexpected root i13nNode in created event handler in existing plugins (ex. Rapid Plugin)

3.x version's payload.i13nNode is a root node (_DOMNode is body) in the plugin

2E7276E9-3D64-49BD-9794-F36DFA5794BB

2.x version's payload.i13nNode is a correct node (_DOMNode is a, it's an i13nAnchor) in the plugin

90521513-772A-4ABC-97E1-9E9189924309

It causes Rapid plugin (or any plugins need i13nNode) be broken for LinkView because of incorrect i13node and related model.

Root Cause

In the 2.x version

After executeI13nEvent with an empty object in comoonentDidMount
https://github.com/yahoo/react-i13n/blob/2.x/src/libs/ComponentSpecs.js#L161

payload.i13nNode will run a fallback for getting a i13nNode

payload.i13nNode = payload.i13nNode || this.getI13nNode();

And getI13nNode() will return current i13nNode (_i13nNode) or parentI13nNode as below

 this._i13nNode || this._getParentI13nNode();

In this case, payload will contain current i13nNode (_i13nNode) before sending to the handler
image

But in 3.x version

After executEvent with an empty object, nowhere do the same fallback logic before sending the event, so payload.i13nNode become to a root node.
I thought It would be an unexpected result otherwise causing a breaking changes for all plugins which need i13nNode for operations.

My Code Tracing in version 3.x:

useEffect
->
executeI13nEvent
image
->
execute (Even though there is a fallback in execute, but no current i13nNode in payload, so it fallbacks to the root node and is not the same logic as the 2.x version. After this line, payload.i13nNode become a root body node )
image
->
executeEvent
image

According to the code tracing, react-i13n v3 has a different payload.i13nNode in this case, and leads the different result in the Rapid Plugin. The count of module views will be lost.

@caa1211 Is this still an issue?

@redonkulus Confirmed, the issue is fixed.

Ok thank you.