Skip to content

chore: stop redux action console flood in dev#7412

Open
diegolmello wants to merge 1 commit into
developfrom
native-1298-redux-devtools
Open

chore: stop redux action console flood in dev#7412
diegolmello wants to merge 1 commit into
developfrom
native-1298-redux-devtools

Conversation

@diegolmello

@diegolmello diegolmello commented Jun 18, 2026

Copy link
Copy Markdown
Member

Proposed changes

In dev builds, reduxLogger logged every dispatched action and the full store state to Metro on each dispatch (console.group/info/log/groupEnd), flooding the console and slowing the dev loop.

This removes the logger from the store wiring and replaces it with inspection surfaces that stay quiet:

  • A silent, dev-only action ring buffer on global.__reduxActions (records each action type + timestamp, capped at 100, oldest dropped). Writes nothing to the console.
  • The store exposed on global.reduxStore (dev only) so current state is readable at runtime by agents.
  • The verbose logger kept available but commented in the store config, so a developer can re-enable it on demand.

Both surfaces live inside the if (__DEV__) branch, so release builds strip them and the production store config is unchanged.

Issue(s)

https://rocketchat.atlassian.net/browse/NATIVE-1298

How to test or reproduce

  1. Run the app in dev (Metro). The Metro console no longer shows per-action dispatching / next state lines.
  2. With the JS debugger attached, read state: globalThis.reduxStore.getState().login.isAuthenticated.
  3. Read recent actions: globalThis.__reduxActions.slice(-10).
  4. Confirm an action fired: globalThis.__reduxActions.some(a => a.type === 'LOGIN_SUCCESS').
  5. To get the old verbose logging back: in app/lib/store/index.ts, uncomment the logger require and the applyMiddleware(logger) line (add a comma after applyMiddleware(actionBuffer())).

Types of changes

  • Improvement (non-breaking change which improves a current function)

Checklist

  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for action tracking middleware, verifying action recording, buffer capacity limits, FIFO removal of oldest entries, and absence of console output.
  • New Features

    • Integrated action tracking middleware in development mode, recording Redux actions with type and timestamp information in a fixed-size buffer of 100 entries with automatic overflow handling.

reduxLogger logged every dispatched action and the full store state to Metro
on each dispatch, drowning out other logs and slowing the dev loop. Replace it
with a silent dev-only action ring buffer (global.__reduxActions, cap 100) and
expose the store on global.reduxStore, so actions and state stay inspectable at
runtime without console noise. The verbose logger stays available, commented in
the store config, for manual re-enable. Production store config is unchanged.
@diegolmello diegolmello temporarily deployed to approve_e2e_testing June 18, 2026 20:59 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

A new actionBuffer Redux middleware is added that records dispatched action types with timestamps into a global array capped at 100 entries. In development mode, this middleware replaces reduxLogger in the store enhancer chain, and the store instance is assigned to global.reduxStore after sagas start. A Jest test suite validates the buffer's append, FIFO cap, and no-console-output behavior.

Changes

actionBuffer middleware and store wiring

Layer / File(s) Summary
actionBuffer middleware implementation and tests
app/lib/store/actionBuffer.ts, app/lib/store/actionBuffer.test.ts
Exports the actionBuffer middleware factory that pushes { type, t: Date.now() } to global.__reduxActions and calls shift() when the buffer exceeds a CAP of 100. Tests cover single-action append, FIFO cap enforcement after 110 dispatches, and silence of console.log/info/group/groupEnd.
Store wiring: replace reduxLogger, expose global store
app/lib/store/index.ts
In the __DEV__ branch, reduxLogger is removed and actionBuffer is loaded via require and inserted into the composed enhancer middleware list. After sagas are started, global.reduxStore is assigned the created store instance.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: chore

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely describes the main objective of the PR: removing Redux action console logging in development mode to reduce console noise.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • NATIVE-1298: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/lib/store/index.ts (1)

36-38: ⚡ Quick win

Type the dev global store handle instead of casting to any.

This debug API is useful, but the any cast removes compile-time safety for callers and future maintenance.

♻️ Proposed refactor
 if (__DEV__) {
-	(global as any).reduxStore = store;
+	global.reduxStore = store;
 }

Add a shared declare global for reduxStore (alongside __reduxActions) so both debug globals stay strongly typed.

