Skip to content
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

tricky support for container styles #37

Merged
merged 3 commits into from
Dec 20, 2024
Merged

tricky support for container styles #37

merged 3 commits into from
Dec 20, 2024

Conversation

tiye
Copy link
Member

@tiye tiye commented Dec 10, 2024

mainly for media query and https://developer.mozilla.org/en-US/docs/Web/CSS/@container

Summary by CodeRabbit

  • New Features

    • Introduced a new style macro contained_styles! for enhanced CSS styling.
    • Added a function declare_contained_style for inserting CSS styles with a contained selector.
  • Bug Fixes

    • Updated various dependencies to their latest versions, ensuring improved stability and performance.
  • Documentation

    • Updated dependency specifications in multiple Cargo.toml files across packages.

@tiye tiye requested a review from a team December 10, 2024 19:46
Copy link

coderabbitai bot commented Dec 10, 2024

Walkthrough

The pull request includes updates to multiple Cargo.toml files across various packages, reflecting version increments for several dependencies such as uuid, web-sys, and serde. The demo_respo/src/main.rs file has been modified to enhance styling with the introduction of a new macro and style container. Additionally, the respo/src/node/css.rs file has been expanded with a new function and macros to facilitate the definition of styles with an optional contained selector. The respo_state_derive/Cargo.toml file has also been updated to modify the version of the syn dependency.

Changes

File Path Change Summary
demo_respo/Cargo.toml Updated dependencies: js-sys from 0.3.69 to 0.3.76, uuid from 1.10.0 to 1.11.0, serde from 1.0.210 to 1.0.216, serde_json from 1.0.128 to 1.0.133, web-sys from 0.3.70 to 0.3.76.
demo_respo/src/main.rs Added contained_styles macro and created style_container for media query styling; updated class assignment in view.
respo/Cargo.toml Updated package version from 0.1.14 to 0.1.15 and dependencies: js-sys to 0.3.76, serde to 1.0.216, serde_json to 1.0.133, web-sys to 0.3.76.
respo/src/node/css.rs Added declare_contained_style function and macros contained_style_seq! and contained_styles! for style definition.
respo_state_derive/Cargo.toml Updated syn dependency version from 2.0.77 to 2.0.90.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

Copy link

@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: 6

🧹 Outside diff range comments (1)
respo/Cargo.toml (1)

Line range hint 31-54: Consistent web-sys feature set

The web-sys features list is comprehensive and matches the requirements for DOM manipulation. However, as noted in the demo_respo review, consider adding container query related features.

Consider adding the following web-sys features for container query support:

  • "CssContainerRule"
  • "CssContainerStyleSheet"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 1df6885 and 556bd19.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • demo_respo/Cargo.toml (1 hunks)
  • demo_respo/src/main.rs (3 hunks)
  • respo/Cargo.toml (3 hunks)
  • respo/src/node/css.rs (2 hunks)
  • respo_state_derive/Cargo.toml (1 hunks)
🔇 Additional comments (4)
respo_state_derive/Cargo.toml (1)

Line range hint 14-19: Verify syn upgrade compatibility

The update from syn 2.0.77 to 2.0.90 is a minor version bump. While this should be backward compatible, it's good practice to verify the changelog for any potential breaking changes in proc-macro behavior.

✅ Verification successful

Syn upgrade is safe to proceed

The proc macro implementation uses only basic syn functionality (parsing and accessing identifiers) that has been stable across 2.0.x versions. The implementation is straightforward and doesn't rely on any advanced syn features that might be affected by version changes:

  • Only uses syn::parse() for basic TokenStream parsing
  • Only accesses the ident field of DeriveInput
  • No custom parsers or complex syn API usage
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check syn changelog for breaking changes between 2.0.77 and 2.0.90

# Fetch the changelog from syn repository
gh api repos/dtolnay/syn/contents/CHANGELOG.md | jq -r '.content' | base64 -d | grep -A 10 "2.0.90\|2.0.77"

Length of output: 229


Script:

#!/bin/bash
# Let's verify if there are any changes in the codebase that might be affected by the syn upgrade
# Look for any proc macro implementations that might be sensitive to syn changes

# Search for proc macro attribute usage
ast-grep --pattern 'proc_macro'

# Also check for any direct syn API usage
rg "syn::" -A 2

Length of output: 512


Script:

#!/bin/bash
# Let's examine the actual proc macro implementation to understand syn usage
cat respo_state_derive/src/lib.rs

Length of output: 1149

demo_respo/Cargo.toml (2)

20-21: Verify uuid compatibility

The uuid update from 1.10.0 to 1.11.0 appears safe as it maintains the same feature set ("v4", "js").


Line range hint 26-45: Verify web-sys features for container queries

The web-sys update to 0.3.76 aligns with the PR's container styles objective. However, we should verify if additional features are needed for CSS container query support.

Consider adding the following web-sys features if you plan to use container queries:

  • "CssContainerRule"
  • "CssContainerStyleSheet"
respo/Cargo.toml (1)

3-3: Version bump aligns with feature addition

The increment to version 0.1.15 is appropriate for adding container styles support.

