Skip to content

fix: port applicable fixes from mostlyserious/craftcms#4 - #1

Merged
corneliusio merged 5 commits into
mainfrom
fix/port-craftcms-pr4-fixes
Aug 12, 2026
Merged

fix: port applicable fixes from mostlyserious/craftcms#4#1
corneliusio merged 5 commits into
mainfrom
fix/port-craftcms-pr4-fixes

Conversation

@corneliusio

@corneliusio corneliusio commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Ports the fixes from mostlyserious/craftcms#4 that apply to this repo's architecture. The module-lifecycle, lightbox, and Modal changes from that PR have no counterparts here and were skipped.

  • frontend/src/lib/util/image.ts - the 2x srcset URL no longer emits ?width=0&height=0 when no transform dimensions are given, and width/height attributes fall back to the asset's intrinsic size instead of 0.
  • vite-plugin-tinify (both copies) - the cache checksum now hashes the raw image bytes instead of asset.source.toString(), which was lossy for binary data and could collide across distinct images, serving the wrong cached file.
  • frontend/vite.config.ts - the Tinify API key is now loaded via loadEnv and passed as a plugin option. The plugin previously read process.env.TINYPNG_KEY, which SvelteKit never populates from .env during builds, so production builds with uncached images would always throw. TINYPNG_KEY added to frontend/.env.example.
  • GeneralExtension::onlyEnv - returns an empty string for non-matching environments instead of wrapping the markup in <template>, which still shipped it in the page source.
  • Serializer::menuItems - nested menu link queries are eager loaded, removing the N+1 when serializing dropdown navigation items.
  • utility/install.sh - existing backend/.env and frontend/.env files are no longer clobbered on re-run (previously wiped security keys on an existing install).
  • Config - .gitignore gains /.pnpm-store; .zed/settings.json switches tsgo to typescript-ls to match the source repo.

Testing

  • pnpm run lint - only pre-existing warnings.
  • pnpm run check (svelte-check) - 0 errors.
  • pnpm run test - image.test.ts and all other suites pass; formie-schema.test.ts fails identically on main (pre-existing).
  • backend/vendor/bin/pint --test passes on both modified PHP files.
  • PHPStan error count identical to main (182 pre-existing findings, none on changed lines).

🤖 Generated with Claude Code

Note

Port bug fixes and small feature improvements from upstream fork

  • Fixes image.attributes in frontend/src/lib/util/image.ts to avoid zero-value width/height in 2x srcset URLs and fall back to intrinsic asset dimensions when not specified.
  • Changes Serializer.menuItems to call eagerly()->all() instead of all() when fetching menu item query results.
  • Updates GeneralExtension conditional markup method to return an empty string instead of a <template> wrapper when the environment is not in the allowed list.
  • Refactors vite-plugin-tinify to accept an options object with an explicit key instead of reading process.env.TINYPNG_KEY, and computes SHA1 checksums from the raw asset buffer rather than its string representation.
  • Updates utility/install.sh to skip copying .env.example files if .env already exists, preventing overwriting existing environment config.
  • Behavioral Change: TinyPNG plugin now throws if no key is provided via options; checksum change may invalidate existing cache entries.

Macroscope summarized ff7059a.

Hashing asset.source.toString() is lossy for binary images, so distinct
images could collide on the same cache key. The plugin also read
TINYPNG_KEY from process.env, which SvelteKit never populates from .env
during builds; the key is now loaded via loadEnv and passed as a plugin
option.
Wrapping excluded markup in <template> still ships it in the page
source; return an empty string instead.
@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR ports fixes for image sizing, Tinify cache correctness and environment loading, environment-specific Twig output, menu-query performance, and safer installer reruns.

  • Uses intrinsic image dimensions when transforms omit width or height and avoids zero-valued 2x URL parameters.
  • Hashes raw image bytes for Tinify caching and explicitly supplies the API key from Vite environment loading.
  • Suppresses nonmatching environment markup, enables lazy eager loading for menu items, and preserves existing environment files during installation.
  • Updates supporting environment, ignore, and editor configuration.

Confidence Score: 5/5

The PR appears safe to merge with no concrete changed-code defects identified.

The modified paths preserve their existing contracts while correcting cache hashing, environment-key propagation, image metadata, markup suppression, query loading, and installer file preservation.

Important Files Changed

Filename Overview
frontend/src/lib/util/image.ts Corrects intrinsic dimension fallback and conditionally includes dimensions in the 2x image URL.
frontend/utility/vite-plugin-tinify.ts Hashes binary image data directly and accepts the Tinify key through explicit plugin configuration.
frontend/vite.config.ts Loads the Tinify key through Vite’s environment mechanism and passes it to the plugin.
utility/vite-plugin-tinify.ts Keeps the root plugin copy aligned with the frontend implementation; it currently has no repository caller.
backend/modules/general/services/Serializer.php Enables Craft’s lazy eager-loading behavior when resolving nested menu-item queries.
backend/modules/general/web/twig/GeneralExtension.php Removes nonmatching environment markup entirely rather than retaining it in an inert template element.
utility/install.sh Preserves existing backend and frontend environment files while continuing to apply required dotenv updates.

Reviews (1): Last reviewed commit: "chore: preserve existing .env files in i..." | Re-trigger Greptile

@corneliusio
corneliusio merged commit ddd287a into main Aug 12, 2026
2 checks passed
@corneliusio
corneliusio deleted the fix/port-craftcms-pr4-fixes branch August 12, 2026 16:40
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.

1 participant