Replies: 4 comments
-
It's kind of hard to understand what this even means. What is "a certain condition", be precise and give a very concrete example. I'm not able to understand the goal of your code snippet at all 😅 It would be helpful to create a simplified repro. If any of your React components throw at render time, it will also fail the build. We render those components during the build. # My Doc
import ThrowIf from '@site/src/components/throwIf'
<ThrowIf test={() => concepts.has("abc"}/> |
Beta Was this translation helpful? Give feedback.
-
No worries. I also struggled a lot while explaining it. It's a complex setup.
It is failing during runtime, specifically when I click on I'll try to give a short example below. Hopefully that's more understandable: // My component file at src/components/Concept.tsx
type ConceptData = {
title : string
kind : string
}
type ConceptsMap = Map<string, ConceptData>;
const ConceptList :ConceptsMap= new Map();
export const Concept = (props) => {
if (ConceptList.has(props.title)) {
// Check that we are not accidentally re-registering the data (ideally check at compile time)
if (props.kind) throw Error("Tried to define a `.kind=` property for a concept that already exists: "+props.title)
// Render an already existing component. Don't need any other props.
return (<ExistingConcept title={props.title} />);
} else {
// Store a new Concept from the data passed, AND also render it
return (
<NewConcept
title = {props.title}
kind = {props.kind}
>
{props.children}
</NewConcept>
}
} import Concept from '@site/src/components/Concept.tsx'
# Example MDX file
This registers+renders a new concept with the defined title.
<Concept title="Thing" kind="SomeKind" />
This renders the above existing concept again.
<Concept title="Thing"/>
This is another correct usage of the concept.
They all trigger an error at runtime when clicking on hN and ToC hyperlinks.
<Concept title="Thing"/>
This should error at compile time, but triggers at runtime.
<Concept title="Thing" kind="Some other Kind for Thing" /> |
Beta Was this translation helpful? Give feedback.
-
Can't you make a simplified https://docusaurus.new/stackblitz runnable repro instead? This way you show me runnable code that doesn't throw (but should), and I will be able to fix it (make it throw) for you. You can probably simplify things greatly. Do we really need all the complexity of your whole system to show you that it's possible to make site compilation fail? |
Beta Was this translation helpful? Give feedback.
-
Hi, @slorber I don't want to create noise in your repo, and there is no ETA for getting back to complete the task I will save the link to this thread internally, so we can come back to it sometime in the future. Thank you so much for your time! |
Beta Was this translation helpful? Give feedback.
-
Is there an existing way to trigger compile-time-only errors that trigger under a certain condition defined inside an MDX component?
I've been trying this approach, but they seem to bug/fail when combined with Markdown Partials or Custom MDX Components.
They currently trigger incorrectly when clicking on a
##
link,and trigger correctly when they are setup to trigger for debugging.
But they trigger at runtime, not a compile-time, so I wonder if there could be a way to trigger them only when the website is built.
Beta Was this translation helpful? Give feedback.
All reactions