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

feat: new preload strategy swap-low #72

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SukkaW
Copy link

@SukkaW SukkaW commented Dec 17, 2024

swap-low uses rel="alternate stylesheet" (instead of rel="alternate stylesheet preload" used by swap-high) to ensure the lowest priority.

See https://filamentgroup.github.io/loadCSS/test/new-low.html


This was originally implemented in GoogleChromeLabs/critters#101, but Google Chrome Teams simply ignored my PR for three years (Just a typical tradition of how Google Chrome Teams treats open-source contributions as always) and simply closed it as they archive the repo.

Description by Callstackai

This PR introduces a new preload strategy called swap-low, which uses rel="alternate stylesheet" to ensure the lowest priority for stylesheets. It updates the README, TypeScript definitions, and implementation in the Beasties class.

Diagrams of code changes
sequenceDiagram
    participant Browser
    participant Link as Link Element
    participant CSS as Stylesheet

    Browser->>Link: Create link element
    Link->>Link: Set rel="alternate stylesheet"
    Link->>Link: Set title="styles"
    Link->>CSS: Begin loading stylesheet
    CSS-->>Link: Stylesheet loaded
    Link->>Link: onload: Clear title
    Link->>Link: onload: Set rel="stylesheet"
    Note over Browser,CSS: Lowest priority loading<br/>compared to swap/swap-high
Loading
Files Changed
FileSummary
packages/beasties/README.mdAdded documentation for the new swap-low preload strategy.
packages/beasties/src/index.d.tsUpdated TypeScript definitions to include swap-low in the preload options.
packages/beasties/src/index.tsImplemented the logic for the new swap-low preload strategy in the Beasties class.
packages/beasties/src/types.tsUpdated type definitions to include swap-low in the PreloadStrategy type.

This PR includes files in programming languages that we currently do not support. We have not reviewed files with the extensions .md, .ts. See list of supported languages.

Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request introduces a new preload strategy "swap-low" to the Beasties package. This addition allows for the conversion of stylesheet links to an alternate stylesheet without the preload attribute, ensuring it has the lowest priority compared to other strategies. The change is implemented across multiple files, including the README, type definitions, and implementation, providing a comprehensive update to the package's configuration options for stylesheet preloading.

Changes

File Change Summary
packages/beasties/README.md Added documentation for new "swap-low" preload strategy and updated type definition for PreloadStrategy
packages/beasties/src/types.ts Updated PreloadStrategy type to include "swap-low" option
packages/beasties/src/index.d.ts Extended Options interface to support "swap-low" preload strategy
packages/beasties/src/index.ts Implemented conditional logic for "swap-low" preload mode in embedLinkedStylesheet method

Sequence Diagram

sequenceDiagram
    participant User
    participant Beasties
    participant StylesheetLink

    User->>Beasties: Configure with "swap-low" strategy
    Beasties->>StylesheetLink: Create link with rel="alternate stylesheet"
    StylesheetLink-->>Beasties: Link created
    Beasties->>StylesheetLink: On load, change rel to "stylesheet"
Loading

The sequence diagram illustrates the new "swap-low" preload strategy, showing how the stylesheet link is initially created with low priority and then activated upon loading.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e887b64 and ab0e8d1.

📒 Files selected for processing (2)
  • packages/beasties/README.md (1 hunks)
  • packages/beasties/src/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/beasties/src/types.ts
  • packages/beasties/README.md

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. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
packages/beasties/src/types.ts (1)

13-13: Fix grammar in documentation.

Change "compare to" to "compared to" for correct English usage.

