diff options
author | 2021-08-15 22:17:20 -0700 | |
---|---|---|
committer | 2021-08-15 22:17:20 -0700 | |
commit | 23357806183eff94632915239f7b98a4046eb3d7 (patch) | |
tree | efdd9eae103bd29f2a914eccb1f4c2e0009d3fa1 /demos/css-stress-test | |
parent | bd11b04c18ef0ab5ba05b043829a729f45e53d5e (diff) | |
download | bun-23357806183eff94632915239f7b98a4046eb3d7.tar.gz bun-23357806183eff94632915239f7b98a4046eb3d7.tar.zst bun-23357806183eff94632915239f7b98a4046eb3d7.zip |
rename to bun
Former-commit-id: f982fc85fac3f0120e1851ad4027dd8413216439
Diffstat (limited to 'demos/css-stress-test')
-rw-r--r-- | demos/css-stress-test/.env | 1 | ||||
-rw-r--r-- | demos/css-stress-test/.env.development | 1 | ||||
-rw-r--r-- | demos/css-stress-test/.env.local | 1 | ||||
-rw-r--r-- | demos/css-stress-test/nextjs-framework.tsx | 6 | ||||
-rw-r--r-- | demos/css-stress-test/nexty/client.development.tsx | 162 | ||||
-rw-r--r-- | demos/css-stress-test/nexty/package.json | 21 | ||||
-rw-r--r-- | demos/css-stress-test/nexty/renderDocument.tsx | 4 | ||||
-rw-r--r-- | demos/css-stress-test/nexty/server.development.tsx | 16 | ||||
-rw-r--r-- | demos/css-stress-test/node_modules.jsb.zip | bin | 143577 -> 0 bytes | |||
-rw-r--r-- | demos/css-stress-test/package.json | 3 | ||||
-rw-r--r-- | demos/css-stress-test/pages/index.tsx | 4 | ||||
-rw-r--r-- | demos/css-stress-test/src/button.tsx | 1 | ||||
-rw-r--r-- | demos/css-stress-test/src/colors.css | 24 | ||||
-rw-r--r-- | demos/css-stress-test/test-pnpm.js | 2 |
14 files changed, 193 insertions, 53 deletions
diff --git a/demos/css-stress-test/.env b/demos/css-stress-test/.env deleted file mode 100644 index 0b3ef03c1..000000000 --- a/demos/css-stress-test/.env +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_TEST=1
\ No newline at end of file diff --git a/demos/css-stress-test/.env.development b/demos/css-stress-test/.env.development deleted file mode 100644 index 81dc6216e..000000000 --- a/demos/css-stress-test/.env.development +++ /dev/null @@ -1 +0,0 @@ -SO_MANY_DOT_ENVS=true diff --git a/demos/css-stress-test/.env.local b/demos/css-stress-test/.env.local deleted file mode 100644 index 1723445f0..000000000 --- a/demos/css-stress-test/.env.local +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_TEST=100
\ No newline at end of file diff --git a/demos/css-stress-test/nextjs-framework.tsx b/demos/css-stress-test/nextjs-framework.tsx index 38948e482..40aa52ba4 100644 --- a/demos/css-stress-test/nextjs-framework.tsx +++ b/demos/css-stress-test/nextjs-framework.tsx @@ -1,13 +1,13 @@ -import { renderNextJSPage } from "speedy-nextjs/server"; +import { renderNextJSPage } from "bun-nextjs/server"; addEventListener("fetch", (event: FetchEvent) => { const AppComponent = module.requireFirst( "pages/_app", - "speedy-nextjs/pages/_app" + "bun-nextjs/pages/_app" ); const Document = module.requireFirst( "pages/_document", - "speedy-nextjs/pages/_document" + "bun-nextjs/pages/_document" ); }); diff --git a/demos/css-stress-test/nexty/client.development.tsx b/demos/css-stress-test/nexty/client.development.tsx index 82bce03a8..b83d78e01 100644 --- a/demos/css-stress-test/nexty/client.development.tsx +++ b/demos/css-stress-test/nexty/client.development.tsx @@ -30,32 +30,168 @@ import { createRouter, makePublicRouterInstance, } from "next/dist/client/router"; +import * as React from "react"; export const emitter: MittEmitter<string> = mitt(); +declare global { + interface Window { + /* test fns */ + __NEXT_HYDRATED?: boolean; + __NEXT_HYDRATED_CB?: () => void; + + /* prod */ + __NEXT_PRELOADREADY?: (ids?: (string | number)[]) => void; + __NEXT_DATA__: NEXT_DATA; + __NEXT_P: any[]; + } +} + +type RenderRouteInfo = PrivateRouteInfo & { + App: AppComponent; + scroll?: { x: number; y: number } | null; +}; +type RenderErrorProps = Omit<RenderRouteInfo, "Component" | "styleSheets">; + +const data: typeof window["__NEXT_DATA__"] = JSON.parse( + document.getElementById("__NEXT_DATA__")!.textContent! +); +window.__NEXT_DATA__ = data; + +const { + props: hydrateProps, + err: hydrateErr, + page, + query, + buildId, + assetPrefix, + runtimeConfig, + dynamicIds, + isFallback, + locale, + locales, + domainLocales, + isPreview, +} = data; + +const prefix: string = assetPrefix || ""; + +setConfig({ + serverRuntimeConfig: {}, + publicRuntimeConfig: runtimeConfig || {}, +}); + +let asPath: string = getURL(); + +// make sure not to attempt stripping basePath for 404s +if (hasBasePath(asPath)) { + asPath = delBasePath(asPath); +} + +const pageLoader: PageLoader = new PageLoader(buildId, prefix); + +const headManager: { + mountedInstances: Set<unknown>; + updateHead: (head: JSX.Element[]) => void; +} = initHeadManager(); +const appElement: HTMLElement | null = document.getElementById("__next"); + +let lastRenderReject: (() => void) | null; +let webpackHMR: any; +export let router: Router; +let CachedApp: AppComponent, onPerfEntry: (metric: any) => void; + export default function boot(EntryPointNamespace, loader) { _boot(EntryPointNamespace); } -function _boot(EntryPointNamespace) { - const next_data_node = document.querySelector("#__NEXT_DATA__"); - if (!next_data_node) { - throw new Error( - "__NEXT_DATA__ is missing. That means something went wrong while rendering on the server." - ); +class Container extends React.Component<{ + fn: (err: Error, info?: any) => void; +}> { + componentDidCatch(componentErr: Error, info: any) { + this.props.fn(componentErr, info); + } + + componentDidMount() { + this.scrollToHash(); + + // We need to replace the router state if: + // - the page was (auto) exported and has a query string or search (hash) + // - it was auto exported and is a dynamic route (to provide params) + // - if it is a client-side skeleton (fallback render) + if ( + router.isSsr && + // We don't update for 404 requests as this can modify + // the asPath unexpectedly e.g. adding basePath when + // it wasn't originally present + page !== "/404" && + page !== "/_error" && + (isFallback || + (data.nextExport && + (isDynamicRoute(router.pathname) || + location.search || + process.env.__NEXT_HAS_REWRITES)) || + (hydrateProps && + hydrateProps.__N_SSG && + (location.search || process.env.__NEXT_HAS_REWRITES))) + ) { + // update query on mount for exported pages + router.replace( + router.pathname + + "?" + + String( + assign( + urlQueryToSearchParams(router.query), + new URLSearchParams(location.search) + ) + ), + asPath, + { + // @ts-ignore + // WARNING: `_h` is an internal option for handing Next.js + // client-side hydration. Your app should _never_ use this property. + // It may change at any time without notice. + _h: 1, + // Fallback pages must trigger the data fetch, so the transition is + // not shallow. + // Other pages (strictly updating query) happens shallowly, as data + // requirements would already be present. + shallow: !isFallback, + } + ); + } + } + + componentDidUpdate() { + this.scrollToHash(); } - try { - globalThis.NEXT_DATA = JSON.parse(next_data_node.innerHTML); - } catch (error) { - error.message = `Error parsing __NEXT_DATA__\n${error.message}`; - throw error; + scrollToHash() { + let { hash } = location; + hash = hash && hash.substring(1); + if (!hash) return; + + const el: HTMLElement | null = document.getElementById(hash); + if (!el) return; + + // If we call scrollIntoView() in here without a setTimeout + // it won't scroll properly. + setTimeout(() => el.scrollIntoView(), 0); } - const props = { ...globalThis.NEXT_DATA.props }; + render() { + return this.props.children; + } +} +let CachedComponent: React.ComponentType; + +function _boot(EntryPointNamespace) { const PageComponent = EntryPointNamespace.default; ReactDOM.hydrate( - <App Component={PageComponent} pageProps={props.pageProps}></App>, + <Container fn={(error) => <div>{JSON.stringify(error)}</div>}> + <App Component={PageComponent} pageProps={data.props}></App> + </Container>, + document.querySelector("#__next") ); } diff --git a/demos/css-stress-test/nexty/package.json b/demos/css-stress-test/nexty/package.json index ea9879069..359aa3f34 100644 --- a/demos/css-stress-test/nexty/package.json +++ b/demos/css-stress-test/nexty/package.json @@ -1,12 +1,16 @@ { - "name": "nexty", - "version": "1.0.0", + "name": "wipwipwipwip-next-donotuse", + "version": "4.0.0", "description": "", + "main": "package.json", "framework": { "static": "public", "assetPrefix": "_next/", "router": { - "dir": "pages", + "dir": [ + "pages", + "src/pages" + ], "extensions": [ ".js", ".ts", @@ -28,7 +32,8 @@ "process.env.__NEXT_HAS_REWRITES": "false", "process.env.__NEXT_ANALYTICS_ID": "null", "process.env.__NEXT_OPTIMIZE_CSS": "false", - "process.env.__NEXT_CROSS_ORIGIN": "''" + "process.env.__NEXT_CROSS_ORIGIN": "''", + "process.env.__NEXT_STRICT_MODE": "false" } }, "server": { @@ -44,7 +49,8 @@ "process.env.__NEXT_I18N_SUPPORT": "false", "process.env.__NEXT_HAS_REWRITES": "false", "process.env.__NEXT_ANALYTICS_ID": "null", - "process.env.__NEXT_CROSS_ORIGIN": "''" + "process.env.__NEXT_CROSS_ORIGIN": "''", + "process.env.__NEXT_STRICT_MODE": "false" } } } @@ -58,8 +64,5 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "ISC", - "dependencies": { - "next": "^11.1.0" - } + "license": "ISC" } diff --git a/demos/css-stress-test/nexty/renderDocument.tsx b/demos/css-stress-test/nexty/renderDocument.tsx index e5261d4c2..9fd2e8e07 100644 --- a/demos/css-stress-test/nexty/renderDocument.tsx +++ b/demos/css-stress-test/nexty/renderDocument.tsx @@ -468,7 +468,7 @@ export async function render({ isFallback: isFallback, }, true, - Wundle.origin, + Bun.origin, null, [], // renderOpts.locales, null, //renderOpts.defaultLocale, @@ -573,7 +573,7 @@ export async function render({ docComponentsRendered, ...renderOpts, disableOptimizedLoading: false, - canonicalBase: Wundle.origin, + canonicalBase: Bun.origin, buildManifest: { devFiles: [], allFiles: [], diff --git a/demos/css-stress-test/nexty/server.development.tsx b/demos/css-stress-test/nexty/server.development.tsx index 9dfa07168..1f0eaee50 100644 --- a/demos/css-stress-test/nexty/server.development.tsx +++ b/demos/css-stress-test/nexty/server.development.tsx @@ -4,7 +4,7 @@ let buildId = 0; var DocumentNamespacePromise; -DocumentNamespacePromise = import(Wundle.routesDir + "_document"); +DocumentNamespacePromise = import(Bun.routesDir + "_document"); var DocumentLoaded = false; var DocumentNamespace; @@ -21,22 +21,22 @@ addEventListener("fetch", async (event: FetchEvent) => { var appRoute; try { - appRoute = await import(Wundle.routesDir + "_app"); + appRoute = await import(Bun.routesDir + "_app"); } catch (exception) { appRoute = null; } - const appStylesheets = (Wundle.getImportedStyles() as string[]).slice(); - var route = Wundle.match(event); + const appStylesheets = (Bun.getImportedStyles() as string[]).slice(); + var route = Bun.match(event); // This imports the currently matched route. const PageNamespace = await import(route.filePath); // This returns all .css files that were imported in the line above. // It's recursive, so any file that imports a CSS file will be included. - const pageStylesheets = (Wundle.getImportedStyles() as string[]).slice(); + const pageStylesheets = (Bun.getImportedStyles() as string[]).slice(); event.respondWith( - await render({ + render({ route, PageNamespace, appStylesheets, @@ -44,7 +44,7 @@ addEventListener("fetch", async (event: FetchEvent) => { DocumentNamespace, AppNamespace: appRoute, buildId, - routePaths: Wundle.getRouteFiles(), + routePaths: Bun.getRouteFiles(), }) ); buildId++; @@ -53,7 +53,7 @@ addEventListener("fetch", async (event: FetchEvent) => { // typescript isolated modules export {}; -declare var Wundle: any; +declare var Bun: any; function getNextData(request: Request, route) { return { diff --git a/demos/css-stress-test/node_modules.jsb.zip b/demos/css-stress-test/node_modules.jsb.zip Binary files differdeleted file mode 100644 index b24a7823b..000000000 --- a/demos/css-stress-test/node_modules.jsb.zip +++ /dev/null diff --git a/demos/css-stress-test/package.json b/demos/css-stress-test/package.json index a4b3e1f91..e45f6d1f2 100644 --- a/demos/css-stress-test/package.json +++ b/demos/css-stress-test/package.json @@ -15,7 +15,8 @@ "react-dom": "^17.0.2", "react-form": "^4.0.1", "react-hook-form": "^7.8.3", - "url": "^0.11.0" + "url": "^0.11.0", + "wipwipwipwip-next-donotuse": "4.0.0" }, "parcel": "parceldist/index.js", "targets": { diff --git a/demos/css-stress-test/pages/index.tsx b/demos/css-stress-test/pages/index.tsx index aee3be2cf..95d190f81 100644 --- a/demos/css-stress-test/pages/index.tsx +++ b/demos/css-stress-test/pages/index.tsx @@ -1,5 +1,7 @@ import { Main } from "src/main"; -export default function IndexPage() { +export function IndexPage() { return <Main />; } + +export default IndexPage; diff --git a/demos/css-stress-test/src/button.tsx b/demos/css-stress-test/src/button.tsx new file mode 100644 index 000000000..42207a6ca --- /dev/null +++ b/demos/css-stress-test/src/button.tsx @@ -0,0 +1 @@ +export const Button = ({ children }) => <div>asdasasd{children}</div>; diff --git a/demos/css-stress-test/src/colors.css b/demos/css-stress-test/src/colors.css index d45bf4ffc..71d54c25c 100644 --- a/demos/css-stress-test/src/colors.css +++ b/demos/css-stress-test/src/colors.css @@ -1,14 +1,14 @@ :root { - --timestamp: "12812"; - --interval: "8"; - --progress-bar: 11.83299999999997%; - --spinner-1-muted: rgb(142, 6, 182); - --spinner-1-primary: rgb(177, 8, 227); - --spinner-2-muted: rgb(110, 148, 190); - --spinner-2-primary: rgb(138, 185, 238); - --spinner-3-muted: rgb(75, 45, 64); - --spinner-3-primary: rgb(94, 56, 80); - --spinner-4-muted: rgb(155, 129, 108); - --spinner-4-primary: rgb(194, 161, 135); - --spinner-rotate: 213deg; + --timestamp: "596"; + --interval: "64"; + --progress-bar: 33.167%; + --spinner-1-muted: rgb(42, 74, 66); + --spinner-1-primary: rgb(53, 93, 82); + --spinner-2-muted: rgb(90, 51, 192); + --spinner-2-primary: rgb(112, 64, 240); + --spinner-3-muted: rgb(157, 140, 68); + --spinner-3-primary: rgb(196, 175, 85); + --spinner-4-muted: rgb(86, 152, 66); + --spinner-4-primary: rgb(108, 190, 82); + --spinner-rotate: 237deg; }
\ No newline at end of file diff --git a/demos/css-stress-test/test-pnpm.js b/demos/css-stress-test/test-pnpm.js index b494d82dd..a0a27e463 100644 --- a/demos/css-stress-test/test-pnpm.js +++ b/demos/css-stress-test/test-pnpm.js @@ -1 +1 @@ -import jsx from "/Users/jarred/Code/esdev/demos/css-stress-test/node_modules/react/cjs/react-jsx-dev-runtime.development.js"; +import jsx from "/Users/jarred/Code/bun/demos/css-stress-test/node_modules/react/cjs/react-jsx-dev-runtime.development.js"; |