Skip to content

Commit d73accf

Browse files
committed
fix: use version of htmlrewriter which does not make use of asyncify, which looks to have a potential memory leak under high load
we noticed the memory issue with Netlify's CSP plugin which used the same htmlrewriter library. We've built a new htmlrewriter library which uses the latest version of lol-html and removes the ability to use async-handlers, which is what required asyncify to be included.
1 parent 00e3a4b commit d73accf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

deno.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
},
77
"imports": {
88
"@netlify/edge-functions": "https://edge.netlify.com/v1/index.ts"
9-
}
9+
},
10+
"importMap": "./edge-runtime/vendor/import_map.json"
1011
}

edge-runtime/lib/response.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context } from '@netlify/edge-functions'
2-
import { HTMLRewriter } from '../vendor/deno.land/x/[email protected]/index.ts'
2+
import { HTMLRewriter, init, type TextChunk } from 'https://deno.land/x/[email protected]/src/index.ts'
33

44
import { updateModifiedHeaders } from './headers.ts'
55
import type { StructuredLogger } from './logging.ts'
@@ -13,6 +13,8 @@ import {
1313
relativizeURL,
1414
} from './util.ts'
1515

16+
await init();
17+
1618
export interface FetchEventResult {
1719
response: Response
1820
waitUntil: Promise<any>
@@ -79,7 +81,7 @@ export const buildResponse = async ({
7981

8082
if (response.dataTransforms.length > 0) {
8183
rewriter.on('script[id="__NEXT_DATA__"]', {
82-
text(textChunk) {
84+
text(textChunk: TextChunk) {
8385
// Grab all the chunks in the Next data script tag
8486
buffer += textChunk.text
8587
if (textChunk.lastInTextNode) {

0 commit comments

Comments
 (0)