- * - **"swap-low":** Use `<link rel="alternate stylesheet">` (no `preload` in `rel` here!) and swap to `rel="stylesheet"` once loaded ([details](http://filamentgroup.github.io/loadCSS/test/new-low.html)). It ensures lowest priority compare to `swap-high`. <kbd>JS</kbd>
+ * - **"swap-low":** Use `<link rel="alternate stylesheet">` (no `preload` in `rel` here!) and swap to `rel="stylesheet"` once loaded ([details](http://filamentgroup.github.io/loadCSS/test/new-low.html)). It ensures lowest priority compared to `swap-high`. <kbd>JS</kbd>
packages/beasties/README.md (1)

243-243: Fix grammar in documentation.

Change "compare to" to "compared to" for correct English usage.

- - **"swap-low":** Use `<link rel="alternate stylesheet">` (no `preload` in `rel` here!) and swap to `rel="stylesheet"` once loaded ([details](http://filamentgroup.github.io/loadCSS/test/new-low.html)). It ensures lowest priority compare to `swap-high`. <kbd>JS</kbd>
+ - **"swap-low":** Use `<link rel="alternate stylesheet">` (no `preload` in `rel` here!) and swap to `rel="stylesheet"` once loaded ([details](http://filamentgroup.github.io/loadCSS/test/new-low.html)). It ensures lowest priority compared to `swap-high`. <kbd>JS</kbd>
🧰 Tools
🪛 LanguageTool

[uncategorized] ~243-~243: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...-low.html)). It ensures lowest priority compare to swap-high. JS - **"js":...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 30a442c and e887b64.

📒 Files selected for processing (4)
  • packages/beasties/README.md (1 hunks)
  • packages/beasties/src/index.d.ts (1 hunks)
  • packages/beasties/src/index.ts (1 hunks)
  • packages/beasties/src/types.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/beasties/README.md

[uncategorized] ~243-~243: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...-low.html)). It ensures lowest priority compare to swap-high. JS - **"js":...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

🔇 Additional comments (4)
packages/beasties/src/types.ts (1)

18-18: LGTM! Type definition updated correctly.

The new swap-low strategy has been properly added to the PreloadStrategy type.

packages/beasties/src/index.d.ts (1)

50-50: LGTM! Options interface updated correctly.

The swap-low strategy has been properly added to the preload option in the Options interface, maintaining consistency with the PreloadStrategy type.

packages/beasties/README.md (1)

243-248: LGTM! Documentation updated comprehensively.

The new swap-low strategy is well-documented with clear explanation of its purpose, behaviour, and implementation details. The type definition example is also correctly updated.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~243-~243: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...-low.html)). It ensures lowest priority compare to swap-high. JS - **"js":...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

packages/beasties/src/index.ts (1)

313-319: Implementation looks good and matches the reference!

The new preload strategy swap-low is correctly implemented, following the same pattern as other strategies. The implementation properly sets the rel="alternate stylesheet" attribute to ensure lowest priority loading, which aligns with the reference implementation from Filament Group's test page.

Let's verify the implementation against the reference:

✅ Verification successful

Implementation matches the reference implementation perfectly

The verification confirms that our implementation exactly mirrors the reference implementation from Filament Group's test page:

  • Both set rel="alternate stylesheet"
  • Both use title="styles"
  • Both use the same onload handler to clear the title and switch to rel="stylesheet"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare our implementation with the reference test page
# Expected: Our implementation should match the reference implementation

# Fetch the reference implementation
curl -s https://filamentgroup.github.io/loadCSS/test/new-low.html | rg -A 5 'rel="alternate stylesheet"'

# Check our implementation
rg -A 5 'preloadMode === .swap-low.' packages/beasties/src/index.ts

Length of output: 1228

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.

Project coverage is 83.62%. Comparing base (30a442c) to head (ab0e8d1).

Files with missing lines Patch % Lines
packages/beasties/src/index.ts 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #72      +/-   ##
==========================================
- Coverage   83.95%   83.62%   -0.34%     
==========================================
  Files           7        7              
  Lines        1203     1209       +6     
  Branches      281      282       +1     
==========================================
+ Hits         1010     1011       +1     
- Misses        193      198       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Dec 25, 2024

CodSpeed Performance Report

Merging #72 will not alter performance

Comparing SukkaW:swap-low (ab0e8d1) with main (30a442c)

Summary

✅ 9 untouched benchmarks

@danielroe
Copy link
Owner

i love it! i wonder if there's any useful way of adding tests to cover the strategy?

@SukkaW
Copy link
Author

SukkaW commented Dec 25, 2024

i love it! i wonder if there's any useful way of adding tests to cover the strategy?

Lemme see how to setup a test case for this!

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.

3 participants