Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support disabling interaction tracing for suspense promises #16776

Merged
merged 2 commits into from
Sep 13, 2019

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Sep 13, 2019

If a thrown Promise has the __reactDoNotTraceInteractions attribute, React will not wrapped its callbacks to continue tracing any current interaction(s).

Example usage:

function SomeComponent() {
  try {
    const value = SomeCache.read(/*...*/);
  } catch (maybePromise) {
    if (typeof value === "object" && typeof value.then === "function") {
      maybePromise.__reactDoNotTraceInteractions = true;
    }
    throw maybePromise;
  }
}

If a thrown Promise has the __reactDoNotTraceInteractions attribute, React will not wrapped its callbacks to continue tracing any current interaction(s).
@bvaughn bvaughn force-pushed the opt-in-dont-trace-for-suspense branch from 4674984 to 986a614 Compare September 13, 2019 15:35
@sizebot
Copy link

sizebot commented Sep 13, 2019

No significant bundle size changes to report.

Generated by 🚫 dangerJS against 434c0e9

@@ -174,7 +174,9 @@ function attachPingListener(
renderExpirationTime,
);
if (enableSchedulerTracing) {
ping = Schedule_tracing_wrap(ping);
if (thenable.__reactDoNotTraceInteractions !== true) {
ping = Schedule_tracing_wrap(ping);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ping part is a bit weird because it means that means that if we’re only suspended on this promise for the first commit I believe it will decrement and complete the interaction before we commit.

I think this only happens if this also happened to cause a “Delayed” suspended state (bad loading) since otherwise we don’t suspend the commit and it’ll continue until it commits.

However fixing this is tricky since we’d have to keep track of this promise and call it once we commit to detach.

Copy link
Contributor Author

@bvaughn bvaughn Sep 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ping part is a bit weird because it means that means that if we’re only suspended on this promise for the first commit I believe it will decrement and complete the interaction before we commit.

Hm... I don't think this is the case, but maybe you can point out what I'm overlooking? We only decrement in finishPendingInteractions, which runs after commit.

Not-wrapping isn't the same as decrementing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to put it is, if this is ok, then it should be ok to remove this wrapper in all cases.

Because this ping is only relevant when there is an in progress render. If the in progress render keeps its own interactions alive then we never need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm...yeah, maybe wrapping the ping listener is never necessary.

@bvaughn bvaughn merged commit d6f6b95 into facebook:master Sep 13, 2019
@bvaughn bvaughn deleted the opt-in-dont-trace-for-suspense branch September 13, 2019 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants