Skip to content
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

stdTTL not working for release builds (console.dir undefined) #42

Open
tsgriff opened this issue Feb 13, 2022 · 4 comments
Open

stdTTL not working for release builds (console.dir undefined) #42

tsgriff opened this issue Feb 13, 2022 · 4 comments

Comments

@tsgriff
Copy link

tsgriff commented Feb 13, 2022

While implementing the stdTTL feature to remove cached entries after expiration, I noticed that entries were successfully removed for debug builds, but not release builds.

The error logged was: console.dir is not a function. (In 'console.dir(Date.parse(c.created))', 'console.dir' is undefined). I traced this to the following code block within the peek function in dist/cache.js:

if (this.policy.stdTTL > 0) { console.dir(Date.parse(entry.created));

It appears that this could have been added to the dist folder before the version 2.0.2 release since it's not in the repository and was accidentally left in. Console.dir is problematic for iOS and Android (facebook/react-native#29300).

Could this be removed with another release please? I'd open a PR if it was included with the repo code.

@stijnstroeve
Copy link

stijnstroeve commented Feb 24, 2022

I second this! Please remove this from the package as the package is not working correctly now.

For now I have just added:

console.dir = () => {}

to the top of my index.js file.

@levizimmerman
Copy link

levizimmerman commented Apr 14, 2022

@stijnstroeve @tsgriff Thank you for finding the misplaced console.dir.

For people who are reading this and looking for a fix:

I have used patch-package (https://www.npmjs.com/package/patch-package).

In node_modules/react-native-cache/dist/cache.js I have commented out the line where it called the console.dir() function.

After changing the file I ran yarn patch-package react-native-cache so it creates a patch in the /patches folder:

diff --git a/node_modules/react-native-cache/dist/cache.js b/node_modules/react-native-cache/dist/cache.js
index fe6824d..6d5eeef 100644
--- a/node_modules/react-native-cache/dist/cache.js
+++ b/node_modules/react-native-cache/dist/cache.js
@@ -69,7 +69,8 @@ class Cache {
         if (entry) {
             value = entry.value;
             if (this.policy.stdTTL > 0) {
-                console.dir(Date.parse(entry.created));
+                // Do not call console.dir
+                // console.dir(Date.parse(entry.created));
                 const created = entry.created ? Date.parse(entry.created) : 0;
                 const deadline = created + this.policy.stdTTL * 1000;
                 const now = Date.now();

@jonahgreenthal
Copy link

@timfpark any chance of this being fixed for real?

@justinjaeger
Copy link

Still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants