fix: ActivitiesCard crashes — t() in a prop default has no scope

`ActivitiesCard` takes its title as `({ title = t('activity.title') })`.
A default parameter is evaluated in the function's own scope, where `t`
does not exist: the only `t` in the file is bound inside `ActivityItem`,
a separate component. `Sidepanel` renders the card without a `title`, and
`activities` is `enabled: true` in `DEFAULT_SIDEPANEL_CONFIG`, so the
default is always evaluated on a desktop-width screen.

The hook moves into the component body and the title falls back there
instead. Same rendered output; three render sites now read `displayTitle`.

This is my regression: it arrived with #216, which described itself as
"no behaviour change". It was not caught because a bundler cannot flag it
— an unbound `t` is indistinguishable from a global — and my checks only
verified that keys and imports existed, not that `t` was in scope. It is
visible in the built bundle: `({title:e=t("activity.title")})` keeps the
literal `t` because the minifier cannot rename a free variable, while a
working call nearby minifies to `q=e("common.confirm")`.

I have added an eslint `no-undef` pass to my own pipeline and run it
before sending anything from now on.
This commit is contained in:
everysingletear
2026-08-15 15:45:20 +08:00
parent 96ba672b09
commit d813971809

View File

@@ -274,7 +274,9 @@ const groupActivitiesByDate = activities => {
return groups
}
const ActivitiesCard = ({ title = t('activity.title') }) => {
const ActivitiesCard = ({ title }) => {
const { t } = useTranslation('chores')
const displayTitle = title || t('activity.title')
const [noteViewerConfig, setNoteViewerConfig] = useState({ isOpen: false })
// Use hooks to fetch data
@@ -323,7 +325,7 @@ const ActivitiesCard = ({ title = t('activity.title') }) => {
}}
>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mb: 2 }}>
<Typography level='title-md'>{title}</Typography>
<Typography level='title-md'>{displayTitle}</Typography>
</Box>
<Box
sx={{
@@ -380,7 +382,7 @@ const ActivitiesCard = ({ title = t('activity.title') }) => {
>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mb: 2 }}>
<EventNote color='' />
<Typography level='title-md'>{title}</Typography>
<Typography level='title-md'>{displayTitle}</Typography>
</Box>
<Box
sx={{
@@ -425,7 +427,7 @@ const ActivitiesCard = ({ title = t('activity.title') }) => {
>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<EventNote color='' />
<Typography level='title-md'>{title}</Typography>
<Typography level='title-md'>{displayTitle}</Typography>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Chip size='sm' variant='soft' color='neutral'>