Skip to content

fix: check type before using string-only method #2393

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

Merged
merged 10 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demos/default/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
10 changes: 6 additions & 4 deletions packages/runtime/src/templates/handlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ export const augmentFsModule = ({

// ...then monkey-patch it to see if it's requesting a CDN file
promises.readFile = (async (file, options) => {
const baseUrl = getBase()

// We only care about page files
if (file.startsWith(pageRoot)) {
// file argument can be a string, URL, etc - Next.js cache reading uses a string
// and that's only thing we really want to handle here, so we just do type checking
// instead of trying to handle all possible type before checking weather read
// is about page files.
if (typeof file === 'string' && file.startsWith(pageRoot)) {
const baseUrl = getBase()
// We only want the part after `.next/server/`
const filePath = file.slice(pageRoot.length + 1)

Expand Down