Feat: error-decoder (#6214)

* Feat: port error-decoder

* Fix: do not choke on empty invariant

* Refactor: read url query from `useRouter`

* Fix: argsList can contains `undefined`

* Fix: handle empty string arg

* Feat: move error decoder to the separate page

* Fix: wrap error decoder header in <Intro />

* Perf: cache GitHub RAW requests

* Refactor: apply code review suggestions

* Fix: build error

* Refactor: apply code review suggestions

* Discard changes to src/content/index.md

* Fix: animation duration/delay

* Refactor: read error page from markdown

* Fix lint

* Fix /error being 404

* Prevent `_default.md` being included in `[[...markdownPath]].md`

* Fix custom error markdown reading

* Updates

---------

Co-authored-by: Ricky Hanlon <rickhanlonii@gmail.com>
This commit is contained in:
Sukka
2024-01-13 05:18:21 +08:00
committed by GitHub
parent 6987f0fb30
commit 8d2664b806
11 changed files with 504 additions and 135 deletions

View File

@@ -0,0 +1,23 @@
// Error Decoder requires reading pregenerated error message from getStaticProps,
// but MDX component doesn't support props. So we use React Context to populate
// the value without prop-drilling.
// TODO: Replace with React.cache + React.use when migrating to Next.js App Router
import {createContext, useContext} from 'react';
const notInErrorDecoderContext = Symbol('not in error decoder context');
export const ErrorDecoderContext = createContext<
| {errorMessage: string | null; errorCode: string | null}
| typeof notInErrorDecoderContext
>(notInErrorDecoderContext);
export const useErrorDecoderParams = () => {
const params = useContext(ErrorDecoderContext);
if (params === notInErrorDecoderContext) {
throw new Error('useErrorDecoder must be used in error decoder pages only');
}
return params;
};