Skip to content

Conversation

@hoxyq
Copy link
Contributor

@hoxyq hoxyq commented Oct 22, 2025

This moves the implementation of async stack tagging API to renderer config:

  • DOM: still uses console.createTask().
  • Fabric: will use custom experimental API called RN$unstable_createTask().

Note

We want to implement console.createTask() in React Native as well, it will take us quite some time to support async stack traces in Hermes and then implement async stack tagging APIs properly.

The temporary React Native API will have the same signature, but it doesn't follow the same behaviour or implementation as Chromium's console.createTask().

We are only going to use it at the moment for capturing updates. We won't use it for owner stacks for now, because this API won't implement proper stack tagging, and we don't support async stack traces in Hermes, so we won't be able to recreate full owner stack branches, unfortunately. We don't want to patch console.createTask with local host implementation, because console.createTask is called for every JSX invocation, and we won't get any value from it, but we will capture the stack trace for every call.

This approach aligns with other Web APIs, like scheduleMicrotask, scheduleTimeout, etc.

@meta-cla meta-cla bot added the CLA Signed label Oct 22, 2025
@hoxyq hoxyq force-pushed the async-stack-tagging-api-provided-by-renderer branch from 231b327 to 738c060 Compare October 22, 2025 15:12
Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

Can React Native just patch console.createTask?

console.createTask = RN$unstable_createTask;

@rickhanlonii
Copy link
Member

If we add this to the fiber config, then we should add it to the react-reconciler README, but that's also kinda silly if we're just going to remove it later, which makes me think RN should just do the patching instead.

@hoxyq
Copy link
Contributor Author

hoxyq commented Oct 22, 2025

Can React Native just patch console.createTask?

console.createTask = RN$unstable_createTask;

If we patch it, we will pay the cost of it being called in owner stacks. It is being called for every JSX invocation, and we won't get any value from it, but we will capture the stack trace for every call.

Also, the console.createTask() is non-standard API in Chrome, not even mentioned on MDN, so I think it is fine to fork it there, until we match Chromium's console.createTask() 1:1.

@hoxyq hoxyq force-pushed the async-stack-tagging-api-provided-by-renderer branch from 738c060 to 1549105 Compare October 22, 2025 16:05
@react-sizebot
Copy link

react-sizebot commented Oct 22, 2025

Comparing: 71b3a03...04bc686

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.11% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 605.41 kB 605.41 kB = 107.21 kB 107.22 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB +0.11% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 664.38 kB 664.38 kB = 117.09 kB 117.09 kB
facebook-www/ReactDOM-prod.classic.js = 688.25 kB 688.25 kB = 121.13 kB 121.13 kB
facebook-www/ReactDOM-prod.modern.js = 678.67 kB 678.67 kB = 119.48 kB 119.49 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 04bc686

@hoxyq hoxyq force-pushed the async-stack-tagging-api-provided-by-renderer branch from 1549105 to d22ba54 Compare October 22, 2025 16:13
@hoxyq hoxyq force-pushed the async-stack-tagging-api-provided-by-renderer branch from d22ba54 to 04bc686 Compare October 22, 2025 16:30
@hoxyq
Copy link
Contributor Author

hoxyq commented Oct 22, 2025

I will measure the impact of using console.createTask for owner stacks and will follow-up here. We would follow Chrome's approach on no-oping this API when DevTools are not opened.

If the cost is trivial, we could eliminate this fork.

@hoxyq hoxyq marked this pull request as draft October 22, 2025 18:43
@hoxyq hoxyq closed this Oct 31, 2025
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.

4 participants