Skip to content

fix(convertUtilitiesToV4): drop js-regexp-lookbehind for improved browser support #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

SutuSebastian
Copy link
Collaborator

@SutuSebastian SutuSebastian commented Apr 2, 2025

Issue

#1554

Summary by CodeRabbit

  • Chores

    • Improved browser compatibility by updating processing methods for smoother operation.
  • Documentation

    • Streamlined metadata in documentation to focus content indexing.
  • Refactor

    • Enhanced styling conversion processes to ensure consistent and reliable transformations in visual presentation.

@SutuSebastian SutuSebastian added 🐛 bug Something isn't working confirmed This bug was confirmed labels Apr 2, 2025
@SutuSebastian SutuSebastian requested a review from rluders April 2, 2025 07:51
@SutuSebastian SutuSebastian self-assigned this Apr 2, 2025
Copy link

changeset-bot bot commented Apr 2, 2025

🦋 Changeset detected

Latest commit: 27bcf1f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
flowbite-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 2, 2025 7:52am
flowbite-react-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 2, 2025 7:52am

Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request introduces updates in several parts of the project. A new changeset entry documents a patch for the "flowbite-react" package by removing the js-regexp-lookbehind feature and simplifying its regex for improved browser support. The source code in the convertUtilitiesToV4 function has been refactored to process Tailwind CSS classes in a more granular way, including preserving modifiers during conversion. Additionally, metadata keywords have been removed from the AI integration documentation.

Changes

File(s) Change Summary
.changeset/open-toys-sniff.md
packages/ui/src/helpers/convert-utilities-to-v4.ts
Removed the js-regexp-lookbehind feature and replaced it with a simpler regex to improve browser support. Refactored convertUtilitiesToV4 to split class names by whitespace, process modifiers accurately, and updated regex patterns from word boundaries to exact matches.
apps/web/content/docs/getting-started/ai-integration.mdx Removed the keywords field from the metadata section, reducing the document’s associated keywords.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Converter as convertUtilitiesToV4
    participant RegexMapper as Regex Matching

    Caller->>Converter: Pass input string (class names)
    Converter->>Converter: Split input by whitespace
    loop Process each part
        Converter->>Converter: Check if part is non-whitespace
        Converter->>RegexMapper: Apply regex matching for modifiers & base classes
        RegexMapper-->>Converter: Return match (if any)
        Converter->>Converter: Replace text based on regexMap
    end
    Converter-->>Caller: Return the converted class string
Loading

Poem

I’m a rabbit leaping through the code at dawn,
Hopping past lookbehinds and regex magic drawn.
Each class split with care, each modifier kept tight,
Keywords vanish quietly into the digital night.
With every patch and tweak, I celebrate the byte!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/ui/src/helpers/convert-utilities-to-v4.ts

