-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Migrate from Next.js to pure webpack config (#360)
Fix for #348 - migrate our NextJS project to a pure webpack project w/ a single bundle - [x] Switch from `next/link` to `react-router-dom`'s link > This part was easy - just change the import to `import { Link } from "react-router-dom"` and `<Link href={...} />` to `<Link to={...} />` - [x] Switch from `next/router` to `react-router-dom`'s paradigms (`useNavigation`, `useLocation`, and `useParams`) > `router.push` can be converted to `navigate(...)` (provided by the `useNavigate` hook) > `router.replace` can be converted `navigate(..., {replace: true})` > Query parameters (`const { query } = useRouter`) can be converted to `const query = useParams()`) - [x] Implement client-side routing with `react-router-dom` > Parameterized routes in NextJS like `projects/[organization]/[project]` would look like: > ``` > <Route path="projects"> > <Route path=":organization/:project"> > <Route index element={<ProjectPage />} /> > </Route> > </Route> > ``` I've hooked up a `build:analyze` command that spins up a server to show the bundle size: <img width="1303" alt="image" src="https://user-images.githubusercontent.com/88213859/157496889-87c5fdcd-fad1-4f2e-b7b6-437aebf99641.png"> The bundle looks OK, but there are some opportunities for improvement - the heavy-weight dependencies, like React, ReactDOM, Material-UI, and lodash could be brought in via a CDN: https://stackoverflow.com/questions/50645796/how-to-import-reactjs-material-ui-using-a-cdn-through-webpacks-externals
- Loading branch information
1 parent
bf1f858
commit ec077c6
Showing
47 changed files
with
1,903 additions
and
1,302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from "react" | ||
import ReactDOM from "react-dom" | ||
|
||
import { App } from "./app" | ||
|
||
// This is the entry point for the app - where everything start. | ||
// In the future, we'll likely bring in more bootstrapping logic - | ||
// like: https://github.com/coder/m/blob/50898bd4803df7639bd181e484c74ac5d84da474/product/coder/site/pages/_app.tsx#L32 | ||
const main = () => { | ||
const element = document.getElementById("root") | ||
ReactDOM.render(<App />, element) | ||
} | ||
|
||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from "react" | ||
import CssBaseline from "@material-ui/core/CssBaseline" | ||
import ThemeProvider from "@material-ui/styles/ThemeProvider" | ||
import { SWRConfig } from "swr" | ||
import { UserProvider } from "./contexts/UserContext" | ||
import { light } from "./theme" | ||
import { BrowserRouter as Router, Route, Routes } from "react-router-dom" | ||
|
||
import { CliAuthenticationPage } from "./pages/cli-auth" | ||
import { NotFoundPage } from "./pages/404" | ||
import { IndexPage } from "./pages/index" | ||
import { SignInPage } from "./pages/login" | ||
import { ProjectsPage } from "./pages/projects" | ||
import { ProjectPage } from "./pages/projects/[organization]/[project]" | ||
import { CreateWorkspacePage } from "./pages/projects/[organization]/[project]/create" | ||
import { WorkspacePage } from "./pages/workspaces/[workspace]" | ||
|
||
export const App: React.FC = () => { | ||
return ( | ||
<Router> | ||
<SWRConfig | ||
value={{ | ||
// This code came from the SWR documentation: | ||
// https://swr.vercel.app/docs/error-handling#status-code-and-error-object | ||
fetcher: async (url: string) => { | ||
const res = await fetch(url) | ||
|
||
// By default, `fetch` won't treat 4xx or 5xx response as errors. | ||
// However, we want SWR to treat these as errors - so if `res.ok` is false, | ||
// we want to throw an error to bubble that up to SWR. | ||
if (!res.ok) { | ||
const err = new Error((await res.json()).error?.message || res.statusText) | ||
throw err | ||
} | ||
return res.json() | ||
}, | ||
}} | ||
> | ||
<UserProvider> | ||
<ThemeProvider theme={light}> | ||
<CssBaseline /> | ||
|
||
<Routes> | ||
<Route path="/"> | ||
<Route index element={<IndexPage />} /> | ||
|
||
<Route path="login" element={<SignInPage />} /> | ||
<Route path="cli-auth" element={<CliAuthenticationPage />} /> | ||
|
||
<Route path="projects"> | ||
<Route index element={<ProjectsPage />} /> | ||
<Route path=":organization/:project"> | ||
<Route index element={<ProjectPage />} /> | ||
<Route path="create" element={<CreateWorkspacePage />} /> | ||
</Route> | ||
</Route> | ||
|
||
<Route path="workspaces"> | ||
<Route path=":workspace" element={<WorkspacePage />} /> | ||
</Route> | ||
|
||
{/* Using path="*"" means "match anything", so this route | ||
acts like a catch-all for URLs that we don't have explicit | ||
routes for. */} | ||
<Route path="*" element={<NotFoundPage />} /> | ||
</Route> | ||
</Routes> | ||
</ThemeProvider> | ||
</UserProvider> | ||
</SWRConfig> | ||
</Router> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from "./Button" | ||
export * from "./EmptyState" | ||
export * from "./Page" | ||
export * from "./Redirect" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.