Skip to content

Conversation

@bheemreddy-samsara
Copy link
Contributor

@bheemreddy-samsara bheemreddy-samsara commented Jan 22, 2026

Summary

  • Adds console forwarding from device to host for better debugging experience
  • Uses unstable_batchedUpdates to prevent React act() warnings during testing
  • Adds proper TypeScript types for console events in bridge package

What changed

Bridge package (packages/bridge/)

  • shared/console.ts (new): Added ConsoleEvent and ConsoleLevel types
  • shared.ts: Export console types and add ConsoleEvent to BridgeEvents union

Jest package (packages/jest/)

  • harness.ts:
    • Added proper generic constraints for on/off methods using BridgeServerEvents
    • Removed loose string type in favor of typed event names
  • index.ts:
    • Import ConsoleEvent from bridge package instead of local definition
    • Added printf-style string interpolation (%s, %d, %i, %o, %O, %j)
    • Fixed %d to use Number() (preserves decimals) vs %i uses parseInt() (integers only)
    • Added colored console output using chalk (LOG, WARN, ERROR, INFO, DEBUG tags)

Runtime package (packages/runtime/)

  • utils/batchedUpdate.ts (new): Shared utility wrapping unstable_batchedUpdates
  • render/utils.ts (new): resetRenderState() helper for common state reset pattern
  • render/cleanup.ts: Simplified using resetRenderState() helper
  • render/index.ts: Uses shared batchedUpdate and resetRenderState utilities
  • client/factory.ts:
    • Removed type assertion now that ConsoleEvent is in BridgeEvents
    • Preserves Error details (stack/message) instead of serializing to {}

Test plan

  • TypeScript compilation passes
  • Lint passes
  • Run existing tests to verify no regressions
  • Test console forwarding by adding console.log statements in test files
  • Verify act() warnings are no longer appearing
  • Test error forwarding with console.error(new Error('test'))

@vercel
Copy link

vercel bot commented Jan 22, 2026

@bheemreddy-samsara is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@bheemreddy-samsara bheemreddy-samsara force-pushed the bheemreddy-samsara/console-forwarding-and-batched-updates branch from 5f9bae7 to ae5e7b8 Compare January 22, 2026 01:08
@bheemreddy-samsara bheemreddy-samsara changed the title feat(runtime,jest): add console forwarding and batched state updates feat(runtime,jest,bridge): add console forwarding and batched state updates Jan 22, 2026
…pdates

Console Forwarding:
- Forward console.log/warn/error/info/debug from device to Jest output
- Add ConsoleEvent/ConsoleLevel types to BridgeEvents union
- Preserve Error details (stack/message) in forwarded output
- Fix %d printf placeholder to use Number() for decimals

Type Improvements:
- Remove type assertions in factory.ts with proper ConsoleEvent types
- Add proper generic constraints for Harness.on/off methods
- Import shared ConsoleEvent type in jest package

Shared Utilities:
- Extract batchedUpdate utility to avoid code duplication
- Add resetRenderState helper for common state reset pattern
- Simplify render/cleanup.ts using shared utilities
@bheemreddy-samsara bheemreddy-samsara force-pushed the bheemreddy-samsara/console-forwarding-and-batched-updates branch from ae5e7b8 to 55a1412 Compare January 22, 2026 04:54
Comment on lines +4 to +5
* Batches state updates to avoid act() warnings in React Native.
* Falls back to direct execution if unstable_batchedUpdates is unavailable.
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not see 'act' warnings as this is a normal React Native app. Could you provide a code sample where it happens?

Copy link
Contributor

@V3RON V3RON left a comment

Choose a reason for hiding this comment

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

https://github.com/facebook/metro/blob/5ca584bac37b46f4cb171ff0d88dbceaa80f1dc8/packages/metro/src/HmrServer.js#L226

If you enable 'server.forwardClientLogs' via @react-native-harness/metro, you should see client_log events being reported by the Metro reporter in @react-native-harness/bundler-metro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants