Fix create-mode crash in detail panels (null entity access)

The desktop detail panels are pre-mounted (always in DOM, hidden with w-0).
useState(isCreating) only captures the initial value on mount (false), so
when isCreating later becomes true via props, isEditing stays false. The
view-mode branch then runs with a null entity, crashing on property access.

Fix: use (isEditing || isCreating) for all conditionals that gate between
edit/create form and view mode, ensuring the form always renders when
isCreating is true regardless of isEditing state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kyle 2026-02-27 09:57:19 +08:00
parent f07ce02576
commit a128005ae5
3 changed files with 6 additions and 6 deletions

View File

@ -480,7 +480,7 @@ export default function EventDetailPanel({
> >
<X className="h-3.5 w-3.5" /> <X className="h-3.5 w-3.5" />
</Button> </Button>
) : isEditing ? ( ) : (isEditing || isCreating) ? (
<> <>
<Button <Button
variant="ghost" variant="ghost"
@ -586,7 +586,7 @@ export default function EventDetailPanel({
</Button> </Button>
</div> </div>
</div> </div>
) : isEditing ? ( ) : (isEditing || isCreating) ? (
/* Edit / Create mode */ /* Edit / Create mode */
<div className="space-y-4"> <div className="space-y-4">
{/* Title (only shown in body for create mode; edit mode has it in header) */} {/* Title (only shown in body for create mode; edit mode has it in header) */}

View File

@ -224,7 +224,7 @@ export default function ReminderDetailPanel({
)} )}
<div className="flex items-center gap-1 shrink-0"> <div className="flex items-center gap-1 shrink-0">
{isEditing ? ( {(isEditing || isCreating) ? (
<> <>
<Button <Button
variant="ghost" variant="ghost"
@ -308,7 +308,7 @@ export default function ReminderDetailPanel({
{/* Body */} {/* Body */}
<div className="flex-1 overflow-y-auto px-5 py-4 space-y-3"> <div className="flex-1 overflow-y-auto px-5 py-4 space-y-3">
{isEditing ? ( {(isEditing || isCreating) ? (
/* Edit / Create mode */ /* Edit / Create mode */
<div className="space-y-4"> <div className="space-y-4">
{isCreating && ( {isCreating && (

View File

@ -254,7 +254,7 @@ export default function TodoDetailPanel({
)} )}
<div className="flex items-center gap-1 shrink-0"> <div className="flex items-center gap-1 shrink-0">
{isEditing ? ( {(isEditing || isCreating) ? (
<> <>
<Button <Button
variant="ghost" variant="ghost"
@ -326,7 +326,7 @@ export default function TodoDetailPanel({
{/* Body */} {/* Body */}
<div className="flex-1 overflow-y-auto px-5 py-4 space-y-3"> <div className="flex-1 overflow-y-auto px-5 py-4 space-y-3">
{isEditing ? ( {(isEditing || isCreating) ? (
/* Edit / Create mode */ /* Edit / Create mode */
<div className="space-y-4"> <div className="space-y-4">
{isCreating && ( {isCreating && (