Skip to content

Commit 597a1b2

Browse files
committed
enhance: Correctly log throttlable fetch actions in devtool
1 parent 06df291 commit 597a1b2

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

.changeset/hip-donkeys-matter.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@data-client/core': patch
3+
'@data-client/react': patch
4+
---
5+
6+
Disable devtools dispatch feature as it is not usable

.changeset/rude-donuts-smell.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@data-client/core': patch
3+
'@data-client/react': patch
4+
---
5+
6+
fix: Devtools correctly logs fetch actions
7+
8+
We inspect fetches against inflight to see if they are throttled;
9+
However, we previously did this after we sent the action to NetworkManager, which
10+
meant it would also skip logging any throttlable fetches - even if they were not throttled.

.changeset/wild-rabbits-joke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@data-client/core': patch
3+
'@data-client/react': patch
4+
---
5+
6+
Improve typing for devtools options

packages/core/src/manager/DevtoolsManager.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ if (process.env.NODE_ENV !== 'production') {
3737
DEFAULT_CONFIG = {
3838
name: `Data Client: ${globalThis.document?.title}`,
3939
autoPause: true,
40+
features: {
41+
pause: true, // start/pause recording of dispatched actions
42+
lock: true, // lock/unlock dispatching actions and side effects
43+
persist: false, // persist states on page reloading
44+
export: true, // export history of actions in a file
45+
import: 'custom', // import history of actions from a file
46+
jump: true, // jump back and forth (time travelling)
47+
skip: true, // skip (cancel) actions
48+
reorder: true, // drag and drop actions in the history list
49+
dispatch: false, // dispatch custom actions or action creators
50+
test: false, // generate tests for the selected actions
51+
},
4052
actionSanitizer: (action: ActionTypes) => {
4153
if (!('endpoint' in action)) return action;
4254
return {
@@ -131,6 +143,7 @@ export default class DevToolsManager implements Manager {
131143
const reducer = createReducer(controller as any);
132144
let state = controller.getState();
133145
return next => action => {
146+
const shouldSkip = skipLogging?.(action);
134147
const ret = next(action);
135148
if (this.started) {
136149
// we track state changes here since getState() will only update after a batch commit
@@ -139,7 +152,7 @@ export default class DevToolsManager implements Manager {
139152
state = controller.getState();
140153
}
141154
ret.then(() => {
142-
if (skipLogging?.(action)) return;
155+
if (shouldSkip) return;
143156
this.handleAction(action, state.optimistic.reduce(reducer, state));
144157
});
145158
return ret;

packages/core/src/manager/devtoolsTypes.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
type Action = any;
1+
import { ActionTypes } from '../actions.js';
2+
import { State } from '../types.js';
3+
4+
type Action = ActionTypes;
25
type ActionCreator<T> = any;
36

47
// taken from https://github.com/reduxjs/redux-devtools/blob/main/packages/redux-devtools-extension/src/index.ts
@@ -78,7 +81,7 @@ export interface EnhancerOptions {
7881
/**
7982
* function which takes `state` object and index as arguments, and should return `state` object back.
8083
*/
81-
stateSanitizer?: <S>(state: S, index: number) => S;
84+
stateSanitizer?: <S extends State<unknown>>(state: S, index: number) => S;
8285
/**
8386
* *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).
8487
* If `actionsWhitelist` specified, `actionsBlacklist` is ignored.
@@ -105,7 +108,10 @@ export interface EnhancerOptions {
105108
* called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor.
106109
* Use it as a more advanced version of `actionsDenylist`/`actionsAllowlist` parameters.
107110
*/
108-
predicate?: <S, A extends Action>(state: S, action: A) => boolean;
111+
predicate?: <S extends State<unknown>, A extends Action>(
112+
state: S,
113+
action: A,
114+
) => boolean;
109115
/**
110116
* if specified as `false`, it will not record the changes till clicking on `Start recording` button.
111117
* Available only for Redux enhancer, for others use `autoPause`.

website/src/components/Playground/editor-types/@data-client/core.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ declare class PollingSubscription implements Subscription {
876876
protected lastFetchTime(): number;
877877
}
878878

879-
type Action = any;
879+
type Action = ActionTypes;
880880
type ActionCreator<T> = any;
881881
interface EnhancerOptions {
882882
/**
@@ -950,7 +950,7 @@ interface EnhancerOptions {
950950
/**
951951
* function which takes `state` object and index as arguments, and should return `state` object back.
952952
*/
953-
stateSanitizer?: <S>(state: S, index: number) => S;
953+
stateSanitizer?: <S extends State<unknown>>(state: S, index: number) => S;
954954
/**
955955
* *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).
956956
* If `actionsWhitelist` specified, `actionsBlacklist` is ignored.
@@ -977,7 +977,7 @@ interface EnhancerOptions {
977977
* called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor.
978978
* Use it as a more advanced version of `actionsDenylist`/`actionsAllowlist` parameters.
979979
*/
980-
predicate?: <S, A extends Action>(state: S, action: A) => boolean;
980+
predicate?: <S extends State<unknown>, A extends Action>(state: S, action: A) => boolean;
981981
/**
982982
* if specified as `false`, it will not record the changes till clicking on `Start recording` button.
983983
* Available only for Redux enhancer, for others use `autoPause`.

0 commit comments

Comments
 (0)