feat(web_core): expose theme from ComponentContext#1027
feat(web_core): expose theme from ComponentContext#1027ppazosp wants to merge 1 commit intogoogle:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a theme property to the ComponentContext class, allowing components to access theme configurations from the surface. Unit tests were included to verify that the theme is correctly exposed and defaults to an empty object. A review comment suggests replacing the any type with Record<string, any> to improve type safety.
| /** The collection of all component models for the current surface, allowing lookups by ID. */ | ||
| readonly surfaceComponents: SurfaceComponentsModel; | ||
| /** The theme configuration for the surface this component belongs to. */ | ||
| readonly theme: any; |
There was a problem hiding this comment.
Using any for the theme property forfeits TypeScript's type safety benefits. While the source surface.theme is also of type any, we can improve clarity and type safety here by using a more descriptive type. Record<string, any> makes it clear that theme is an object with string keys, which is a good improvement over a plain any and helps with future maintenance.
| readonly theme: any; | |
| readonly theme: Record<string, any>; |
There was a problem hiding this comment.
I intentionally matched the type from SurfaceModel.theme (any) to keep them consistent. Changing only this side to Record<string, any> would create a mismatch between the source and the consumer. If the team decides to strengthen the type on SurfaceModel, this should follow along with it.
Description
Exposes the
themeobject fromSurfaceModeldirectly onComponentContext, following the implementation strategy outlined by @jacobsimionato in #976.This allows component implementations across all renderers to access theme properties (e.g.
primaryColor,iconUrl,agentDisplayName) directly from context without traversing the surface model.Changes
component-context.ts: Addedreadonly theme: anyproperty, assigned fromsurface.themein the constructorcomponent-context.test.ts: Added 2 tests — verifies theme is exposed when provided and defaults to{}when notAll 255 existing web_core tests pass.
This is a prerequisite for wiring up consistent theme support across all renderers, complementing #1025 (React CSS variable injection).
Closes #976
Pre-launch Checklist
If you need help, consider asking for advice on the discussion board.