question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails in production mode

See original GitHub issue

In development environment my dnd component works excellent. But in production it doesn’t. Multiple Uncaught Error: Expected sourceIds to be an array. message in console on drag begin. How is it possible?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
jdconnercommented, Mar 12, 2019

Found out a decent solution. Props to @tambeta for the initial code here

If we take his implementation as is, itll destroy performance if the user hovers the DropTarget since the DropTarget will consistently be forced to rerender. Given our situation, we only want to know if the targets have changed, so we can update his solution to:

import React from 'react';
import { DropTarget } from 'react-dnd';
import pick from 'lodash-es/pick';
import isEqual from 'lodash-es/isEqual';

function RapidFireDropTarget(types, spec, collect, options = {}) {
    let collectProps = {};
    const prevHover = spec.hover;
    const { collectRapidly = [] } = options;
    let lastTargetIds = [];

    const dummyConnect = {
        dropTarget: () => () => {
            throw new Error('Rapidly collected props cannot include results from `connect`');
        },
    };

    const WrappedComponent = Component => 
        class extends React.Component {
            render() {
                return <Component {...this.props} {...collectProps} />;
            }
        };

    spec.hover = (props, monitor, component) => {
        const allCollectProps = collect(dummyConnect, monitor);
        const nextTargetIds = monitor.internalMonitor.store.getState().dragOperation.targetIds;

        collectProps = pick(allCollectProps, collectRapidly);

        if (!isEqual(nextTargetIds, lastTargetIds)) {
            component.forceUpdate();
        }

        lastTargetIds = monitor.internalMonitor.store.getState().dragOperation.targetIds;

        if (prevHover instanceof Function) {
            prevHover(props, monitor, component);
        }
    };

    return Component => DropTarget(types, spec, collect, options)(WrappedComponent(Component));
}

export default RapidFireDropTarget;

then use it:

...

export default RapidFireDropTarget(types, target, collect)(YourComponent);

and it should technically only force a rerender if the targets change.

0reactions
stale[bot]commented, Jul 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build fails in production mode - Material Design for Bootstrap
Expected behavior When I run ng build --prod to compile my project I expect it to successfully build. Actual behavior I get an...
Read more >
An error happens in webpack production mode, but but works ...
An Uncaught TypeError occurred when I use webpack's production mode, but it works well in webpack's development mode.
Read more >
Magento 2: Showing error on production mode
I'm facing an issue like errors are show on PRODUCTION mode, how can this be possible. Anyone have ...
Read more >
Error when enabling production mode - Magento Forums
Solved: I can't enable development mode after i've installed an extension, the errore that i have is in the screenshot.
Read more >
Uncaught error in production mode · Issue #4302 - GitHub
When using redux-form 8.0.4 with react-redux 6.0 there is a bug in production mode (minified code), with throw new Submission Error, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found