aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-framework-next/server-polyfills.tsx
blob: 8942154b72e893d57162d41f4143e5e55a3c033f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
globalThis.global = globalThis;

import { Buffer } from "buffer";

globalThis.Buffer = Buffer;

import * as React from "react";

class URL {
  pathname: string;
  href: string;

  constructor(base: string, source: string) {
    this.pathname = source;
    this.href = base + source;
  }
}

var onlyChildPolyfill = React.Children.only;

React.Children.only = function (children) {
  if (
    children &&
    typeof children === "object" &&
    (children as any).length == 1
  ) {
    return onlyChildPolyfill(children[0]);
  }

  return onlyChildPolyfill(children);
};

globalThis.URL = URL;

import { TextEncoder, TextDecoder } from "./text-encoder-polyfill";

globalThis.TextEncoder ||= TextEncoder;
globalThis.TextDecoder ||= TextDecoder;