fix: call useReqTimelineEnhanced unconditionally to follow Rules of Hooks

- Always call useReqTimelineEnhanced hook regardless of conditions
- Use shouldFetch flag to determine whether to actually fetch
- Pass disabled ID and empty arrays when not fetching
- Fixes 'Rendered more hooks than during the previous render' error
This commit is contained in:
Claude
2026-01-22 15:03:08 +00:00
parent 3ea7151a57
commit e7723cd223
3 changed files with 24 additions and 40 deletions

View File

@@ -175,19 +175,14 @@ function SpellTabContent({
}, [parsed?.relays, targetEvent, spell.name, spellId]);
// Fetch events using the applied filter
const { events, loading, eoseReceived } =
appliedFilter && finalRelays.length > 0
? useReqTimelineEnhanced(
`spell-${spellId}-${targetEventId}`,
appliedFilter,
finalRelays,
{ limit: appliedFilter.limit || 50, stream: true },
)
: {
events: [],
loading: false,
eoseReceived: false,
};
// Always call the hook unconditionally (React Rules of Hooks)
const shouldFetch = !!(appliedFilter && finalRelays.length > 0);
const { events, loading, eoseReceived } = useReqTimelineEnhanced(
shouldFetch ? `spell-${spellId}-${targetEventId}` : `disabled-${spellId}`,
appliedFilter || {},
shouldFetch ? finalRelays : [],
{ limit: appliedFilter?.limit || 50, stream: true },
);
console.log(`[EventSpell:${spell.name || spellId}] Render state:`, {
hasFilter: !!appliedFilter,

View File

@@ -219,19 +219,14 @@ function SpellTabContent({
]);
// Fetch events using the applied filter
const { events, loading, eoseReceived } =
appliedFilter && finalRelays.length > 0
? useReqTimelineEnhanced(
`spell-${spellId}-${targetPubkey}`,
appliedFilter,
finalRelays,
{ limit: appliedFilter.limit || 50, stream: true },
)
: {
events: [],
loading: false,
eoseReceived: false,
};
// Always call the hook unconditionally (React Rules of Hooks)
const shouldFetch = !!(appliedFilter && finalRelays.length > 0);
const { events, loading, eoseReceived } = useReqTimelineEnhanced(
shouldFetch ? `spell-${spellId}-${targetPubkey}` : `disabled-${spellId}`,
appliedFilter || {},
shouldFetch ? finalRelays : [],
{ limit: appliedFilter?.limit || 50, stream: true },
);
console.log(`[SpellTabContent:${spell.name || spellId}] Render state:`, {
hasFilter: !!appliedFilter,

View File

@@ -148,21 +148,15 @@ function SpellTabContent({
}, [parsed?.relays, targetRelay, spell.name, spellId]);
// Fetch events using the applied filter
// Always call the hook unconditionally (React Rules of Hooks)
const shouldFetch = !!(appliedFilter && finalRelays.length > 0);
const { events, loading, eoseReceived, relayStates, overallState } =
appliedFilter && finalRelays.length > 0
? useReqTimelineEnhanced(
`spell-${spellId}-${targetRelay}`,
appliedFilter,
finalRelays,
{ limit: appliedFilter.limit || 50, stream: true },
)
: {
events: [],
loading: false,
eoseReceived: false,
relayStates: new Map(),
overallState: undefined,
};
useReqTimelineEnhanced(
shouldFetch ? `spell-${spellId}-${targetRelay}` : `disabled-${spellId}`,
appliedFilter || {},
shouldFetch ? finalRelays : [],
{ limit: appliedFilter?.limit || 50, stream: true },
);
// Convert relay states to the format expected by SpellHeader
const reqRelayStatesMap = useMemo(() => {