From 1801883b7a40632072e69cc40b4e0a5a196f27a0 Mon Sep 17 00:00:00 2001 From: GreenAsJade Date: Sat, 7 Sep 2024 09:51:41 +0930 Subject: [PATCH 1/2] Defend against GameLog being used in a context without help --- src/views/Game/GameLog.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/views/Game/GameLog.tsx b/src/views/Game/GameLog.tsx index 6c241c92a7..bddf43ab61 100644 --- a/src/views/Game/GameLog.tsx +++ b/src/views/Game/GameLog.tsx @@ -44,7 +44,13 @@ export function GameLog({ const [shouldDisplayFullLog, setShouldDisplayFullLog] = React.useState(false); const { registerTargetItem } = React.useContext(DynamicHelp.Api); - const { ref: autoscoreRef } = registerTargetItem("autoscore-game-log-entry"); + const { ref: autoscoreRef } = { + // this chicanery defends against registerTargetItem being null due to this component _not_ being + // wrapped in OGSHelpProvider, which happens when it is in a Modal. + // TBD: make Modals be inside OGSHelpProvider, so they can have help. + ref: null, + ...registerTargetItem?.("autoscore-game-log-entry"), + }; const game_id = goban_config.game_id as number; From 00044c6813a12b9e36119f6e17866cad066524c9 Mon Sep 17 00:00:00 2001 From: GreenAsJade Date: Sat, 7 Sep 2024 10:00:42 +0930 Subject: [PATCH 2/2] Simplify chicanery --- src/views/Game/GameLog.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/views/Game/GameLog.tsx b/src/views/Game/GameLog.tsx index bddf43ab61..8eb01c481e 100644 --- a/src/views/Game/GameLog.tsx +++ b/src/views/Game/GameLog.tsx @@ -44,14 +44,10 @@ export function GameLog({ const [shouldDisplayFullLog, setShouldDisplayFullLog] = React.useState(false); const { registerTargetItem } = React.useContext(DynamicHelp.Api); - const { ref: autoscoreRef } = { - // this chicanery defends against registerTargetItem being null due to this component _not_ being - // wrapped in OGSHelpProvider, which happens when it is in a Modal. - // TBD: make Modals be inside OGSHelpProvider, so they can have help. - ref: null, - ...registerTargetItem?.("autoscore-game-log-entry"), - }; + // Defend against the case where we aren't wrapped in a help provider: in a Modal + // TBD: made Modals be able to use the help provider + const autoscoreRef = registerTargetItem?.("autoscore-game-log-entry")?.ref || null; const game_id = goban_config.game_id as number; let firstAutoscoringEntryRendered = false;