Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 4, 2025

This PR implements a React-based version of the existing js/Ice/greeter demo as requested in the issue.

What's Added

  • New js/Ice/greeter-react/ directory with a complete React application
  • Modern React setup using Vite, TypeScript, and React 18
  • Web UI with an input field (defaulting to "React"), button, and response display area
  • Ice integration using the @zeroc/ice package from the ZeroC nightly NPM feed
  • Proper error handling and loading states for user feedback
  • Comprehensive documentation in README.md with setup and usage instructions

Key Features

The React application provides:

  • Input field to enter a name with "React" as the default value
  • Button to send greet requests to the Ice server
  • Real-time display of server responses in the UI
  • Error handling for connection issues
  • Loading indicators during requests
  • Clean, responsive design with proper styling

Technical Implementation

  • Uses the same Greeter.ice Slice definition as the original demo
  • Properly manages Ice communicator lifecycle (create → use → destroy)
  • Includes browser polyfills for Node.js modules required by Ice
  • Modern build system with Vite for development and production builds
  • TypeScript support throughout the application

Usage

  1. Install dependencies: npm install
  2. Build the application: npm run build
  3. Start development server: npm run dev
  4. Open browser to the provided URL (typically http://localhost:5173)

The application expects a Greeter server to be running on localhost:4061 (same as the original demo).

Documentation Updates

Updated js/README.md to include the new React demo in the demos table.

Fixes #513.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Create React Version of the js/Ice/Greeter Demo Create React Version of the js/Ice/Greeter Demo Jun 4, 2025
Copilot AI requested a review from bernardnormier June 4, 2025 14:08
Copilot finished work on behalf of bernardnormier June 4, 2025 14:08
Copy link
Member

@bernardnormier bernardnormier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review and fix @pepone comments.

Copy link
Contributor Author

Copilot AI commented Jun 4, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of bernardnormier June 4, 2025 14:32
@bernardnormier
Copy link
Member

Make sure every file added by this PR ends with a newline character.

Copy link
Contributor Author

Copilot AI commented Jun 4, 2025

Make sure every file added by this PR ends with a newline character.

Added missing newlines to all files in the greeter-react demo in commit 5d79ec3.

Copilot finished work on behalf of bernardnormier June 4, 2025 14:52
@pepone pepone requested review from Copilot and externl June 5, 2025 14:14

This comment was marked as outdated.

@pepone pepone marked this pull request as ready for review June 6, 2025 09:54
@pepone pepone requested a review from bernardnormier June 6, 2025 10:06
Copy link
Member

@externl externl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • state message boxes have too much bottom padding.
  • entering no name after getting a successful response doesn't dismiss the previous server response

- Navigate to the demo directory:

```shell
cd js/Ice/greeter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dir is incorrect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, renamed to react-greeter for consistency with android-greeter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directory path js/Ice/react-greeter is correct - the demo was renamed from greeter-react to react-greeter in recent commits.

@pepone
Copy link
Member

pepone commented Jun 10, 2025

state message boxes have too much bottom padding.

Cleanup the css

entering no name after getting a successful response doesn't dismiss the previous server response

Updated the demo to use a StatusMessage which better handle this to only allow one state, loading, greeting, or error.

@pepone pepone requested review from Copilot, externl and pepone and removed request for pepone June 10, 2025 20:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements a new React-based version of the Ice Greeter demo, integrating modern frameworks and tooling (Vite, TypeScript, React 18) with Ice for communication.

  • Introduces a new directory for the React demo with full integration of Ice including proper error handling and loading states.
  • Adds updated documentation and configuration files to support a modern build system and browser environment.
  • Updates the main README to include the new React demo alongside existing demos.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
js/README.md Updated demos table to include the new Ice React Greeter demo.
js/Ice/react-greeter/vite.config.ts New Vite configuration for the React application.
js/Ice/react-greeter/tsconfig.json New TypeScript configuration tailored for a Vite and React environment.
js/Ice/react-greeter/src/* Entire React application including main entry points, styling, and status messaging.
js/Ice/react-greeter/Greeter.ice Greeter Slice definition for the React demo.
js/Ice/react-greeter/package.json Dependency and script definitions for the React demo.
js/Ice/react-greeter/index.html HTML entry point for the React application.
js/Ice/react-greeter/README.md Documentation updated to guide development and usage of the React demo.
js/Ice/react-greeter/.npmrc NPM registry configuration for ZeroC packages.
js/Ice/react-greeter/.gitignore Git ignore configuration for generated and build files.
js/Ice/greeter/README.md Minor documentation updates in the existing Greeter demo.
Comments suppressed due to low confidence (1)

js/Ice/react-greeter/src/App.tsx:35

  • Double-check that instantiating the Greeter proxy using 'new' is consistent with the expected API for the @zeroc/ice package, as factory methods are sometimes preferred.
const greeter = new VisitorCenter.GreeterPrx(communicator, "greeter:ws -h localhost -p 4061");

}));
}

return () => {
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider explicitly handling the promise returned by the asynchronous cleanup function within the useEffect cleanup to ensure that any potential errors during communicator destruction are properly managed.

Copilot uses AI. Check for mistakes.
@pepone pepone removed their request for review June 10, 2025 20:23
Copy link
Contributor Author

Copilot AI commented Jun 10, 2025

  • state message boxes have too much bottom padding.
  • entering no name after getting a successful response doesn't dismiss the previous server response

Fixed both issues in commit 55a6a54:

  • Reduced padding for state message boxes from 1rem to 0.75rem 1rem
  • Now clears previous server response when entering empty name

Copilot finished work on behalf of pepone June 10, 2025 20:32
Comment on lines 46 to 56
const cleanup = async () => {
try {
if (communicatorRef.current) {
await communicatorRef.current.destroy();
}
} catch (err) {
console.warn("Failed to destroy communicator:", err);
}
};
// Kick off the async cleanup, but don't return the promise
cleanup();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this extra step necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check, it is definitely ugly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback returned by useEffect must be not async

src/App.tsx:27:15 - error TS2345: Argument of type '() => () => Promise<void>' is not assignable to parameter of type 'EffectCallback'.
  Type '() => Promise<void>' is not assignable to type 'void | Destructor'.
    Type '() => Promise<void>' is not assignable to type 'Destructor'.
      Type 'Promise<void>' is not assignable to type 'void | { [UNDEFINED_VOID_ONLY]: never; }'.

27     useEffect(() => {            ~~~~~~~

If we call destroy directly and not await it we can end up with an unhalted promise rejection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another alternative is:

return () => {
            const communicator = communicatorRef.current;
            communicatorRef.current = null;
            // Clean up the communicator when the component unmounts
            if (communicator) {
                communicator.destroy().catch((err) => {
                    console.error("Error destroying Ice communicator:", err);
                });
            }
        };

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either one is fine with me.

@@ -0,0 +1,124 @@
import React, { useState, useCallback, useEffect, useRef } from "react";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright


import StatusMessage from "./StatusMessage";

interface AppState {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too few comments

@@ -0,0 +1,29 @@
import React from "react";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs copyright and comments

@bernardnormier bernardnormier removed their assignment Jun 12, 2025
@pepone pepone merged commit 94fb689 into main Jun 12, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create React Version of the js/Ice/Greeter Demo

5 participants