respo/Cargo.toml Outdated Show resolved Hide resolved
demo_respo/src/main.rs Show resolved Hide resolved
demo_respo/src/main.rs Show resolved Hide resolved
respo/src/node/css.rs Outdated Show resolved Hide resolved
respo/src/node/css.rs Show resolved Hide resolved
Copy link

@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: 2

🧹 Outside diff range comments (1)
respo/src/node/css.rs (1)

Container queries implementation needs runtime checks and documentation

The implementation currently lacks browser compatibility checks and documentation for container query support. Based on the codebase analysis:

  1. No runtime checks exist to detect browser support for container queries
  2. No fallback mechanisms are implemented for unsupported browsers
  3. Documentation doesn't mention browser compatibility requirements

To address this:

  • Add runtime detection using window.CSS.supports('@container') before applying container styles
  • Implement graceful fallbacks when container queries aren't supported
  • Document browser requirements in the module's documentation

Example implementation to add:

// Before applying container styles, check:
if window.CSS.supports("@container") {
    // Apply container styles
} else {
    // Apply fallback styles
}
🔗 Analysis chain

Line range hint 739-931: Verify browser compatibility for container queries.

Container queries are a relatively new CSS feature. Consider:

  1. Adding browser compatibility checks
  2. Implementing fallback styles for unsupported browsers
  3. Documenting browser support requirements

Run the following script to check browser support:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check MDN data for container query browser support
curl -s "https://raw.githubusercontent.com/mdn/browser-compat-data/main/css/at-rules/container.json" | \
jq '.css.at-rules.container.support_data'

Length of output: 265


Script:

#!/bin/bash
# Let's check if there are any browser compatibility checks or fallbacks in the codebase
rg -U "(?s)browser.*support|fallback|compat" --type rust

# Also check if there's any documentation about browser requirements
fd README -e md -X cat {}

# Look for any error handling around container queries
ast-grep --pattern 'container' 

Length of output: 11995

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 556bd19 and 003cf26.

📒 Files selected for processing (2)
  • demo_respo/Cargo.toml (1 hunks)
  • respo/src/node/css.rs (2 hunks)
🔇 Additional comments (4)
demo_respo/Cargo.toml (3)

17-17: LGTM! Versions of js-sys and web-sys are properly synchronized.

The update maintains version synchronization between js-sys and web-sys (both at 0.3.76), which is important for compatibility.

Also applies to: 26-26


17-17: Verify security implications of dependency updates.

Let's verify if the updated versions address any known vulnerabilities.

Also applies to: 20-20, 21-21, 22-22, 26-26

✅ Verification successful

No security vulnerabilities found in the updated dependencies

The GitHub Security Advisory Database shows no known vulnerabilities for any of the updated Rust dependencies (js-sys, uuid, serde, serde_json, web-sys). The dependency updates appear to be security-safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for security advisories for the updated dependencies

# Check for security advisories using GitHub API
for pkg in "js-sys" "uuid" "serde" "serde_json" "web-sys"; do
  echo "Checking $pkg..."
  gh api graphql -f query="
  {
    securityVulnerabilities(first: 5, ecosystem: RUST, package: \"$pkg\") {
      nodes {
        advisory {
          summary
          severity
          publishedAt
        }
        vulnerableVersionRange
        firstPatchedVersion {
          identifier
        }
      }
    }
  }"
done

Length of output: 2391


Line range hint 28-47: Consider adding CSS Container Query related features.

Given the PR's objective to support container styles and CSS @container rules, you might need to add features like "CssContainerRule" to the web-sys features list if they are available.

respo/src/node/css.rs (1)

744-787: 🛠️ Refactor suggestion

Enhance error handling and performance.

The function has several areas for improvement:

  1. Replace .expect() calls with proper error handling
  2. Use a string builder for better performance
  3. Add container query syntax validation
  4. Consider cleanup of old style tags

Consider this improved implementation:

-pub fn declare_contained_style<T, U>(name: T, rules: &[(Option<String>, U, RespoStyle)]) -> String
+pub fn declare_contained_style<T, U>(name: T, rules: &[(Option<String>, U, RespoStyle)]) -> Result<String, Box<dyn std::error::Error>>
 where
   T: Into<String> + Clone,
   U: Into<String> + Clone + Display,
 {
-  let mut defined_styles = CLASS_NAME_IN_TAGS.write().expect("access styles");
+  let mut defined_styles = CLASS_NAME_IN_TAGS.write().map_err(|e| format!("Failed to access styles: {}", e))?;
   if defined_styles.contains(&name.to_owned().into()) {
-    name.into()
+    Ok(name.into())
   } else {
-    let window = web_sys::window().expect("window");
-    let document = window.document().expect("load document");
+    let window = web_sys::window().ok_or("Failed to get window")?;
+    let document = window.document().ok_or("Failed to load document")?;
     // ... similar changes for other expect calls
     
-    let mut styles = String::from("");
+    let mut styles = String::with_capacity(rules.len() * 100); // Pre-allocate space
     
     for (contained, query, properties) in rules {
+      if let Some(ref container) = contained {
+        // Validate container query syntax
+        if !container.starts_with("@container") {
+          return Err("Invalid container query syntax".into());
+        }
+      }
       // ... rest of the implementation
     }
     
-    name.into()
+    Ok(name.into())
   }
 }

