Skip to content

Commit

Permalink
Remove TextEncoder and TextDecoder wrappers (#31490)
Browse files Browse the repository at this point in the history
This PR removes the class wrapper that we have for `TextEncoder` and `TextDecoder`. Since this is merged we will be using directly the Node version in the sandbox.
  • Loading branch information
javivelasco committed Nov 16, 2021
1 parent f195650 commit 9375485
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 48 deletions.
48 changes: 2 additions & 46 deletions packages/next/server/web/sandbox/polyfills.ts
@@ -1,7 +1,5 @@
import {
Crypto as WebCrypto,
CryptoKey,
} from 'next/dist/compiled/@peculiar/webcrypto'
import { Crypto as WebCrypto } from 'next/dist/compiled/@peculiar/webcrypto'
import { CryptoKey } from 'next/dist/compiled/@peculiar/webcrypto'
import { TransformStream } from 'next/dist/compiled/web-streams-polyfill'
import { v4 as uuid } from 'next/dist/compiled/uuid'
import crypto from 'crypto'
Expand All @@ -14,48 +12,6 @@ export function btoa(str: string) {
return Buffer.from(str, 'binary').toString('base64')
}

class TextEncoderRuntime {
encoder: TextEncoder

constructor() {
this.encoder = new TextEncoder()
}

get encoding() {
return this.encoder.encoding
}

public encode(input: string) {
return this.encoder.encode(input)
}
}

class TextDecoderRuntime {
decoder: TextDecoder

constructor() {
this.decoder = new TextDecoder()
}

get encoding() {
return this.decoder.encoding
}

get fatal() {
return this.decoder.fatal
}

get ignoreBOM() {
return this.decoder.ignoreBOM
}

public decode(input: BufferSource, options?: TextDecodeOptions) {
return this.decoder.decode(input, options)
}
}

export { TextDecoderRuntime as TextDecoder }
export { TextEncoderRuntime as TextEncoder }
export { CryptoKey }

export class Crypto extends WebCrypto {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/server/web/sandbox/sandbox.ts
Expand Up @@ -82,8 +82,8 @@ export async function run(params: {
ReadableStream: polyfills.ReadableStream,
setInterval,
setTimeout,
TextDecoder: polyfills.TextDecoder,
TextEncoder: polyfills.TextEncoder,
TextDecoder,
TextEncoder,
TransformStream,
URL,
URLSearchParams,
Expand Down

0 comments on commit 9375485

Please sign in to comment.