Redux-saga with Internet Explorer - reactjs

I have a React app using redux-saga in IE 11
It seems to be breaking with the following error
Note that this app works perfectly fine in Chrome for versions of last 3 years and in Safari as well (aside for some display issues)
sagas.js
// functions are called bottom to top, this one is called at the end (also can be seen in stack trace below)
function* getGlobalData() {
console.log('Get global data called'); // this is executed
// something is failing from here on
const [
wardrobeResponse,
lastListingsResponse,
] = yield [
call(api_request, {url: 'store/wardrobes/'}),
call(api_request, {url: 'store/last_listings/'}),
]
yield put(actions.wardrobe.success(wardrobeResponse.json));
yield put(actions.lastListings.success(lastListingsResponse.json));
}
/**
* Watches for LOAD_SEARCH_RESULTS action and calls handler
*/
function* getGlobalDataWatcher() {
console.log('Get data - check if working');
console.log("global data watcher saga run")
yield take(Constants.LOAD_GLOBAL_DATA)
console.log('LOAD_GLOBAL_DATA received in saga')
const state = yield select()
if (state.getIn(['global', 'wardrobes']).isEmpty()) {
console.log('Empty global data, call api')
yield call(getGlobalData);
} else {
console.log('Global data already present, dont call API')
}
}
function* data() {
console.log('Get global results saga data called');
yield fork(getGlobalDataWatcher);
}
export default [
data
]
console error
uncaught at data
at loadMeDataWatcher
at loadMeData
TypeError: Object doesn't support this action
at api_request (http://localhost:3002/main.js:5905:3)
at runCallEffect (eval code:446:7)
at runEffect (eval code:370:5)
at next (eval code:259:9)
at currCb (eval code:329:7)
at runSelectEffect (eval code:651:7)
at runEffect (eval code:370:5)
at next (eval code:259:9)
at proc (eval code:214:3)
at resolveIterator (eval code:390:5)

You may install 'babel-polyfill' to your dependencies and add this line to your app.js.
import 'babel-polyfill';
See more

Related

Why: Uncaught (in promise) Error: Error serializing buffer at eval (logger.js?4ee8:900:1)

Why #logdna/logger raise this:
Uncaught (in promise) Error: Error serializing buffer
at eval (logger.js?4ee8:900:1)
Following docs: https://www.npmjs.com/package/#logdna/logger
Have this config:
const logdna = require('#logdna/logger')
const options = {
app: `tikex-fe-${process.env.NEXT_PUBLIC_ENVIRONMENT ?? 'local'}`,
level: 'debug', // set a default for when level is not provided in function calls
}
export const logger = logdna.createLogger(
'89ed69e8d2a4e79cb5593d40********',
options
)
And logging like this:
logger.log('startPaymentReq exist')
What is wrong?
yarn build raise no error
Or it it more worth to set up a backend log endpoint and send there the text message?!

Simple Peer on data stream throws process not defined error

I am trying to open a data channel using simple peer. I send the signal using Firebase and am able to get the on connect function to fire.
const [thisPeer, setThisPeer] = useState();
const [connectionStatus, setConnectionStatus] = useState(false);
// in a function
var thisPeerT = new Peer({
initiator: false,
config: {
iceServers: iceServers,
},
});
// signaling code
thisPeerT.on("connect", function (data) {
console.log("onconnect");
console.log(data);
setConnectionStatus(true);
});
setThisPeer(thisPeerT);
In the on connect, I set a state hook that triggers a use effect where I create my on data.
useEffect(
function () {
console.log("here");
console.log(roomID);
console.log(thisPeer);
console.log(connectionStatus);
if (roomID && thisPeer && connectionStatus) {
console.log("here2");
thisPeer.on("data", function (data) {
console.log(data);
});
}
},
[roomID, thisPeer, connectionStatus]
);
However, I get the following error when I try to use thisPeer.on("data"...
here
XXYDCgqle4XvZDZ6gm6
Peer {_readableState: ReadableState, readable: true, _events: {…}, _eventsCount: 4, _maxListeners: undefined, …}
true
here2
Uncaught ReferenceError: process is not defined
at resume (_stream_readable.js:905:1)
at Peer.Readable.resume (_stream_readable.js:895:1)
at Peer.Readable.on (_stream_readable.js:813:1)
at ConnectionContext.js:142:1
at invokePassiveEffectCreate (react-dom.development.js:23487:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at flushPassiveEffectsImpl (react-dom.development.js:23574:1)
at unstable_runWithPriority (scheduler.development.js:468:1)
I have tried placing the on data at various places throughout my code, and regardless of the position, it seems this error occurs. If I call peer.send() on the other peer, it also gives a process is not defined error on the peer that received the data. Does anyone know how I can resolve the error or where I should open the data channel?
I got the same issue but I can do a workaround by using CDN script
<script src="https://cdnjs.cloudflare.com/ajax/libs/simple-peer/9.11.1/simplepeer.min.js"></script>
And here is a code example of how to call it in React
var peer1 = new window.SimplePeer({ initiator: true })

Mobx React - CreateViewModel - Error - Object is not a function

I am trying to use the createViewModel from mobx-utils in a Mobx/React app.
My Store is:
export class CompanyStore extends StoreExt {
#observable
companyDetails: ICompanyDetails = {}
}
And when i use the 'createViewModel' function, in the component like so:
function CompanyDetails() {
const { companyStore } = useRootStore()
const test = createViewModel(companyStore.companyDetails);
}
I getting this error:
Uncaught TypeError: Object(...) is not a function
at new ViewModel (mobx-utils.module.js?1a9d:629)
at createViewModel (mobx-utils.module.js?1a9d:775)
at CompanyDetails (index.tsx?dbb5:21)
at eval (observer.js?796d:24)
at eval (useObserver.js?338c:91)
at trackDerivedFunction (mobx.es6.js?cacc:668)
at Reaction.track (mobx.es6.js?cacc:1705)
at eval (useObserver.js?338c:89)
at useQueuedForceUpdateBlock (useQueuedForceUpdate.js?20c5:19)
at useObserver (useObserver.js?338c:83)
What could the cause be?
Well, The issue was an incompatibility between Mobx and mobx-utils packages. By matching them to the same version, the issue was solved.

TypeError from screenfull library during jest test

I've added screenfull, a wrapper for the Fullscreen API (https://github.com/sindresorhus/screenfull.js) to a Redux-connected React component. The application uses Typescript elsewhere, but not in the components. Screenfull is used as follows in the component:
componentDidUnmount() {
screenfull.on('change', () => this.props.toggleFullscreen());
}
componentWillUnmount() {
screenfull.off('change', () => this.props.toggleFullscreen());
}
and I have a test as follows (there are more failing in the component test file, but I thought I'd share the first one)
it('mounts with initial state', () => {
const store = configureStore(reducer);
const container = mount(
<Provider store={store}>
<VideoBoundingBoxApp inIframe={false} />
</Provider>);
expect(container.find('VideoBoundingBoxApp')).toExist();
});
The application runs and works as expected, but when running yarn test, I get the following error:
console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Uncaught [TypeError: _screenfull2.default.on is not a function]
at reportException (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at invokeEventListeners (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
at HTMLUnknownElementImpl._dispatch (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
at HTMLUnknownElementImpl.dispatchEvent (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
at HTMLUnknownElementImpl.dispatchEvent (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
at HTMLUnknownElement.dispatchEvent (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
at Object.invokeGuardedCallbackDev (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:944:16)
at invokeGuardedCallback (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:993:29)
at commitRoot (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7157:9)
at completeRoot (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8065:36) TypeError: _screenfull2.default.on is not a function
at VideoBoundingBoxApp.componentDidMount (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/src/components/VideoBoundingBox/VideoBoundingBoxApp.jsx:122:28)
at commitLifeCycles (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5347:26)
at commitAllLifeCycles (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7018:9)
at HTMLUnknownElement.callCallback (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:906:14)
at invokeEventListeners (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
at HTMLUnknownElementImpl._dispatch (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
at HTMLUnknownElementImpl.dispatchEvent (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
at HTMLUnknownElementImpl.dispatchEvent (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
at HTMLUnknownElement.dispatchEvent (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
at Object.invokeGuardedCallbackDev (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:944:16)
at invokeGuardedCallback (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:993:29)
at commitRoot (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7157:9)
at completeRoot (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8065:36)
at performWorkOnRoot (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8015:11)
at performWork (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7933:9)
at performSyncWork (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7910:5)
at requestWork (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7810:7)
at scheduleWorkImpl (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7685:13)
at scheduleWork (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7645:12)
at scheduleRootUpdate (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8273:5)
at updateContainerAtExpirationTime (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8301:12)
at Object.updateContainer (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8328:14)
at Object.create (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9009:18)
at Object.<anonymous> (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/src/test/components/VideoBoundingBox/VideoBoundingBoxApp.test.jsx:42:49)
at Object.asyncFn (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-jasmine2/build/jasmine_async.js:82:37)
at resolve (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-jasmine2/build/queue_runner.js:52:12)
at new Promise (<anonymous>)
at mapper (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-jasmine2/build/queue_runner.js:39:19)
at promise.then (/Users/mschoemaker/Desktop/CrowdFlower/projects/image_annotation/node_modules/jest-jasmine2/build/queue_runner.js:73:82)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(similar for screenfull.off...) I am not sure how to parse this. I don't think it's Typescript related. Would anyone have any idea?
I (well, mostly my boss) figured it out. Turns out, the screenfull code has a check for whether document contains methods such as requestFullscreen, otherwise it returns false. I fixed this by adding
// fullscreen library will cause an error in jest tests
// if it can't find fullscreen methods on document
[
'requestFullscreen',
'exitFullscreen',
].forEach(each => (document[each] = () => {})); // eslint-disable-line
to my setupTests.js
#Michel Schoemaker answer is correct, but I wanted to provide more context for those curious souls out there like myself. Thankfully, screenfull's source code is super short and easy to reason about.
Looking at the source, you'll see a self-invoking function right at the top which stores its return value in a variable called fn.
// This is what I'm talking about right here. See the end of this function
var fn = (function () {
var val;
var fnMap = [
[
'requestFullscreen',
'exitFullscreen',
'fullscreenElement',
'fullscreenEnabled',
'fullscreenchange',
'fullscreenerror'
],
// New WebKit
[
'webkitRequestFullscreen',
'webkitExitFullscreen',
'webkitFullscreenElement',
'webkitFullscreenEnabled',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
// Old WebKit
[
'webkitRequestFullScreen',
'webkitCancelFullScreen',
'webkitCurrentFullScreenElement',
'webkitCancelFullScreen',
'webkitfullscreenchange',
'webkitfullscreenerror'
],
[
'mozRequestFullScreen',
'mozCancelFullScreen',
'mozFullScreenElement',
'mozFullScreenEnabled',
'mozfullscreenchange',
'mozfullscreenerror'
],
[
'msRequestFullscreen',
'msExitFullscreen',
'msFullscreenElement',
'msFullscreenEnabled',
'MSFullscreenChange',
'MSFullscreenError'
]
];
var i = 0;
var l = fnMap.length;
var ret = {};
// This for loop essentially checks the current document object for the property/methods above.
for (; i < l; i++) {
val = fnMap[i];
if (val && val[1] in document) {
for (i = 0; i < val.length; i++) {
ret[fnMap[0][i]] = val[i];
}
return ret;
}
}
// If it doesn't find any of them, this whole function returns false
// and the fn variable is set to this returned value.
return false;
})();
Then further down in the you'll see for a simple conditional check on this fn variable.
// Sidenote, if you just remove the bang from the conditional, this package
// works in testing. But obviously we don't want to do that.
if (!fn) {
if (isCommonjs) {
module.exports = {isEnabled: false};
// If log out the value of screenfull after importing it
// in your test, this is what you'll see -> {isEnabled: false}
// Thus screenfull sets this object as the exported module and returns early.
} else {
window.screenfull = {isEnabled: false};
}
return;
}
So back to #Michel Schoemaker's answer; The reason that works is because we're basically monkey patching these properties/methods in the document object so Screenfull thinks we have a compatible environment. Once it think's we have a compatible environment, Jest can mock the library as usual.
I did things a little different than #Michel Schoemaker because I was only using screenfull in two methods of my application so I didn't need to set them up for my whole testing environment. Here' my approach:
thing.spec.js
import screenfull from 'screenfull';
jest.mock('screenfull');
//********* Fullscreen **********//
describe('Fullscreen', () => {
beforeEach(() => {
document.requestFullscreen = jest.fn();
document.exitFullscreen = jest.fn();
document.fullscreenElement = jest.fn();
document.fullscreenEnabled = jest.fn();
document.fullscreenchange = jest.fn();
document.fullscreenerror = jest.fn();
});
afterEach(() => {
jest.clearAllMocks();
});
test('test name', (done) => {
// Assemble
// Act
// Assert
expect(screenfull.toggle).toHaveBeenCalled();
done();
});
});
For one thing in the unit test you likely want to jest.mock this dependency.
And the _screenfull2.default.on is not a function error might be caused by mismatch between commonjs modules and es6 modules. How are you importing screenfull?

Cannot read property 'LEENDPOINT' of undefined

I am integrating LogEntries in my react application.
But right after importing LogEntry js file. I am getting console error that:
const Logger = require ('./logger.jsx')('your token', {trace: true});
Error:
le.min.js:5 Uncaught TypeError: Cannot read property 'LEENDPOINT' of undefined
at new e (le.min.js:5)
at new p (le.min.js:10)
at f (le.min.js:11)
at Object.init (le.min.js:12)
at module.exports (logger.jsx:9)
at Object.defineProperty.value (App.js:10)
at __webpack_require__ (bootstrap 9c287bdecc8b4481a87b:19)
at Object.defineProperty.value (AppWrapper.js:2)
at __webpack_require__ (bootstrap 9c287bdecc8b4481a87b:19)
at Object.<anonymous> (index.js:8)
Update:
After debbuging I came to know that window object is undefined in logger file.
This is piece of code which is causing havoc:
if (window.LEENDPOINT) {
_endpoint = window.LEENDPOINT;
}
Still looking for solution.
Update 2.0:
Here is my Logger.jsx
const LogEntries = require ('./le.min.js');
module.exports = (token, opts={}) => {
if(!token){
throw new Error ('A valid token is required for all LogEntries library implementations.');
}
opts.token = token;
LogEntries.init(opts);
return LogEntries;
}
Following solution worked for me:
Downloaded le.min.js from https://docs.logentries.com/docs/javascript
Imported <script src="/assets/scripts/le.min.js"></script> in my index.html. Make sure you import it before bundle.js
Created one file. Logger.js
const token = 'token';
const region = 'us';
const trace = true;
/*eslint-disable */
LE.init({ token, region, trace});
export default LE;
/*eslint-enable */
Whenever you want to make log import import Logger from './Logger';
Log using: Logger.error('Log');

Resources