-
Notifications
You must be signed in to change notification settings - Fork 0
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 the ability to ignore caching server-side result #38
base: main
Are you sure you want to change the base?
Conversation
@@ -9,12 +10,13 @@ export default function useSSRComputation_Server(fn: (...dependencies: any[]) => | |||
// relativePathToCwd is used to make sure that the cache key is unique for each module | |||
// and it's not affected by the file that calls it | |||
const cacheKey = calculateCacheKey(relativePathToCwd, dependencies); | |||
// check if result is a promise | |||
if (result && typeof result.then === 'function') { | |||
cache[cacheKey] = result.then(asyncResult => cache[cacheKey] = asyncResult); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this line before to deal with promises. But, I don't know if server-side renderer will support executing async functions. Should I remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the coding principles I follow is "Every single line of code should be tested". If you don't have proof that the code works, don't merge it.
So I'm for reverting (unless you tested it and found it useful).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Romex91 I don't add lines here, I delete them. I removed the ability to track async results on the server-side. This feature is already not been tested before. So, I think it's a mistake from me to add it before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. So I approve the reversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's necessary (more on it in Slack)
If I'm wrong, there are issues:
cache[cacheKey] = result; | ||
|
||
// check if it should ignore caching | ||
if (result && result[IgnoreCache]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want this feature, this has to be duplicated client-side, as it will return different stuff client-side and server-side, resulting in crashes and hydration conflicts.
It adds the ability to ignore caching the value returned from the server-side. It can be used if the server-side result is not ready, so the client will need to recalculate it
Example