Always provide sensible default or fallback values for configuration properties to prevent undefined states that can block users or cause application errors. Configuration properties should never be left in an undefined state that prevents normal application functionality.
Always provide sensible default or fallback values for configuration properties to prevent undefined states that can block users or cause application errors. Configuration properties should never be left in an undefined state that prevents normal application functionality.
When defining configuration properties, especially those that come from external sources (servers, user settings, migrations), include appropriate fallback values using logical OR operators or default parameter values.
Example of proper fallback implementation:
// Good: Provides fallback to prevent undefined state
const selectedProvider =
(currentMode === "plan" ? apiConfiguration?.planModeApiProvider : apiConfiguration?.actModeApiProvider) || "cline"
// Good: Default parameter with fallback URL
const CreditLimitError: React.FC<CreditLimitErrorProps> = ({
buyCreditsUrl = "https://api.cline.bot/dashboard/account?tab=credits&redirect=true",
// other props...
}) => {
// Good: Explicit default value to prevent UI flashing
const defaultState = {
welcomeViewCompleted: false, // Default to show welcome unless overridden
// other defaults...
}
This practice is especially critical for:
The fallback values should represent the most sensible default behavior for new users or error recovery scenarios.
Enter the URL of a public GitHub repository