Oops! Something went wrong! :(

ESLint: 8.57.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/packages/ui".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "packages/ui/.eslintrc.cjs".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@SutuSebastian SutuSebastian changed the title 1554 safari until 164 syntaxerror invalid regular expression invalid group specifier name Safari until 16.4 | SyntaxError: Invalid regular expression: invalid group specifier name Apr 2, 2025
@SutuSebastian SutuSebastian changed the title Safari until 16.4 | SyntaxError: Invalid regular expression: invalid group specifier name fix(convertUtilitiesToV4): drop js-regexp-lookbehind for improved browser support Apr 2, 2025
@SutuSebastian SutuSebastian changed the title fix(convertUtilitiesToV4): drop js-regexp-lookbehind for improved browser support fix(convertUtilitiesToV4): drop js-regexp-lookbehind for improved browser support Apr 2, 2025
@SutuSebastian SutuSebastian merged commit 2f461ea into main Apr 2, 2025
8 checks passed
@SutuSebastian SutuSebastian deleted the 1554-safari-until-164-syntaxerror-invalid-regular-expression-invalid-group-specifier-name branch April 2, 2025 07:55
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/ui/src/helpers/convert-utilities-to-v4.ts (2)

28-29: Minor redundancy in variable naming.
const processed = part; doesn’t add additional context over part. You can use part directly in the subsequent call to match(...) for improved clarity.

-      const processed = part;
-      const modifierMatch = processed.match(/^([^:]+:)?(.+)$/);
+      const modifierMatch = part.match(/^([^:]+:)?(.+)$/);

65-75: Confirm updated mappings and revisit the commented-out outline rule.
The revised regex patterns look consistent for converting v3 to v4 utility classes. However, the commented line for outline-none remains unresolved. Ensure that future updates address keyboard accessibility and tab focus properly before reintroduction.

Would you like help drafting a solution that maintains keyboard accessibility while adjusting outline behavior?

.changeset/open-toys-sniff.md (1)

5-5: Fix comparative form for proper grammar.
Use "simpler" or "more simple," not "more simpler."

- refactor(ui~convertUtilitiesToV4): drop `js-regexp-lookbehind` in favor of more simpler regex for improved browser support
+ refactor(ui~convertUtilitiesToV4): drop `js-regexp-lookbehind` in favor of simpler regex for improved browser support
🧰 Tools
🪛 LanguageTool

[grammar] ~5-~5: Use only “simpler” (without ‘more’) when you use the comparative.
Context: ...drop js-regexp-lookbehind in favor of more simpler regex for improved browser support

(MOST_COMPARATIVE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6753c4 and 27bcf1f.

📒 Files selected for processing (3)
  • .changeset/open-toys-sniff.md (1 hunks)
  • apps/web/content/docs/getting-started/ai-integration.mdx (0 hunks)
  • packages/ui/src/helpers/convert-utilities-to-v4.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/content/docs/getting-started/ai-integration.mdx
🧰 Additional context used
🪛 LanguageTool
.changeset/open-toys-sniff.md

[grammar] ~5-~5: Use only “simpler” (without ‘more’) when you use the comparative.
Context: ...drop js-regexp-lookbehind in favor of more simpler regex for improved browser support

(MOST_COMPARATIVE)

🔇 Additional comments (1)
packages/ui/src/helpers/convert-utilities-to-v4.ts (1)

21-22: Use of whitespace capture to preserve spacing looks good.
Splitting the class string into an array while capturing the whitespace ensures that any spacing or separation between class names is accurately preserved, which avoids unintended concatenation of classes.

Comment on lines +29 to +31
const modifierMatch = processed.match(/^([^:]+:)?(.+)$/);

if (modifierMatch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Potential issue with multiple colons in modifiers.
The regex ^([^:]+:)?(.+)$ captures only one optional colon-delimited prefix. This may fail to handle scenarios like hover:focus:bg-red-500. If supporting multiple modifiers is intended, consider updating the capture group to handle multiple colons.


🏁 Script executed:

#!/bin/bash
# Description: Search codebase for possible usage of multiple-colon class names 
# to confirm if multiple modifiers are used.

rg -A 3 "hover:.*:.*" 

Length of output: 72460


Attention: Update Regex to Support Compound Modifiers

The current regex in packages/ui/src/helpers/convert-utilities-to-v4.ts (lines 29–31):

- const modifierMatch = processed.match(/^([^:]+:)?(.+)$/);
+ const modifierMatch = processed.match(/^((?:[^:]+:)+)?(.+)$/);

only allows for one optional modifier prefix. However, our codebase and tests demonstrate compound modifier patterns (e.g. hover:focus:bg-red-500, dark:hover:!text-lg). This means that when multiple modifiers are used, only the first (e.g. "hover:") is captured, leaving the rest in the second group—which can lead to incorrect processing or conversion.

Recommendation:

  • Update the regex as shown above so that the optional group can match one or more colon-delimited prefixes.
  • Verify that the rest of the conversion logic correctly handles the split between modifiers and the utility.

Please address this to ensure consistency when multiple modifiers are present.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const modifierMatch = processed.match(/^([^:]+:)?(.+)$/);
if (modifierMatch) {
const modifierMatch = processed.match(/^((?:[^:]+:)+)?(.+)$/);
if (modifierMatch) {

@github-actions github-actions bot mentioned this pull request Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working confirmed This bug was confirmed
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Safari until 16.4 | SyntaxError: Invalid regular expression: invalid group specifier name
1 participant