-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: custom incremental cache handlers should work when transpiled (#…
…54472) This fixes a `CurCacheHandler is not a constructor` error when the custom cache handler path is transpiled from ESM -> CJS (resulting in the handler being attached to the `default` property on the module's exports) Closes NEXT-1558 Fixes #54453
- Loading branch information
Showing
5 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/e2e/app-dir/app-static/app-static-custom-cache-handler-esm.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
import { join } from 'path' | ||
|
||
createNextDescribe( | ||
'app-static-custom-cache-handler-esm', | ||
{ | ||
files: __dirname, | ||
env: { | ||
CUSTOM_CACHE_HANDLER: join( | ||
__dirname, | ||
'./cache-handler-default-export.js' | ||
), | ||
}, | ||
}, | ||
({ next, isNextStart }) => { | ||
if (!isNextStart) { | ||
it('should skip', () => {}) | ||
return | ||
} | ||
|
||
it('should have logs from cache-handler', async () => { | ||
expect(next.cliOutput).toContain('initialized custom cache-handler') | ||
expect(next.cliOutput).toContain('cache-handler get') | ||
expect(next.cliOutput).toContain('cache-handler set') | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
process.env.CUSTOM_CACHE_HANDLER = '1' | ||
process.env.CUSTOM_CACHE_HANDLER = require.resolve('./cache-handler.js') | ||
require('./app-static.test') |
26 changes: 26 additions & 0 deletions
26
test/e2e/app-dir/app-static/cache-handler-default-export.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }) | ||
|
||
const cache = new Map() | ||
|
||
var CacheHandler = /** @class */ (function () { | ||
function CacheHandler(options) { | ||
this.options = options | ||
this.cache = cache | ||
console.log('initialized custom cache-handler') | ||
} | ||
CacheHandler.prototype.get = function (key) { | ||
console.log('cache-handler get', key) | ||
return Promise.resolve(this.cache.get(key)) | ||
} | ||
CacheHandler.prototype.set = function (key, data) { | ||
console.log('cache-handler set', key) | ||
this.cache.set(key, { | ||
value: data, | ||
lastModified: Date.now(), | ||
}) | ||
return Promise.resolve(undefined) | ||
} | ||
return CacheHandler | ||
})() | ||
|
||
exports.default = CacheHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters