Skip to content

Commit

Permalink
chore(website): added sassdoc hot-reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaursen committed Sep 9, 2021
1 parent 9ed096e commit 9d58e09
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/documentation/src/pages/packages/[id]/sassdoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NextFC } from "next";

import NotFoundPage from "components/NotFoundPage";
import PackageSassDoc from "components/PackageSassDoc";
import { useHotReload } from "hooks/useHotReload";
import { qsToString } from "utils/routes";
import { PackageSassDoc as FoundSassDoc } from "utils/sassdoc";

Expand All @@ -11,7 +12,13 @@ interface SassDocProps {
sassdoc: FoundSassDoc | null;
}

const SassDoc: NextFC<SassDocProps> = ({ name, sassdoc }) => {
const getSassdoc = (name: string): Promise<FoundSassDoc | null> =>
import(`../../../constants/sassdoc/${name}`)
.then((mod) => mod.default)
.catch(() => null);

const SassDoc: NextFC<SassDocProps> = ({ name, sassdoc: propSassdoc }) => {
const sassdoc = useHotReload(name, propSassdoc, getSassdoc);
if (!sassdoc) {
if (process.env.NODE_ENV !== "production") {
throw new Error(
Expand All @@ -27,9 +34,7 @@ const SassDoc: NextFC<SassDocProps> = ({ name, sassdoc }) => {

SassDoc.getInitialProps = async ({ query }): Promise<SassDocProps> => {
const name = qsToString(query.id);
const sassdoc = await import(`../../../constants/sassdoc/${name}`)
.then((mod) => mod.default)
.catch(() => null);
const sassdoc = await getSassdoc(name);

return { name, sassdoc };
};
Expand Down

0 comments on commit 9d58e09

Please sign in to comment.