Likely invalid or redundant comment.

respo/src/node/css.rs Outdated Show resolved Hide resolved
respo/src/node/css.rs Outdated Show resolved Hide resolved
Copy link

@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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🛑 Comments failed to post (1)
respo/src/node/css.rs (1)

842-888: 🧹 Nitpick (assertive)

Enhance documentation with browser compatibility notes

The macros are well-implemented with good examples, but consider adding browser compatibility information for container queries, as they are a relatively new CSS feature.

Add a note in the documentation:

 /// macro to create a public function of CSS rules with a slice at current file scope,
+/// Note: Container queries are supported in modern browsers (Chrome 105+, Firefox 110+, Safari 16+).
+/// For compatibility information, see: https://caniuse.com/css-container-queries
 /// ```rust
 /// respo::contained_style_seq!(the_name,

Copy link

@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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e323297 and 869fef3.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • demo_respo/Cargo.toml (1 hunks)
  • respo/Cargo.toml (3 hunks)
  • respo/src/node/css.rs (2 hunks)
🔇 Additional comments (4)
respo/src/node/css.rs (2)

837-840: LGTM! Clean macro implementation.

The macro update properly handles trailing commas and maintains a clean delegation to static_style_seq.


744-787: 🛠️ Refactor suggestion

Consider improving error handling and performance.

The function has several areas that could be enhanced:

  1. Error handling uses .expect() which can panic. Consider using proper error propagation.
  2. String concatenation in a loop could be inefficient for large style sets.
  3. Multiple DOM manipulations could be optimized.

Consider this refactoring:

-pub fn declare_contained_style<T, U>(name: T, rules: &[(Option<String>, U, RespoStyle)]) -> String
+pub fn declare_contained_style<T, U>(name: T, rules: &[(Option<String>, U, RespoStyle)]) -> Result<String, Box<dyn std::error::Error>>
 where
   T: Into<String> + Clone,
   U: Into<String> + Clone + Display,
 {
-  let mut defined_styles = CLASS_NAME_IN_TAGS.write().expect("access styles");
+  let mut defined_styles = CLASS_NAME_IN_TAGS.write().map_err(|e| format!("Failed to access styles: {}", e))?;
   if defined_styles.contains(&name.to_owned().into()) {
-    name.into()
+    Ok(name.into())
   } else {
-    let window = web_sys::window().expect("window");
-    let document = window.document().expect("load document");
+    let window = web_sys::window().ok_or("Failed to get window")?;
+    let document = window.document().ok_or("Failed to load document")?;
     // ... similar changes for other expect calls
     
-    let mut styles = String::from("");
+    let mut styles = String::with_capacity(rules.len() * 100); // Pre-allocate capacity

Likely invalid or redundant comment.

demo_respo/Cargo.toml (1)

17-17: LGTM! Dependency versions are now consistent across workspace

The dependency versions have been properly aligned with the main respo crate:

  • js-sys 0.3.76
  • serde 1.0.216
  • serde_json 1.0.133
  • web-sys 0.3.76

Let's verify the compatibility of these dependencies:

Also applies to: 20-22, 26-26

✅ Verification successful

Dependencies are properly aligned and compatible across workspace

Based on the Cargo.lock and dependency search results:

  • All dependency versions are consistent between demo_respo and respo crates
  • No dependency conflicts or resolution issues in Cargo.lock
  • Dependencies form a compatible set with wasm-bindgen 0.2.99
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify dependency compatibility and check for any reported issues

# Check for any compatibility issues or breaking changes in recent versions
gh api graphql -f query='
{
  repository(owner: "rustwasm", name: "wasm-bindgen") {
    releases(first: 5, orderBy: {field: CREATED_AT, direction: DESC}) {
      nodes {
        tagName
        description
      }
    }
  }
}'

# Check if there are any reported issues with these specific versions
rg -l "serde.*1\.0\.216|serde_json.*1\.0\.133|js-sys.*0\.3\.76" --type md

Length of output: 542


Script:

#!/bin/bash
# Let's verify the dependency compatibility in a different way

# Check Cargo.lock for any dependency conflicts
fd Cargo.lock --type f --exec cat {}

# Check if these versions are used consistently across workspace
rg "js-sys.*0\.3\." --type toml
rg "web-sys.*0\.3\." --type toml
rg "serde.*1\.0\." --type toml
rg "serde_json.*1\.0\." --type toml

Length of output: 10493

respo/Cargo.toml (1)

3-3: Version bump aligns with the new container styles feature

The increment from 0.1.14 to 0.1.15 is appropriate for adding container styles support.

respo/src/node/css.rs Show resolved Hide resolved
respo/src/node/css.rs Show resolved Hide resolved
respo/Cargo.toml Show resolved Hide resolved
@NoEgAm NoEgAm merged commit 8cf9d8f into main Dec 20, 2024
2 checks passed
@NoEgAm NoEgAm deleted the contained branch December 20, 2024 12:11
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.

2 participants