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

Add API to enable/disable debug logging (in development) #35

Merged
merged 7 commits into from
Jun 24, 2023
Merged

Conversation

bvaughn
Copy link
Owner

@bvaughn bvaughn commented Jun 22, 2023

Debug logging can be useful to correlate Suspense data fetching with other things going on in an application. For a while, I've had debugging built into this library locally but not exported for applications that use the library.

This PR adds the ability to turn debug logging on for an individual cache or for all caches.

For all caches:

import { disableDebugLogging, enableDebugLogging } from "suspense";

enableDebugLogging(); // Turns global debug logging on

disableDebugLogging(); // Turns global debug logging back off

For an individual cache:

import { createCache } from "suspense";

// Cache can be configured during initialization
const cache = createCache({
  debugLogging: true,
  // ...
});

// They can also be turned on/off later
cache.disableDebugLogging();
cache.enableDebugLogging();

Note that this logging is only in development builds of this package (see c21c562). The above code will have no observable impact on production builds.

@vercel
Copy link

vercel bot commented Jun 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
suspense ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2023 8:08pm

@bvaughn
Copy link
Owner Author

bvaughn commented Jun 22, 2023

For some reason, it looks like the isDevelopment flag isn't correctly set when running the website locally with Parcel. Need to investigate.

Adding the following to createCache.ts:

import { isDevelopment } from "#is-development";

console.log("[createCache] isDevelopment:", isDevelopment);
console.log("[createCache] NODE_ENV:", process.env.NODE_ENV);

Prints:

[createCache] isDevelopment: false
[createCache] NODE_ENV: development

Not sure what needs to change to connect these two. I've updated parcel deps to the latest release (2.9.2). Based on the Parcel documentation, I would expect the import/export to work. Parcel says it supports "development" (and I've added the packageExports attribute to the root package.json as the docs require):
image

Out of curiosity, I split the "suspense" package exports into development, production, and default– and Parcel seems to be importing the default path.
image

Edit Fix inbound! parcel-bundler/parcel#9108

@bvaughn bvaughn marked this pull request as ready for review June 24, 2023 20:09
@bvaughn bvaughn merged commit 6408cb0 into main Jun 24, 2023
@bvaughn bvaughn deleted the debugging branch June 24, 2023 20:09
@Andarist
Copy link
Contributor

Were you able to figure out everything here? I wonder if there is still anything that is unclear when it comes to those exports and stuff that I could help you out with.

@bvaughn
Copy link
Owner Author

bvaughn commented Jun 24, 2023

Only that it was a Parcel bug. In the meanwhile, I just hard-coded the condition to true so I could test what I was working on.

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

Successfully merging this pull request may close these issues.

2 participants