-
Notifications
You must be signed in to change notification settings - Fork 141
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
Argument 'maxAge' must be false or a number #1133
Comments
Seems to be me like it might be stripping the empty string argument (which it shouldn't do). Have you tried with a non-empty string? Like so e.g.: client.getListing('/', false) |
It minifies that line into I put the example here to better inspect :) https://csb-2op6w034zj-lnloqmcccy.now.sh/ |
That's some hardcore minification. Apparently the rs.js argument validation is not happy with that. If you don't provide an argument for See https://remotestoragejs.readthedocs.io/en/latest/js-api/base-client.html?highlight=getListing#getListing for details (also see the linked explanation of maxAge and caching behavior). In order to fix your problem without patching rs.js, you could e.g. provide the argument as a very high number of milliseconds instead. And in order to fix the problem upstream and for other people using a minifier like that, you could see if you can change the argument validation so it accepts |
Thanks for explanation! I don't think the argument validation is the issue, because both remotestorage.js/src/syncedgetputdelete.js Lines 8 to 10 in 44672c5
maxAgeInvalid(false) === maxAgeInvalid(-1) // true` BUT, if I replace remotestorage.js from the minified bundle with a So maybe the real issue is that the create-react-app minifier modifies the imported remotestorage.js in a way it shouldn't? |
Edit: Hmm, both work for me. So yeah, could be that it messes with the library in a different way. |
I checked your example on now.sh, but I couldn't see any errors in the console logs (FF stable). Edit: I do see the error in Chromium. Checking if it's just because it's an uncaught promise error... |
Sorry, confused the -1 and !1 ⚡️I also don't see any errors in Firefox, only Chrome. The source code is in the other link --> https://codesandbox.io/s/2op6w034zj. But now I'm getting curious so created another maybe simpler test repo here: |
Haha, wow! Here's what your minifier does to the original code that receives the maxAge internally ( get: function (e, t) {
return this.local ? (
void 0 === t && ('object' === n(this.remote) && this.remote.connected && this.remote.online ? t = 2 * this.getSyncInterval() : (o('Not setting default maxAge, because remote is offline or not connected'), t = !1)),
Promise.reject('Argument \'maxAge\' must be false or a number')
) : this.remote.get(e)
}, As you can see, it doesn't even contain the actual We do ship our own minified versions of the library and didn't run into this before. It seems that whatever minifier and config create-react-app is using is trying a bit too hard, and as a result failing miserably with this function. |
@oskarrough Could you try using 4ca0f0c as dependency and see if it helps? I refactored the source code a little bit, so hopefully the minifier doesn't destroy it anymore. |
@skddc tried but couldn't see any difference, sorry. Continuing this rabbit hole: if I run
I'm wondering what causes the minifier to break here... I also tried with the |
Simplify the code. Aside from being more readable, this fixes a problem with the UglifyJS compressor destroying the code by restructuring it wrong. closes #1133
Simplify the code. Aside from being more readable, this fixes a problem with the UglifyJS compressor destroying the code by restructuring it wrong. closes #1133
When looking at the output I noticed that your app didn't actually use my updated code, because it's importing from the release build, but I failed to commit that to my branch. However, with those changes, it was still destroying the code, albeit in a slightly different way. I have now changed it again (#1134), and have arrived at a version that actually works after being compressed to death by uglifyjs. I'm still rather perplexed about how uglify's compression algos just straight-up destroy perfectly fine JavaScript code by restructuring it completely wrong. So I think this should actually be fixed over there. But fwiw, at least our code is a bit more readable now, and hopefully the entire build now works with the default settings that started this issue. I wouldn't actually bet on the latter though, because this was by no means a complex part of our code in comparison to the rest of the library. |
Hey, I tried your branch and I can confirm it also works here now! Thank you very much. Did you learn exactly which code/syntax uglifyjs failed with? Just curious. |
Glad to hear.
Yes, both the code I originally linked, as well as the version from my linked refactoring commit (4ca0f0c). |
Simplify the code. Aside from being more readable, this fixes a problem with the UglifyJS compressor destroying the code by restructuring it wrong. closes remotestorage#1133
Whenever I minify the following example, remotestorage.js throws an error:
Note, this only happens after building the code. If you don't include remotestorage in the bundle but use a global via cdn or so, there is no error. I am not connecting to any remote storage, e.g. only local.
Could it be how the code is minified? You can test by putting above example inside a
create-react-app
(webpack) ornpx bili example.js --format umd
(rollup).May be related to something here https://github.com/remotestorage/remotestorage.js/blob/master/src/syncedgetputdelete.js#L25
The text was updated successfully, but these errors were encountered: