Skip to content

Give a minify builder its own file list - #731

Merged
blaipr merged 1 commit into
mainfrom
fix/minify-builder-is-independent
Aug 13, 2026
Merged

Give a minify builder its own file list#731
blaipr merged 1 commit into
mainfrom
fix/minify-builder-is-independent

Conversation

@blaipr

@blaipr blaipr commented Aug 13, 2026

Copy link
Copy Markdown
Member

The bug

Minify::builder() returns clone $this, and PHP's shallow copy left the clone sharing the source's SplObjectStorage. So a file added to the builder was added to whatever it was built from as well — and two builders taken from one service shared with each other, for the same reason.

That is the opposite of what asking for a builder means.

Nothing trips over it today: each request builds a fresh service and calls builder() once. The moment a service is reused, the stylesheet route would serve the script route's files alongside its own.

The fix

__clone() gives the copy an empty storage.

Testing

Both directions, and each fails against the old code:

  • the source is untouched by what its builder collects;
  • two builders from one service do not see each other's files.

Reading the list back needs reflection — it is private, deliberately — which is the only way to tell one builder's contents from another's without rendering both.

And because a change to how assets are gathered deserves more than a green suite, the bundles the login page actually links were fetched from the running application afterwards:

resource/css  200   36897 bytes
resource/css  200  194434 bytes
resource/js   200  651664 bytes
resource/js   200   62060 bytes

Unit suite green: 3083. PHPStan and PHPCS clean.

builder() returns clone $this, and PHP's shallow copy left the clone sharing the
source's SplObjectStorage — so a file added to the builder was added to whatever
it was built from as well, which is the opposite of what asking for a builder
means. Two builders from one service shared with each other for the same reason.

Nothing trips over it today because each request builds a fresh service and asks
for one builder; the moment a service is reused, the stylesheet route would
serve the script route's files alongside its own.

__clone() gives the copy an empty storage. Covered both ways: the source is
untouched by what its builder collects, and two builders do not see each other's
files.

The bundles the login page links were fetched from the running application
afterwards — both stylesheets and both scripts still serve at full size.
@blaipr
blaipr merged commit e1b220f into main Aug 13, 2026
8 checks passed
@blaipr
blaipr deleted the fix/minify-builder-is-independent branch August 13, 2026 22:06
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