aboutsummaryrefslogtreecommitdiff
path: root/examples/hello-next/bun-framework-next
diff options
context:
space:
mode:
Diffstat (limited to 'examples/hello-next/bun-framework-next')
-rw-r--r--examples/hello-next/bun-framework-next/client.development.tsx6
-rw-r--r--examples/hello-next/bun-framework-next/package.json5
-rw-r--r--examples/hello-next/bun-framework-next/renderDocument.tsx94
-rw-r--r--examples/hello-next/bun-framework-next/server.development.tsx11
4 files changed, 99 insertions, 17 deletions
diff --git a/examples/hello-next/bun-framework-next/client.development.tsx b/examples/hello-next/bun-framework-next/client.development.tsx
index a4ef9bf96..755441fa2 100644
--- a/examples/hello-next/bun-framework-next/client.development.tsx
+++ b/examples/hello-next/bun-framework-next/client.development.tsx
@@ -1,3 +1,7 @@
+globalThis.global = globalThis;
+globalThis.Bun_disableCSSImports = true;
+
+import * as React from "react";
var onlyChildPolyfill = React.Children.only;
React.Children.only = function (children) {
if (children && typeof children === "object" && children.length == 1) {
@@ -7,7 +11,6 @@ React.Children.only = function (children) {
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";
@@ -43,7 +46,6 @@ import {
createRouter,
makePublicRouterInstance,
} from "next/dist/client/router";
-import * as React from "react";
export const emitter: MittEmitter<string> = mitt();
declare global {
diff --git a/examples/hello-next/bun-framework-next/package.json b/examples/hello-next/bun-framework-next/package.json
index fbe7a1d60..9436aef52 100644
--- a/examples/hello-next/bun-framework-next/package.json
+++ b/examples/hello-next/bun-framework-next/package.json
@@ -1,6 +1,6 @@
{
"name": "bun-framework-next",
- "version": "0.0.0-9",
+ "version": "0.0.0-11",
"description": "",
"framework": {
"static": "public",
@@ -13,7 +13,8 @@
"extensions": [
".js",
".ts",
- ".tsx"
+ ".tsx",
+ ".jsx"
]
},
"css": "onimportcss",
diff --git a/examples/hello-next/bun-framework-next/renderDocument.tsx b/examples/hello-next/bun-framework-next/renderDocument.tsx
index 67c89efc2..d55e35ed6 100644
--- a/examples/hello-next/bun-framework-next/renderDocument.tsx
+++ b/examples/hello-next/bun-framework-next/renderDocument.tsx
@@ -21,17 +21,57 @@ import * as NextDocument from "next/document";
import * as ReactDOMServer from "react-dom/server.browser";
import * as url from "url";
import * as React from "react";
-
+import * as ReactIs from "react-is";
const dev = process.env.NODE_ENV === "development";
type ParsedUrlQuery = Record<string, string | string[]>;
const isJSFile = (file: string) =>
file.endsWith(".js") ||
+ file.endsWith(".jsx") ||
file.endsWith(".mjs") ||
file.endsWith(".ts") ||
file.endsWith(".tsx");
+const notImplementedProxy = (base) =>
+ new Proxy(
+ {},
+ {
+ deleteProperty: function (target, prop) {
+ return undefined;
+ },
+ enumerate: function (oTarget, sKey) {
+ return [].entries();
+ },
+ ownKeys: function (oTarget, sKey) {
+ return [].values();
+ },
+ has: function (oTarget, sKey) {
+ return false;
+ },
+ defineProperty: function (oTarget, sKey, oDesc) {
+ return undefined;
+ },
+ getOwnPropertyDescriptor: function (oTarget, sKey) {
+ return undefined;
+ },
+ get(this, prop) {
+ throw new ReferenceError(
+ `${base} is not available for this environment.`
+ );
+ },
+ set(this, prop, value) {
+ throw new ReferenceError(
+ `${base} is not available for this environment.`
+ );
+ },
+ }
+ );
+
+globalThis.fetch = (url, options) => {
+ return Promise.reject(new Error(`fetch is not implemented yet. sorry!!`));
+};
+
function getScripts(files: DocumentFiles) {
const { context, props } = this;
const {
@@ -396,6 +436,31 @@ export async function render({
const headTags = (...args: any) => callMiddleware("headTags", args);
+ if (!ReactIs.isValidElementType(Component)) {
+ const exportNames = Object.keys(PageNamespace || {});
+
+ const reactComponents = exportNames.filter(ReactIs.isValidElementType);
+ if (reactComponents.length > 2) {
+ throw new Error(
+ `\"export default\" missing in ${
+ route.filePath
+ }.\nTry exporting one of ${reactComponents.join(", ")}\n`
+ );
+ } else if (reactComponents.length === 2) {
+ throw new Error(
+ `\"export default\" missing in ${route.filePath}.\n\nTry exporting <${reactComponents[0]} /> or <${reactComponents[1]} />\n`
+ );
+ } else if (reactComponents.length == 1) {
+ throw new Error(
+ `\"export default\" missing in ${route.filePath}. Try adding this to the bottom of the file:\n\n export default ${reactComponents[0]};\n`
+ );
+ } else if (reactComponents.length == 0) {
+ throw new Error(
+ `\"export default\" missing in ${route.filePath}. Try exporting a React component.\n`
+ );
+ }
+ }
+
const isFallback = !!query.__nextFallback;
delete query.__nextFallback;
delete query.__nextLocale;
@@ -503,6 +568,32 @@ export async function render({
ctx,
});
+ // This isn't correct.
+ // We don't call getServerSideProps on clients.
+ const getServerSideProps = PageNamespace.getServerSideProps;
+ if (typeof getServerSideProps === "function") {
+ const result = await getServerSideProps({
+ params: route.params,
+ query: route.query,
+ req: notImplementedProxy("req"),
+ res: notImplementedProxy("res"),
+ resolvedUrl: route.pathname,
+ preview: false,
+ previewData: null,
+ locale: null,
+ locales: [],
+ defaultLocale: null,
+ });
+
+ if (result) {
+ if ("props" in result) {
+ if (typeof result.props === "object") {
+ Object.assign(props, result.props);
+ }
+ }
+ }
+ }
+
const renderToString = ReactDOMServer.renderToString;
const ErrorDebug = null;
@@ -567,7 +658,6 @@ export async function render({
const docComponentsRendered: DocumentProps["docComponentsRendered"] = {};
const isPreview = false;
- const getServerSideProps = PageNamespace.getServerSideProps;
let html = renderDocument(Document, {
docComponentsRendered,
diff --git a/examples/hello-next/bun-framework-next/server.development.tsx b/examples/hello-next/bun-framework-next/server.development.tsx
index 82caf0ab7..02c3eaee0 100644
--- a/examples/hello-next/bun-framework-next/server.development.tsx
+++ b/examples/hello-next/bun-framework-next/server.development.tsx
@@ -71,14 +71,3 @@ addEventListener("fetch", async (event: FetchEvent) => {
export {};
declare var Bun: any;
-
-function getNextData(request: Request, route) {
- return {
- NEXT_DATA: {
- query: route.query,
- props: {},
- page: route.path,
- buildId: buildId.toString(16),
- },
- };
-}