From 7a1ca0bc0cb93f62daedfb4d5dee1bd22020a9d2 Mon Sep 17 00:00:00 2001 From: Jack Hanford Date: Tue, 17 Aug 2021 15:25:09 -0700 Subject: [PATCH] add React.Children.only pollyfill Former-commit-id: e140319390f56979487444529ca49a677264ad57 --- .../bun-framework-next/client.development.tsx | 14 ++++++++++++-- demos/hello-next/bun-framework-next/package.json | 3 ++- .../bun-framework-next/server.development.tsx | 16 ++++++++++++++++ demos/hello-next/components/Title.tsx | 3 +++ demos/hello-next/package.json | 3 ++- demos/hello-next/pages/{_app.js => _app.tsx} | 0 .../hello-next/pages/api/{hello.js => hello.tsx} | 0 demos/hello-next/pages/blue.tsx | 9 +++++++++ demos/hello-next/pages/{index.js => index.tsx} | 11 ++++++++++- 9 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 demos/hello-next/components/Title.tsx rename demos/hello-next/pages/{_app.js => _app.tsx} (100%) rename demos/hello-next/pages/api/{hello.js => hello.tsx} (100%) create mode 100644 demos/hello-next/pages/blue.tsx rename demos/hello-next/pages/{index.js => index.tsx} (90%) diff --git a/demos/hello-next/bun-framework-next/client.development.tsx b/demos/hello-next/bun-framework-next/client.development.tsx index d046751b26..c4346913de 100644 --- a/demos/hello-next/bun-framework-next/client.development.tsx +++ b/demos/hello-next/bun-framework-next/client.development.tsx @@ -1,3 +1,13 @@ +var onlyChildPolyfill = React.Children.only; +React.Children.only = function (children) { + if (children && typeof children === "object" && children.length == 1) { + return onlyChildPolyfill(children[0]); + } + + return onlyChildPolyfill(children); +}; + +globalThis.global = globalThis; import * as ReactDOM from "react-dom"; import App from "next/app"; import mitt, { MittEmitter } from "next/dist/shared/lib/mitt"; @@ -21,7 +31,7 @@ import { NEXT_DATA, ST, } from "next/dist/shared/lib/utils"; -import { Portal } from "next/dist/client/portal"; +// import { Portal } from "next/dist/client/portal"; import initHeadManager from "next/dist/client/head-manager"; import PageLoader, { StyleSheetTuple } from "next/dist/client/page-loader"; import measureWebVitals from "next/dist/client/performance-relayer"; @@ -187,7 +197,7 @@ let CachedComponent: React.ComponentType; function _boot(EntryPointNamespace) { const PageComponent = EntryPointNamespace.default; - + ReactDOM.hydrate(
{JSON.stringify(error)}
}> diff --git a/demos/hello-next/bun-framework-next/package.json b/demos/hello-next/bun-framework-next/package.json index 02377e339c..7aa47a88f3 100644 --- a/demos/hello-next/bun-framework-next/package.json +++ b/demos/hello-next/bun-framework-next/package.json @@ -68,5 +68,6 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "ISC" + "license": "ISC", + "dependencies": {} } diff --git a/demos/hello-next/bun-framework-next/server.development.tsx b/demos/hello-next/bun-framework-next/server.development.tsx index 54181c271f..82caf0ab7b 100644 --- a/demos/hello-next/bun-framework-next/server.development.tsx +++ b/demos/hello-next/bun-framework-next/server.development.tsx @@ -1,3 +1,19 @@ +import React from "react"; +class URL { + constructor(base, source) { + this.pathname = source; + this.href = base + source; + } +} +var onlyChildPolyfill = React.Children.only; +React.Children.only = function (children) { + if (children && typeof children === "object" && children.length == 1) { + return onlyChildPolyfill(children[0]); + } + + return onlyChildPolyfill(children); +}; +globalThis.URL = URL; globalThis.global = globalThis; import { render } from "./renderDocument"; diff --git a/demos/hello-next/components/Title.tsx b/demos/hello-next/components/Title.tsx new file mode 100644 index 0000000000..10636164f4 --- /dev/null +++ b/demos/hello-next/components/Title.tsx @@ -0,0 +1,3 @@ +export default function Title() { + return

Hello

; +} diff --git a/demos/hello-next/package.json b/demos/hello-next/package.json index 8309b88ebc..fd803c98a0 100644 --- a/demos/hello-next/package.json +++ b/demos/hello-next/package.json @@ -7,6 +7,7 @@ "next": "^11.1.0", "path": "^0.12.7", "react": "^17.0.2", - "react-dom": "^17.0.2" + "react-dom": "^17.0.2", + "whatwg-url": "^9.1.0" } } diff --git a/demos/hello-next/pages/_app.js b/demos/hello-next/pages/_app.tsx similarity index 100% rename from demos/hello-next/pages/_app.js rename to demos/hello-next/pages/_app.tsx diff --git a/demos/hello-next/pages/api/hello.js b/demos/hello-next/pages/api/hello.tsx similarity index 100% rename from demos/hello-next/pages/api/hello.js rename to demos/hello-next/pages/api/hello.tsx diff --git a/demos/hello-next/pages/blue.tsx b/demos/hello-next/pages/blue.tsx new file mode 100644 index 0000000000..fe72a744fe --- /dev/null +++ b/demos/hello-next/pages/blue.tsx @@ -0,0 +1,9 @@ +import Link from "next/link"; + +export default function Blue({}) { + return ( +
+

Blue

+
+ ); +} diff --git a/demos/hello-next/pages/index.js b/demos/hello-next/pages/index.tsx similarity index 90% rename from demos/hello-next/pages/index.js rename to demos/hello-next/pages/index.tsx index 4db0d5ae6e..2866bad51d 100644 --- a/demos/hello-next/pages/index.js +++ b/demos/hello-next/pages/index.tsx @@ -1,6 +1,9 @@ import Head from "next/head"; import Image from "next/image"; import styles from "../styles/Home.module.css"; +import Link from "next/link"; + +import Title from "../components/Title"; export default function Home() { return ( @@ -13,9 +16,15 @@ export default function Home() {

- Welcome to Next.js! + Welcom Next.js!

+ + + <Link href="/blue"> + <a>Blue page</a> + </Link> + <p className={styles.description}> Get started by editing{" "} <code className={styles.code}>pages/index.js</code>