Skip to content

Fix Bricks synchronization for empty class sets - #10

Merged
DavidBabinec merged 2 commits into
CoreBunch:mainfrom
Jan-CoreBunch:fix/bricks-empty-class-sync
Aug 17, 2026
Merged

Fix Bricks synchronization for empty class sets#10
DavidBabinec merged 2 commits into
CoreBunch:mainfrom
Jan-CoreBunch:fix/bricks-empty-class-sync

Conversation

@Jan-CoreBunch

Copy link
Copy Markdown
Contributor

Summary

Fixes Bricks synchronization when Core Framework generates variables but no utility classes, and removes stale CF-owned classes immediately when the final generated class is disabled.

Root cause

  • The client returned early when the generated class collection was empty, so update-classes was never called and Bricks variables were not refreshed.
  • Empty selector input could be parsed as an array containing an empty string.
  • Previously synchronized CF classes were filtered before removed locked-class IDs were calculated, losing the IDs required for stale-reference cleanup.

Changes

  • Always invoke class and variable synchronization, including with zero classes.
  • Send selector names as an array while retaining normalization for legacy string input.
  • Normalize empty input to a real empty array and prevent creation of a blank _c class.
  • Run synchronization only after successful stylesheet persistence.
  • Calculate removed IDs from the original CF-owned class collection.
  • Remove deleted CF IDs from Bricks locked classes and relevant _cssGlobalClasses references.
  • Preserve user-created and non-CF classes, variables, categories, and unrelated post settings.
  • Preserve variable extraction through StylesheetStorage.
  • Keep repeated synchronization idempotent.

Automated validation

  • bun run php-test:wp — 26 tests and 47 assertions passed.
  • bun run test:www — 23 suites and 147 tests passed.
  • bun run build:wp — passed.
  • PHP syntax, targeted production PHPCS, Biome, and git diff --check passed.

Manual functional validation

Using Bricks 2.3.11:

  1. Saved a variables-only project with no generated utility classes.
  2. Confirmed CF variables appeared immediately in Bricks.
  3. Enabled a CF class and confirmed it appeared.
  4. Disabled the final CF class and saved once.
  5. Confirmed it disappeared immediately while variables remained.
  6. Confirmed an independent Bricks global class remained untouched.
  7. Repeated synchronization without duplicates or additional mutations.

Manual performance validation

Bricks documents Elements/document Add class Remove class
100 25 76 ms 321 ms
1,000 25 78 ms 2.78 s
5,000 25 68 ms 13.54 s
5,000 100 78 ms 19.09 s

All update-classes requests returned HTTP 200 and completed without errors.

Class addition remained effectively constant. Removal scaled approximately linearly because stale CF references must be removed from Bricks post metadata. The 5,000-document cases are considered an extreme-site caveat rather than a blocker for this focused fix. Further optimization can be considered separately if real-world usage demonstrates a need.

Always run Bricks synchronization after the stylesheet is persisted, including when Core Framework generates no utility classes.

Normalize empty selector payloads, prevent blank global classes, and calculate removed CF class IDs before filtering previous classes. Remove stale locked-class references while preserving non-CF classes, settings, variables, and categories.

Add regression coverage for empty, non-empty, removal, preservation, and idempotent synchronization.

Manual validation against Bricks 2.3.11 covered variables-only synchronization and stress testing up to 5,000 synthetic Bricks documents with 100 elements each. Cleanup remained correct and error-free. Removal time scaled approximately linearly, reaching 19.09 seconds in the largest synthetic case.
@Jan-CoreBunch
Jan-CoreBunch force-pushed the fix/bricks-empty-class-sync branch from 65bf3ad to 1eb2c30 Compare August 14, 2026 11:05
@DavidBabinec
DavidBabinec marked this pull request as ready for review August 17, 2026 18:05
Review fixes on top of the empty-class-set change.

- Prime the meta cache per batch of 50. 'fields' => 'ids' stops WP_Query
  from priming it, so the sweep cost five queries per post, roughly 25k
  on a 5k-post site, which is what produced the 13.5s and 19.1s timings
  in the PR description.
- Sweep references after the class options are written, not before. An
  interrupted sweep used to leave elements stripped of their references
  while the classes still existed, with nothing to recover from it.
- Report a failed push. Gating the toast on persistence removed the false
  confirmation but left silence in its place. handlePushDb no longer
  toasts on its own so the two do not double up.
- Gate colors on persistence as well, ahead of classes, which is the
  order the batch already gave them.
- Skip a selector whose sanitized id collides with one already emitted.
  Bricks keys elements by id, so two classes sharing one is ambiguous.

28 tests pass with 52 assertions, up from 26 and 47. The ordering test
was checked against the previous placement and fails there.
@DavidBabinec
DavidBabinec merged commit ca4a513 into CoreBunch:main Aug 17, 2026
4 checks passed
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.

2 participants