-
Notifications
You must be signed in to change notification settings - Fork 86
fix: fix memoization #128
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
fix: fix memoization #128
Conversation
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 thinking this test failure is due to the addition of a |
my new theory is that the memoization means the different next configs used in testing are no longer loaded due to returning the same promise I started debugging this, but I ran into an issue where tests failed due to promises never resolving I've run out of time to keep working on this, but for the record, here's where I ended up (tests still fail at this point) first, I disabled memoization during tests: // Memoizes `nextConfig` except during test runs
if (nextConfigPromise !== undefined && process.env.NODE_ENV !== 'test') {
return await nextConfigPromise
} the code also moved the let config
try {
nextConfigPromise = loadConfig(PHASE_PRODUCTION_BUILD, resolve('.'))
config = await nextConfigPromise
} catch (error) {
return failBuild('Error loading your next.config.js.', { error })
}
return config the tests at this point are failing with:
so I'm either doing something very obviously wrong (quite possible) or there's something tricky happening here that we haven't found yet |
b2db4e5
to
f42888e
Compare
Thanks for the additional debugging @jlengstorf, this really helped!
I fixed those by using a proper memoization library instead, which correctly handles async functions. Tests are now passing 🎉 |
@@ -1,28 +1,29 @@ | |||
'use strict' |
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.
Needed by moize
(otherwise, it throws).
helpers/getNextConfig.js
Outdated
} | ||
|
||
const moizedGetNextConfig = moize(getNextConfigValue, { maxSize: 1e3, isPromise: true }) |
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.
maxSize
is required by moize@6
. 1
would work in our case since the function has no arguments, but I used 1e3
so it covers future usage where we might add more arguments to this function.
f42888e
to
fc9b555
Compare
fc9b555
to
7910888
Compare
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.
nice! I'm adding this to my list of things to look at and figure out why your original solution didn't work
This fixes memoization of
getNextConfig()
.Note: the tests seem to be failing. Work in progress.