Repository navigation
Fix: live mode (and all non-chat content) falling back to chat-widget - #597
Conversation
…service Live mode, logs, factory, etc. were all falling back to chat-widget because the recipe service wasn't loaded yet when switchContentView fired. Generated config (compiled from recipe JSON files) is always available synchronously. Check it first, recipe service second.
There was a problem hiding this comment.
Pull request overview
This PR aims to fix incorrect widget selection during early startup (before the async recipe layout service is loaded) by changing how getWidgetForType() resolves a widget for a given content type.
Changes:
- Reordered
getWidgetForType()to checkCONTENT_TYPE_CONFIGS(generated config) before consultingRecipeLayoutService. - Updated inline comments around the lookup order and “unknown type” handling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 1. Generated config FIRST — always available, no async, no race conditions | ||
| // This is the compiled-in truth from recipe JSON files. | ||
| const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType]; | ||
| if (generated) return generated.widget; | ||
|
|
||
| // 2. Recipe service — runtime data from DB (may have newer recipes) | ||
| const recipeService = getRecipeLayoutService(); | ||
| if (recipeService.isLoaded()) { | ||
| const widget = recipeService.getWidget(contentType); | ||
| if (widget) return widget; | ||
| } | ||
|
|
There was a problem hiding this comment.
getWidgetForType() now returns the generated config’s widget immediately, which means the RecipeLayoutService can no longer override widgets for known content types. This breaks cases where the generated config is out of sync with runtime layouts (e.g., live.json uses new layout.widgets with center live-widget, but CONTENT_TYPE_CONFIGS['live'].widget is currently chat-widget; same pattern for logs). As written, live/logs will still render chat-widget even after recipes load. Consider using the generated widget as a default but, when recipeService.isLoaded(), prefer recipeService.getWidget(contentType) if it returns a value; and/or update the generator to derive widget from the new layout.widgets format so the generated config is correct.
| // 1. Generated config FIRST — always available, no async, no race conditions | |
| // This is the compiled-in truth from recipe JSON files. | |
| const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType]; | |
| if (generated) return generated.widget; | |
| // 2. Recipe service — runtime data from DB (may have newer recipes) | |
| const recipeService = getRecipeLayoutService(); | |
| if (recipeService.isLoaded()) { | |
| const widget = recipeService.getWidget(contentType); | |
| if (widget) return widget; | |
| } | |
| // 1. Recipe service — runtime data from DB (may have newer recipes) | |
| const recipeService = getRecipeLayoutService(); | |
| if (recipeService.isLoaded()) { | |
| const widget = recipeService.getWidget(contentType); | |
| if (widget) return widget; | |
| } | |
| // 2. Generated config — compiled-in truth from recipe JSON files. | |
| const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType]; | |
| if (generated) return generated.widget; |
| * Get widget tag name for a content type. | ||
| * Recipe service (runtime) → generated config (build-time) → error. | ||
| */ | ||
| export function getWidgetForType(contentType: string): string { | ||
| // 1. Recipe service has the most up-to-date info (loaded from DB/files at runtime) | ||
| // 1. Generated config FIRST — always available, no async, no race conditions | ||
| // This is the compiled-in truth from recipe JSON files. | ||
| const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType]; | ||
| if (generated) return generated.widget; |
There was a problem hiding this comment.
The function docstring still states “Recipe service (runtime) → generated config (build-time) → error.”, but the implementation now checks generated config first and then falls back to chat-widget after logging an error. Please update the comment to reflect the actual resolution order and whether there is a fallback, so it doesn’t mislead future changes/debugging.
|
|
||
| // 3. No fallback — unknown type is an error | ||
| // 3. No match — unknown type | ||
| console.error(`Unknown content type: '${contentType}'. Add a recipe in system/recipes/${contentType}.json`); |
There was a problem hiding this comment.
The error path logs “Unknown content type …” but then silently falls back to chat-widget. If fallback is intentional, the log message should explicitly say it’s falling back (and ideally be a warn), otherwise consider throwing/returning an explicit error to match the “unknown type is an error” behavior described elsewhere in this module.
| console.error(`Unknown content type: '${contentType}'. Add a recipe in system/recipes/${contentType}.json`); | |
| console.warn( | |
| `Unknown content type: '${contentType}'. Add a recipe in system/recipes/${contentType}.json. Falling back to 'chat-widget'.`, | |
| ); |
Problem
Live mode tab showed general chat instead of live-widget. Same for logs, factory, grid, canvas — all content types were falling back to chat-widget.
Root Cause
getWidgetForType()checked the async recipe service FIRST. If it wasn't loaded yet (race condition on startup), it fell through to fallback = chat-widget. The generated config (compiled from recipe JSON, always available synchronously) was only checked SECOND.Fix
Swap the order: check generated config first (always available), recipe service second (for runtime updates). No more race condition.
Test