Skip to content

Commit c10269d

Browse files
committed
fix: prevenr hydration when content contains \r
1 parent d562f8e commit c10269d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/utils/content/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt)
155155
file.dirname = file.dirname ?? dirname(file.path)
156156
file.extension = file.extension ?? file.path.includes('.') ? '.' + file.path.split('.').pop() : undefined
157157
}
158+
// Replace all \r\n with \n to avoid hydration errors on Windows
159+
if (String(file.body).includes('\r\n')) {
160+
file.body = file.body.replace(/\r\n/g, '\n')
161+
}
162+
158163
const beforeParseCtx: FileBeforeParseHook = { file, collection, parserOptions }
159164
await nuxt?.callHook?.('content:file:beforeParse', beforeParseCtx)
160165
const { file: hookedFile } = beforeParseCtx

0 commit comments

Comments
 (0)