As per coding guidelines, "Use TypeScript for type safety; add explicit type annotations to function parameters and return types".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/lib/store/index.ts` around lines 36 - 38, Remove the unsafe `any` cast
from the global store assignment in the development block where `(global as
any).reduxStore = store` is defined. Instead, add a shared `declare global`
statement (similar to how `__reduxActions` is declared) that properly types the
`reduxStore` property on the global object with the correct Redux Store type.
This will eliminate the type safety hole created by the cast and provide
compile-time type checking for all callers accessing this debug API.

Source: Coding guidelines

app/lib/store/actionBuffer.ts (1)

3-6: Improve global type safety for the debug action buffer using TypeScript's declare global.

The current (global as any) pattern bypasses TypeScript type-checking on the shared global state. Use a typed global augmentation with interfaces instead.

♻️ Proposed refactor
+interface BufferedReduxAction {
+	type: unknown;
+}
+
+interface BufferedActionEntry {
+	type: unknown;
+	t: number;
+}
+
+declare global {
+	// eslint-disable-next-line no-var
+	var __reduxActions: BufferedActionEntry[] | undefined;
+}
+
 const CAP = 100;
 
 export const actionBuffer = () => (_store: any) => (next: any) => (action: any) => {
-	(global as any).__reduxActions ??= [];
-	const buf = (global as any).__reduxActions;
+	global.__reduxActions ??= [];
+	const buf = global.__reduxActions;
 	buf.push({ type: action.type, t: Date.now() });
 	if (buf.length > CAP) buf.shift();
 	return next(action);
 };

This approach follows the TypeScript guideline: "Use TypeScript for type safety; add explicit type annotations" and "Prefer interfaces over type shapes."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/lib/store/actionBuffer.ts` around lines 3 - 6, The actionBuffer
middleware uses `(global as any)` type assertions which bypass TypeScript's type
checking for the shared global `__reduxActions` state. Instead of using `any`,
add a TypeScript `declare global` block with an interface that properly augments
the global namespace to type the `__reduxActions` property as an array with the
shape containing type and timestamp fields. This way, when accessing `(global as
any).__reduxActions` in the actionBuffer function, you can replace the `any`
assertions with the properly typed global object, maintaining type safety
throughout the middleware.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/lib/store/actionBuffer.test.ts`:
- Around line 33-50: The console spy restorations in the test
(logSpy.mockRestore, infoSpy.mockRestore, groupSpy.mockRestore,
groupEndSpy.mockRestore) are only called if all assertions pass, leaving the
mocks in place if any assertion fails. Move the restoration calls to an
afterEach hook to ensure cleanup happens regardless of test outcome, or wrap the
spy setup and test logic in a try-finally block where the finally clause
contains all mockRestore calls. This guarantees that the mocked console.log,
console.info, console.group, and console.groupEnd methods are properly restored
even when tests fail.

---

Nitpick comments:
In `@app/lib/store/actionBuffer.ts`:
- Around line 3-6: The actionBuffer middleware uses `(global as any)` type
assertions which bypass TypeScript's type checking for the shared global
`__reduxActions` state. Instead of using `any`, add a TypeScript `declare
global` block with an interface that properly augments the global namespace to
type the `__reduxActions` property as an array with the shape containing type
and timestamp fields. This way, when accessing `(global as any).__reduxActions`
in the actionBuffer function, you can replace the `any` assertions with the
properly typed global object, maintaining type safety throughout the middleware.

In `@app/lib/store/index.ts`:
- Around line 36-38: Remove the unsafe `any` cast from the global store
assignment in the development block where `(global as any).reduxStore = store`
is defined. Instead, add a shared `declare global` statement (similar to how
`__reduxActions` is declared) that properly types the `reduxStore` property on
the global object with the correct Redux Store type. This will eliminate the
type safety hole created by the cast and provide compile-time type checking for
all callers accessing this debug API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5530592-21d5-4bc3-9851-9915a5716970

📥 Commits

Reviewing files that changed from the base of the PR and between e208c91 and 399790d.

📒 Files selected for processing (3)
  • app/lib/store/actionBuffer.test.ts
  • app/lib/store/actionBuffer.ts
  • app/lib/store/index.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: ESLint and Test / run-eslint-and-test
  • GitHub Check: format
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions

Files:

  • app/lib/store/actionBuffer.ts
  • app/lib/store/actionBuffer.test.ts
  • app/lib/store/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Prefer interfaces over type aliases for defining object shapes in TypeScript
Use enums for sets of related constants rather than magic strings or numbers

Use TypeScript with strict mode enabled

Files:

  • app/lib/store/actionBuffer.ts
  • app/lib/store/actionBuffer.test.ts
  • app/lib/store/index.ts
**/*.{js,jsx,ts,tsx,json}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Prettier formatting with tabs, single quotes, 130 character line width, no trailing commas, and avoid arrow function parentheses

Files:

  • app/lib/store/actionBuffer.ts
  • app/lib/store/actionBuffer.test.ts
  • app/lib/store/index.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Enforce ESLint rules from @rocket.chat/eslint-config with React, React Native, TypeScript, and Jest plugins

Files:

  • app/lib/store/actionBuffer.ts
  • app/lib/store/actionBuffer.test.ts
  • app/lib/store/index.ts
app/lib/store/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Store Redux store configuration in 'app/lib/store/' directory

Files:

  • app/lib/store/actionBuffer.ts
  • app/lib/store/actionBuffer.test.ts
  • app/lib/store/index.ts
🧠 Learnings (1)
📚 Learning: 2026-04-30T17:07:51.020Z
Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7274
File: app/lib/services/voip/MediaCallEvents.ts:0-0
Timestamp: 2026-04-30T17:07:51.020Z
Learning: In this Rocket.Chat React Native codebase, the ESLint rule `no-void: error` is enforced. When you see a promise returned from an async call that is not awaited (a “floating promise”), do not silence it with the `void somePromise()` pattern. Instead, handle the promise explicitly by attaching `.catch(...)` (or otherwise awaiting/handling the error) so unhandled-rejection risks are addressed in a way that satisfies the existing ESLint configuration.

Applied to files:

  • app/lib/store/actionBuffer.ts
  • app/lib/store/actionBuffer.test.ts
  • app/lib/store/index.ts

Comment thread app/lib/store/actionBuffer.test.ts
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

iOS Build Available

Rocket.Chat 4.74.0.109152

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.

1 participant