-
Notifications
You must be signed in to change notification settings - Fork 424
Ensure react lazy initializer is in the top generator body #2026
Ensure react lazy initializer is in the top generator body #2026
Conversation
src/serializer/Emitter.js
Outdated
while (topBody.parentBody !== undefined) { | ||
topBody = topBody.parentBody; | ||
} | ||
// temproarily set the body to be the top parent body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spelling
src/serializer/Emitter.js
Outdated
@@ -504,4 +504,17 @@ export class Emitter { | |||
invariant(!this._finalized); | |||
return new BodyReference(this._body, this._body.entries.length); | |||
} | |||
emitLazyReactElementInitializer(statement: BabelNodeStatement): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer it if we don't add such special cases to the Emitter. The Emitter is already confusing enough...
@@ -96,7 +96,7 @@ export class ResidualReactElementSerializer { | |||
t.callExpression(funcId, originalCreateElementIdentifier ? [originalCreateElementIdentifier] : []) | |||
) | |||
); | |||
this.residualHeapSerializer.emitter.emit(statement); | |||
this.residualHeapSerializer.emitter.emitLazyReactElementInitializer(statement); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this intends to do what I think it does, then you want to do the following:
- Pass the result of
this.residualHeapSerializer.isReferencedOnlyByAdditionalFunction(value)
(currently evaluated by caller) into this function; let's call itadditionalFunction
. It should be defined by construction. - Then replace this line with the following:
this.residualHeapSerializer._getPrelude(additionalFunction).push(statement);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly what I want to do!
@NTillmann are you happy with the requested changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Release notes: none
We need to ensure we emit the ReactElement lazy initializer is in the top generator body (the function body) of the React component render. If we emit it in a nested generator body, it may not get called in the right place after we've nested many components. This also renames a bunch of functions to optimized functions rather than additional functions.
I've got an issue tracking the progress on a follow up PR to add regression tests for this PR: #2027