Skip to content

participant_id#177

Closed
BayerC wants to merge 0 commit into
mainfrom
test-participant_id
Closed

participant_id#177
BayerC wants to merge 0 commit into
mainfrom
test-participant_id

Conversation

@BayerC

@BayerC BayerC commented May 28, 2026

Copy link
Copy Markdown
Owner

No description provided.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In SessionState.__init__, unconditionally deleting session_id from st.query_params changes existing behavior and may break deep links or flows that rely on URL-based session IDs; consider keeping support for an incoming session_id or explicitly deciding on and documenting the precedence.
  • The frontend component invokes sendParticipantId both immediately and on Streamlit.RENDER_EVENT, which looks redundant; consider relying on only the render event to avoid duplicate calls and potential race conditions.
  • The participant ID is stored in sessionStorage, which resets per tab/session; if you intend to track users across browser sessions or tabs, consider using localStorage or clarifying the desired persistence semantics.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `SessionState.__init__`, unconditionally deleting `session_id` from `st.query_params` changes existing behavior and may break deep links or flows that rely on URL-based session IDs; consider keeping support for an incoming `session_id` or explicitly deciding on and documenting the precedence.
- The frontend component invokes `sendParticipantId` both immediately and on `Streamlit.RENDER_EVENT`, which looks redundant; consider relying on only the render event to avoid duplicate calls and potential race conditions.
- The participant ID is stored in `sessionStorage`, which resets per tab/session; if you intend to track users across browser sessions or tabs, consider using `localStorage` or clarifying the desired persistence semantics.

## Individual Comments

### Comment 1
<location path="src/open_cups/participant_id/frontend/index.html" line_range="29-31" />
<code_context>
+        Streamlit.setComponentValue(participantId);
+      }
+
+      Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, sendParticipantId);
+      Streamlit.setComponentReady();
+      sendParticipantId();
+    </script>
+  </body>
</code_context>
<issue_to_address>
**suggestion:** Avoid calling sendParticipantId both immediately and on RENDER_EVENT to reduce redundant work.

Because `Streamlit.RENDER_EVENT` will typically fire on initial mount, this setup will likely call `setComponentValue` twice. Consider using only one mechanism (either the event listener or the immediate call, depending on Streamlit’s guarantees) to avoid duplicate updates and possible race conditions.

```suggestion
      Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, sendParticipantId);
      Streamlit.setComponentReady();
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +29 to +31
Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, sendParticipantId);
Streamlit.setComponentReady();
sendParticipantId();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Avoid calling sendParticipantId both immediately and on RENDER_EVENT to reduce redundant work.

Because Streamlit.RENDER_EVENT will typically fire on initial mount, this setup will likely call setComponentValue twice. Consider using only one mechanism (either the event listener or the immediate call, depending on Streamlit’s guarantees) to avoid duplicate updates and possible race conditions.

Suggested change
Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, sendParticipantId);
Streamlit.setComponentReady();
sendParticipantId();
Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, sendParticipantId);
Streamlit.setComponentReady();

@BayerC BayerC closed this May 28, 2026
@BayerC BayerC force-pushed the test-participant_id branch from 4337907 to 19578fb Compare May 28, 2026 20:08
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.

1 participant