feat: new preload strategy swap-low#72
Conversation
WalkthroughThe pull request introduces a new preload strategy Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code Definitions (1)packages/beasties/test/beasties.test.ts (1)
🔇 Additional comments (3)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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 toswap-high. JS - **"js":...(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
onloadhandler to clear the title and switch torel="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 ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #72 +/- ##
==========================================
+ Coverage 84.43% 84.92% +0.48%
==========================================
Files 7 7
Lines 1221 1227 +6
Branches 283 286 +3
==========================================
+ Hits 1031 1042 +11
+ Misses 190 185 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #72 will not alter performanceComparing Summary
|
|
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! |
|
did you get a chance to look into this? I'm also happy to merge without tests on the interim basis |
Ah sorry. Haven't got any time for a while looking into this and then I just forgot it. And besides, I don't know what unit test case to add. Currently, |
|
thank you ❤️ |
swap-lowusesrel="alternate stylesheet"(instead ofrel="alternate stylesheet preload"used byswap-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 usesrel="alternate stylesheet"to ensure the lowest priority for stylesheets. It updates the README, TypeScript definitions, and adds tests for the new strategy.Diagrams of code changes
sequenceDiagram participant Browser participant Beasties participant StylesheetLink Browser->>Beasties: Process HTML with stylesheet alt preload="swap-low" Beasties->>StylesheetLink: Set rel="alternate stylesheet" Beasties->>StylesheetLink: Set title="styles" Beasties->>StylesheetLink: Add onload handler StylesheetLink-->>Browser: Load stylesheet with lowest priority Note over StylesheetLink: Once loaded StylesheetLink->>StylesheetLink: Clear title StylesheetLink->>StylesheetLink: Set rel="stylesheet" end Beasties->>Browser: Return processed HTMLFiles Changed
swap-lowpreload strategy.swap-lowin the preload options.swap-lowpreload strategy in the Beasties class.swap-lowin the PreloadStrategy type.swap-lowpreload mode test.swap-lowpreload mode.This PR includes files in programming languages that we currently do not support. We have not reviewed files with the extensions
.md,.ts,.snap. See list of supported languages.