-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
useAsyncDebounce in minified production has undefined reference #3297
Comments
@jacebot I've been running into this also, fixing it right now by adding the |
@garand thanks, I will experiment with this and let you know if it helped my situation. |
I think this is because react-table builds with this browserslist config https://github.com/tannerlinsley/react-table/blob/master/package.json#L53, which in turn means that babel will use the regenerator-runtime polyfill for With Webpack you can go around this by importing
|
Any updates on this? What worked for me aswell was to simply extract the code and put it in my own function useGetLatest(obj) {
const ref = React.useRef();
ref.current = obj;
return React.useCallback(() => ref.current, []);
}
export function useAsyncDebounce(defaultFn, defaultWait = 0) {
const debounceRef = React.useRef({});
const getDefaultFn = useGetLatest(defaultFn);
const getDefaultWait = useGetLatest(defaultWait);
return React.useCallback(
async (...args) => {
if (!debounceRef.current.promise) {
debounceRef.current.promise = new Promise((resolve, reject) => {
debounceRef.current.resolve = resolve;
debounceRef.current.reject = reject;
});
}
if (debounceRef.current.timeout) {
clearTimeout(debounceRef.current.timeout);
}
debounceRef.current.timeout = setTimeout(async () => {
delete debounceRef.current.timeout;
try {
debounceRef.current.resolve(await getDefaultFn()(...args));
} catch (err) {
debounceRef.current.reject(err);
} finally {
delete debounceRef.current.promise;
}
}, getDefaultWait());
return debounceRef.current.promise;
},
[getDefaultFn, getDefaultWait],
);
} |
This issue is being marked as stale (no activity in the last 14 days) |
This issue has been detected as stale and automatically closed. It's very likely that your issue has remained here this long because it would require breaking changes to v7. React Table v8 is currently in alpha (soon beta!) and already contains bug fixes, performance improvements and architectural changes that likely address this issue.
|
I this issue when i was unit testing a react project. Configuration:
Solution:
Hope this solves the issue |
Hey Tanner,
Thanks for the awesome project, I know you're working hard on moving to TS, I've seen/read your pain on Twitter. But I have noticed a bug has popped up since the beginning of the spring. A possible regression or new exposure as there are some closed tickets related around it. Please see below.
Also, send me a DM and I can give you some creds to my personal site if you want just to see it in action fail. I can't post anything from work at the moment.
Describe the bug (required)
useAsyncDebounce in a project, when minified for production will throw an error. (Maybe related to treeshaking?)
ReferenceError: Can't find variable: regeneratorRuntime
Provide an example via Codesandbox! (required)
Unable to reproduce outside of a minified production build. In dev this works as expected.
ReferenceError: Can't find variable: regeneratorRuntime
(anonymous function) — react-table.production.min.js:1:51258
(anonymous function) — react-table.production.min.js:1:51238
Steps To Reproduce (required)
add useAsyncDebounce to your project.
Build production output. Pull up page using the plugin in a browser. Instant error.
Expected behavior (Recommended)
Suspected it worked up to version v7.6.2 , possibly introduced after that version. Tried upgrading to 7.7.0 this morning. Same thing after build.
Additional context
PLEASE READ THIS: Had this error occur in two separate unrelated projects, with an entirely different build system, but same error in bundled production builds. My work project uses Parcel v2, while my personal one use Webpack(redwoodjs).
I have tried all kinds of 'tricks' and hacks including babelrc files but really to no avail. In my work project I moved on to lodash as a bandaid. But today I pull my personal project and blam, same error. And it points to the useAsyncdebounce function in minified production.
Sorry for no PR to go with this. Thanks again!
The text was updated successfully, but these errors were encountered: