Skip to content

Fix crypto.randomUUID is not a function#995

Open
apedley wants to merge 1 commit intoCodeWithCJ:mainfrom
apedley:fix-bcrypt-workout-plan
Open

Fix crypto.randomUUID is not a function#995
apedley wants to merge 1 commit intoCodeWithCJ:mainfrom
apedley:fix-bcrypt-workout-plan

Conversation

@apedley
Copy link
Contributor

@apedley apedley commented Mar 25, 2026

Tip

Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run pnpm run validate to check for any errors.
PRs that include tests and clear screenshots are highly preferred!

Description

Fix crypto.randomUUID is not a function error that occurs when accessing the web client without HTTPS. Note that localhost is not affected so this slipped by the dev team.

Related Issue

PR type [x] Issue [ ] New Feature [ ] Documentation
Linked Issue: #992

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where the application failed to generate client-side IDs in non-HTTPS environments due to the unavailability of crypto.randomUUID. By introducing a new generateClientId utility, the application now gracefully handles various browser contexts, ensuring that unique IDs are consistently generated using the most secure method available, or falling back to alternative strategies when necessary. This change enhances the application's robustness and user experience, particularly for those accessing it without HTTPS.

Highlights

  • Robust Client ID Generation: Replaced direct calls to crypto.randomUUID with a new utility function, generateClientId, to ensure stable ID generation across all environments.
  • Fallback Mechanism: The new generateClientId utility includes fallbacks for environments where crypto.randomUUID is unavailable (e.g., non-HTTPS contexts), first attempting crypto.getRandomValues and then a temporary ID.
  • Improved Test Coverage: Added dedicated unit tests for the generateClientId utility to verify its behavior and fallback logic under different crypto API availability scenarios.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new generateClientId utility function to provide a robust method for generating unique client-side IDs. This utility includes fallbacks for crypto.randomUUID(), crypto.getRandomValues(), and a temporary ID generation if the crypto API is entirely unavailable. The new utility is integrated into the AddWorkoutPlanDialog and WorkoutPresetForm components, replacing direct calls to crypto.randomUUID(). Additionally, comprehensive unit tests for generateClientId have been added. The only feedback provided suggests improving the conciseness of the generateClientId function by directly modifying bytes[6] and bytes[8] instead of using intermediate variables and nullish coalescing, as Uint8Array elements are guaranteed to be numbers.

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