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
performance.mark
is not always available
#655
Comments
PRs are very welcome! There already is a check in the code - https://github.com/bhovhannes/redux-profiler/blob/main/src/index.js#L122-L124 Perhaps additional checks can be added to these lines - https://github.com/bhovhannes/redux-profiler/blob/main/src/index.js#L42-L47, to make sure not only |
I'd rather disable |
Thanks for your quick answer! I agree with I would say it is more relevant to disable Otherwise, I was thinking of implementing a check to these lines: Lines 63 to 65 in 3f3ed74
|
That way checks will run for each action. Better to make Index: src/index.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/index.js b/src/index.js
--- a/src/index.js (revision 2b6863855fc8ba05c0793c4015fddbad3d6d6aeb)
+++ b/src/index.js (date 1638188151119)
@@ -45,6 +45,10 @@
} else if (typeof window !== 'undefined') {
performance = window.performance
}
+
+ if (typeof performance !== 'object' || typeof performance.mark !== 'function') {
+ performance = undefined
+ }
const performProfiledOperation = (() => {
let counter = {}
|
Here's a digression from the original problem for those who will read this in the future and want to disable I created an enhancer that does nothing (i.e. the identity reducer): const entityEnhancer =
(createStore) =>
(reducer, initialState, enhancer) => {
const monitoredReducer = (state) => reducer(state, action);
return createStore(monitoredReducer, initialState, enhancer);
}; And then I create the my store with the following manner: const store = createStore(
rootReducer(history),
composeEnhancers(!!window.__TEST__ ? entityEnhancer : profileStore(), enhancers)
); |
Regarding your suggestion, I agree with you that it would be better if |
I went ahead and fixed this myself as I had some unexpected free time. Sorry if you have already started to work on that. Fix is released in version |
Thank you a lot for that. However, I have upgraded the package to Here's the error trace I got:
|
In my case, it is probably Jest that destroys the Lines 72 to 91 in f33d0d0
|
I don't understand what do you mean. Can you put together a sample repo reproducing the issue? |
Sorry for the late reply. I fully agree with you, it does not make any sense and it would not be Anyway I have set-up a small repo to try to reproduce the issue but I was not able to reproduce... ( https://github.com/Amatewasu/redux-profiler_issue-655 ) |
I am glad to help, but honestly I think code is defensive as it could be and I don't see any code paths which may fail if for some reason performance object is not available or has a wrong shape. Without reproducible case I don't know how I can help. |
Despite having a good adoption by the current browsers, sometimes
performance.mark
is still unavailable in some environments.In my case, it is not available in my test environment leading to a crash of some of my units tests. It looks like it is due to the fake timers of Jest that remove the performance.mark function. (I wanted to create a codesandbox to show the problem but we cannot use the jest fake timers in codesandbox).
It would be nice to check if
performance.mark
really exists before calling it and therefore avoid raising an error.For example, here's the error I get:
What do you think? (if needed, I can send a PR)
The text was updated successfully, but these errors were encountered: