feat: add flat CSS bundle toggle to plugin settings - #79
Conversation
Adds a css_flat boolean setting so users can opt into the flat (no-@layer) variant of whichever bundle they have selected. Changes: - class-settings.php: new get_css_flat() + css_flat persisted in save() - class-css-loader.php: appends .flat to the CSS filename when enabled - class-admin.php: flat toggle UI in Plugin Settings; handles POST save; local-file-ok check honours the flat suffix - class-framework-updater.php: best-effort download of .flat.css files alongside base bundles on every framework update
|
Warning Review limit reached
More reviews will be available in 58 minutes and 44 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
PR Summary by QodoAdd css_flat toggle to load/download .flat.css bundle variants Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1. Missing flat file drops CSS
|
| // Best-effort: download flat (.flat.css) variants. These were introduced | ||
| // alongside the layer-based bundles; older release tags may not have them, | ||
| // so a non-200 response is silently skipped rather than failing the update. | ||
| foreach ( self::BUNDLES as $bundle ) { | ||
| $filename = 'slashed.' . $bundle . '.flat.css'; | ||
| $url = sprintf( self::CDN_BASE, rawurlencode( $version ), $filename ); | ||
|
|
||
| $response = wp_remote_get( | ||
| $url, | ||
| array( | ||
| 'timeout' => 30, | ||
| 'user-agent' => 'SLASHED/' . SLASHED_VERSION . '; WordPress/' . get_bloginfo( 'version' ), | ||
| ) | ||
| ); | ||
|
|
||
| if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| $content = wp_remote_retrieve_body( $response ); | ||
| $wp_filesystem->put_contents( $dist_dir . $filename, $content, FS_CHMOD_FILE ); | ||
| } |
There was a problem hiding this comment.
1. Stale flat files on rollback 🐞 Bug ≡ Correctness
In Slashed_Framework_Updater::download_files(), flat bundle downloads are skipped on non-200 responses and write failures are ignored, so existing slashed.*.flat.css files can remain from a previous version after a rollback. With css_flat enabled, Slashed_CSS_Loader::get_url() will keep serving that stale flat file even though LOCAL_VER_OPTION is updated to the rolled-back version.
Agent Prompt
## Issue description
When updating/rolling back framework files, the best-effort flat download loop can leave old `slashed.<bundle>.flat.css` files in `dist/` if the requested version doesn't provide flat assets (e.g., 404) or if the write fails. Since the loader prefers `.flat.css` when `css_flat` is enabled, this can cause serving a mismatched framework version.
## Issue Context
Base bundles are staged and installed atomically, but flat variants are written directly and failures are silently ignored.
## Fix Focus Areas
- Ensure no stale flat files remain after a non-200/failed flat download (delete existing `.flat.css` for that bundle when the new one can't be retrieved).
- Check `put_contents()` return value for flat writes; on failure, delete any partially written file.
- (Optional) Use the same tmp+move approach as base bundles for `.flat.css` when a 200 response is received.
### Suggested code-level approach
For each bundle in the flat loop:
- Compute `$final_path = $dist_dir . $filename`.
- If response is WP_Error or status != 200: `$wp_filesystem->delete( $final_path ); continue;`
- If 200: write to `$tmp_path = $final_path . '.tmp'`, verify write, then move to `$final_path`.
## Fix Focus Areas (exact locations)
- SLASHED-for-WP/includes/class-framework-updater.php[181-202]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| $source = Slashed_Settings::get_css_source(); | ||
| $bundle = self::get_bundle(); | ||
| $filename = 'slashed.' . $bundle . '.css'; | ||
| $flat = Slashed_Settings::get_css_flat(); | ||
| $filename = 'slashed.' . $bundle . ( $flat ? '.flat' : '' ) . '.css'; |
There was a problem hiding this comment.
2. Missing flat file drops css 🐞 Bug ☼ Reliability
For local delivery, Slashed_CSS_Loader::get_url() returns an empty string when the selected *.flat.css file is missing, and Slashed_Core_Enqueue then skips enqueuing the framework stylesheet entirely. This makes enabling css_flat break styling whenever the local flat artifact is absent (e.g., after a rollback to a version without flat bundles).
Agent Prompt
## Issue description
When `css_flat` is enabled and source is `local`, the loader only looks for `slashed.<bundle>.flat.css`; if it doesn't exist it returns `''`, and the enqueue layer bails, resulting in no framework CSS loaded.
## Issue Context
Returning `''` is currently used to surface missing local files, but with `css_flat` this can happen during normal supported workflows (e.g., rollback) and can wipe styling.
## Fix Focus Areas
- In local mode, if flat is enabled but the flat file is missing, fall back to the non-flat `slashed.<bundle>.css` if it exists.
- Keep the admin notice behavior if desired (e.g., detect “flat requested but missing” separately), but do not drop CSS entirely when a valid non-flat bundle is present.
### Suggested code-level approach
In the `else` (local) branch of `get_url()`:
- If `$flat` is true:
- Check for `slashed.<bundle>.flat.css`; if present, use it.
- Else check for `slashed.<bundle>.css`; if present, use it.
- Else return `''`.
## Fix Focus Areas (exact locations)
- SLASHED-for-WP/includes/class-css-loader.php[54-80]
- SLASHED-for-WP/includes/class-core-enqueue.php[40-68]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Adds a css_flat boolean setting so users can opt into the flat (no-@layer)
variant of whichever bundle they have selected. Changes:
local-file-ok check honours the flat suffix
alongside base bundles on every framework update