Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { lazy, Suspense } from "react";
import { createRoot } from "react-dom/client";
import { ErrorBoundary } from "react-error-boundary";

const Index = lazy(async () => import("./index"));
const containerId = "root";
const container = document.getElementById(containerId);
if (!container) {
throw Error(`couldn't find element with id ${containerId}!`);
}
const root = createRoot(container);
root.render(
<ErrorBoundary fallback={<div>Something went wrong...</div>}>
<Suspense fallback="loading">
<Index />
</Suspense>
</ErrorBoundary>,
);
27 changes: 14 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { lazy, Suspense } from "react";
import { createRoot } from "react-dom/client";
import type { ReactElement } from "react";
import { ErrorBoundary } from "react-error-boundary";

const App = lazy(async () => import("./App"));
const containerId = "root";
const container = document.getElementById(containerId);
if (!container) {
throw Error(`couldn't find element with id ${containerId}!`);

export default function Index(): ReactElement {
return (
<ErrorBoundary FallbackComponent={Fallback}>
<Suspense fallback="loading">
<App />
</Suspense>
</ErrorBoundary>
);
}

function Fallback({ error }: { error: Error }): ReactElement {
return <p>{error.message}</p>;
}
const root = createRoot(container);
root.render(
<ErrorBoundary fallback={<div>shit hit the fan bruv!</div>}>
<Suspense fallback="loading">
<App />
</Suspense>
</ErrorBoundary>,
);
9 changes: 8 additions & 1 deletion webpack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function webpackConfig(_env, { mode = "development" }) {
return {
mode,
devtool: isDevelopment ? "eval-source-map" : "source-map",
entry: "./src/index.tsx",
entry: "./src/bootstrap.tsx",
devServer: {
hot: true,
historyApiFallback: true,
Expand Down Expand Up @@ -94,6 +94,13 @@ function webpackConfig(_env, { mode = "development" }) {
}),
isDevelopment && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
performance:
mode === "production"
? {
maxEntrypointSize: 200000,
hints: "warning",
}
: undefined,
};
}

Expand Down