From 6cc28dbc860af00996c44dda6dc8b03867eb1527 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 18 Mar 2026 16:23:02 -0400 Subject: [PATCH 1/2] fix: address PR #11 review feedback from Copilot - Await async post_message() in 8-modules example - Update ShinyModuleContext JSDoc to reflect nesting behavior - Clarify applyNamespace docs for empty string/null/undefined - Add namespace prop JSDoc to ImageOutput component - Remove debug print(env_file) in 7-chat example - Fix tailwind.css path in 5-shadcn components.json - Fix 5-shadcn package.json name/description, add private:true - Fix indentation in 8-modules srcts-standard/main.tsx Co-Authored-By: Claude Opus 4.6 --- examples/shiny-react-upstream/5-shadcn/components.json | 2 +- examples/shiny-react-upstream/5-shadcn/package.json | 5 +++-- examples/shiny-react-upstream/7-chat/py/app.py | 1 - examples/shiny-react-upstream/8-modules/py/app.py | 4 ++-- .../8-modules/srcts-standard/main.tsx | 2 +- js/src/shiny-react/ImageOutput.tsx | 4 ++++ js/src/shiny-react/ShinyModuleContext.tsx | 9 +++++---- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/shiny-react-upstream/5-shadcn/components.json b/examples/shiny-react-upstream/5-shadcn/components.json index 285033d3..67ea69c1 100644 --- a/examples/shiny-react-upstream/5-shadcn/components.json +++ b/examples/shiny-react-upstream/5-shadcn/components.json @@ -5,7 +5,7 @@ "tsx": true, "tailwind": { "config": "", - "css": "src/styles/globals.css", + "css": "srcts/globals.css", "baseColor": "neutral", "cssVariables": true, "prefix": "" diff --git a/examples/shiny-react-upstream/5-shadcn/package.json b/examples/shiny-react-upstream/5-shadcn/package.json index c6c0841f..ff2dc1ee 100644 --- a/examples/shiny-react-upstream/5-shadcn/package.json +++ b/examples/shiny-react-upstream/5-shadcn/package.json @@ -1,8 +1,9 @@ { - "name": "shiny-react-dashboard", + "name": "shiny-react-shadcn", + "private": true, "version": "1.0.0", "type": "module", - "description": "Interactive dashboard example using shiny-react and shadcn/ui", + "description": "shadcn/ui components example using shiny-react", "scripts": { "build": "concurrently -c auto \"tsc --noEmit\" \"tsx build.ts\"", "watch": "concurrently -c auto \"tsc --noEmit --watch --preserveWatchOutput\" \"tsx build.ts --watch\"", diff --git a/examples/shiny-react-upstream/7-chat/py/app.py b/examples/shiny-react-upstream/7-chat/py/app.py index 699c6cee..04aecd72 100644 --- a/examples/shiny-react-upstream/7-chat/py/app.py +++ b/examples/shiny-react-upstream/7-chat/py/app.py @@ -9,7 +9,6 @@ # Load .env file in this directory for OPENAI_API_KEY app_dir = Path(__file__).parent env_file = app_dir / ".env" -print(env_file) dotenv.load_dotenv(env_file) # Initialize chat with OpenAI GPT-4o-mini by default diff --git a/examples/shiny-react-upstream/8-modules/py/app.py b/examples/shiny-react-upstream/8-modules/py/app.py index 977c12a3..18687b67 100644 --- a/examples/shiny-react-upstream/8-modules/py/app.py +++ b/examples/shiny-react-upstream/8-modules/py/app.py @@ -14,11 +14,11 @@ def _(): return 0 @reactive.effect - def _(): + async def _(): """Send notification message every 5 counts""" count = input.count() if count is not None and count > 0 and count % 5 == 0: - shinyreact.post_message( + await shinyreact.post_message( session, "notification", {"message": f"Milestone reached: {count}"}, diff --git a/examples/shiny-react-upstream/8-modules/srcts-standard/main.tsx b/examples/shiny-react-upstream/8-modules/srcts-standard/main.tsx index b3c0287a..96205345 100644 --- a/examples/shiny-react-upstream/8-modules/srcts-standard/main.tsx +++ b/examples/shiny-react-upstream/8-modules/srcts-standard/main.tsx @@ -7,5 +7,5 @@ class CounterWidgetElement extends ShinyReactComponentElement { } if (!customElements.get("counter-widget")) { - customElements.define("counter-widget", CounterWidgetElement); + customElements.define("counter-widget", CounterWidgetElement); } diff --git a/js/src/shiny-react/ImageOutput.tsx b/js/src/shiny-react/ImageOutput.tsx index 9a01cf56..9dfb4d2c 100644 --- a/js/src/shiny-react/ImageOutput.tsx +++ b/js/src/shiny-react/ImageOutput.tsx @@ -72,6 +72,10 @@ export type ImageData = { * dimension change detection (default: 400ms). Controls how long to wait * after a resize event before sending updated dimensions to Shiny. Higher * values reduce server load but may delay updates. + * @param props.namespace - Optional namespace override for Shiny module + * support. If provided, overrides the namespace from ShinyModuleProvider + * context. Pass `null` to explicitly disable namespacing even when inside + * a provider. * @param props.onRecalculating - Optional callback function that gets called * whenever the recalculation status changes. Receives a boolean indicating * whether the image is currently recalculating. diff --git a/js/src/shiny-react/ShinyModuleContext.tsx b/js/src/shiny-react/ShinyModuleContext.tsx index 62ddb383..c21c48a3 100644 --- a/js/src/shiny-react/ShinyModuleContext.tsx +++ b/js/src/shiny-react/ShinyModuleContext.tsx @@ -14,8 +14,9 @@ export interface ShinyModuleProviderProps { * useShinyMessageHandler will automatically have their IDs prefixed * with the provided namespace. * - * Note: This provider does NOT support nesting. If you need nested modules, - * pass the full namespace string (e.g., "outer-inner") directly. + * Note: Nesting providers is supported — an inner provider overrides the + * outer one (it does not concatenate namespaces). If you need a combined + * namespace, pass the full string (e.g., "outer-inner") directly. * * @param namespace The complete namespace string to apply to child hooks. * @param children React children that will receive the namespace context. @@ -48,8 +49,8 @@ export function useShinyModuleNamespace(): string | null { /** * Utility function to apply namespace to an ID. - * If namespace is provided, returns `${namespace}-${id}`. - * Otherwise returns the original id. + * If namespace is a non-empty string, returns `${namespace}-${id}`. + * If namespace is null, undefined, or empty string, returns the original id. */ export function applyNamespace( id: string, From 756ffe62eeb716cf1c9fdc06d6cfd981136599f0 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 18 Mar 2026 16:31:24 -0400 Subject: [PATCH 2/2] Apply suggestion from @schloerke --- examples/shiny-react-upstream/5-shadcn/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/shiny-react-upstream/5-shadcn/package.json b/examples/shiny-react-upstream/5-shadcn/package.json index ff2dc1ee..1df48b4f 100644 --- a/examples/shiny-react-upstream/5-shadcn/package.json +++ b/examples/shiny-react-upstream/5-shadcn/package.json @@ -3,7 +3,7 @@ "private": true, "version": "1.0.0", "type": "module", - "description": "shadcn/ui components example using shiny-react", + "description": "Interactive dashboard example using shiny-react and shadcn/ui", "scripts": { "build": "concurrently -c auto \"tsc --noEmit\" \"tsx build.ts\"", "watch": "concurrently -c auto \"tsc --noEmit --watch --preserveWatchOutput\" \"tsx build.ts --watch\"",