participant_id#177
Closed
BayerC wants to merge 0 commit into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
SessionState.__init__, unconditionally deletingsession_idfromst.query_paramschanges existing behavior and may break deep links or flows that rely on URL-based session IDs; consider keeping support for an incomingsession_idor explicitly deciding on and documenting the precedence. - The frontend component invokes
sendParticipantIdboth immediately and onStreamlit.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 usinglocalStorageor 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>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(); |
Contributor
There was a problem hiding this comment.
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(); |
4337907 to
19578fb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.