Skip to content
Closed
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
12 changes: 8 additions & 4 deletions packages/react/src/accordion/item/AccordionItemContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import * as React from 'react';
import type { AccordionItem } from './AccordionItem';
import { productionContextError } from '../../utils/productionContextError';

export interface AccordionItemContext {
open: boolean;
Expand All @@ -19,10 +20,13 @@ if (process.env.NODE_ENV !== 'production') {

export function useAccordionItemContext() {
const context = React.useContext(AccordionItemContext);
if (context === undefined) {
throw new Error(
'Base UI: AccordionItemContext is missing. Accordion parts must be placed within <Accordion.Item>.',
);
if (!context) {
if (process.env.NODE_ENV !== 'production') {
throw new Error(
'Base UI: AccordionItemContext is missing. Accordion parts must be placed within <Accordion.Item>.',
);
}
productionContextError();
}
return context;
}
3 changes: 3 additions & 0 deletions packages/react/src/utils/productionContextError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function productionContextError(): never {
throw new Error('Base UI: Invalid component tree');
}
Comment on lines +1 to +3
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React's minified errors link to a webpage that details the error, but this seems unnecessary for invalid component trees since it's certain to be encountered while developing beforehand