Skip to content

Add client runtime init, tier-visibility CSS, signal enhancements, and default signal matrix#39

Open
fabianzimber wants to merge 2 commits into
mainfrom
feature/improve-developer-experience-and-signal-detection
Open

Add client runtime init, tier-visibility CSS, signal enhancements, and default signal matrix#39
fabianzimber wants to merge 2 commits into
mainfrom
feature/improve-developer-experience-and-signal-detection

Conversation

@fabianzimber
Copy link
Copy Markdown
Member

@fabianzimber fabianzimber commented May 2, 2026

Motivation

  • Provide a small client runtime to initialize BCL state and publish tier/features to the DOM so existing apps can opt-in without wrapping the tree in CakeProvider/CakeLayer.
  • Improve progressive degradation heuristics by enabling a conservative signal matrix by default and adding more non-unique signals (online, contrast, UA mobile fallback) to better protect low-resource or offline clients.
  • Make CSS-only layering easy by injecting default visibility rules for data-cake-tier / caketier selectors.
  • Improve DX by exposing a cakeTier JSX attribute type and documenting a 30-second setup in README.md.

Description

  • Added a client runtime: src/runtime.ts with initCakeRuntime that detects signals, resolves tier/features, writes data-bcl-* attributes to <html>, and injects tier visibility styles via ensureCakeTierVisibilityStyles.
  • New CSS visibility helper: src/cake-tier-visibility.ts that generates and injects rules to hide elements for tiers; exported and consumed by the runtime.
  • Enabled the signal matrix by default via DEFAULT_CONFIG.advanced.signalMatrix = true and extended DEFAULT_SIGNAL_MATRIX_RULES in src/signal-matrix.ts with conservative rules (offline, save-data/downlink cap, reduced-motion + high contrast, etc.).
  • Enhanced signal detection in src/signals.ts to include online, prefersContrastMore, and a userAgent fallback for userAgentMobile; added additional listeners (online/offline, visibilitychange, pageshow) to subscribeToSignalChanges.
  • Exposed new exports in src/index.ts: initCakeRuntime, ensureCakeTierVisibilityStyles, and CakeTierSelector type; added src/jsx.d.ts to allow cakeTier as a JSX attribute.
  • Updated src/types.ts and src/context.tsx to include the new signals and to publish the new data-bcl-* attributes on <html>.
  • Documentation: extended README.md with a 30-second setup example showing initCakeRuntime, data attributes, and a note about the default signal matrix and HTML dataset usage.

Testing

  • Added unit tests in tests/runtime.test.ts that validate initCakeRuntime writes data-bcl-* to the document and injects the default visibility CSS; these tests were executed as part of the test run and succeeded.
  • Ran the automated test suite with npm test, and the new tests passed along with the existing test suite.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a lightweight client-side runtime to initialize BCL state without requiring CakeProvider/CakeLayer, improves signal detection and the default signal matrix behavior, and enables CSS-only tier layering via injected visibility rules and <html data-bcl-*> attributes.

Changes:

  • Added initCakeRuntime to compute tier/features from detected signals, publish state to <html data-bcl-*>, and optionally watch for signal changes.
  • Introduced automatic tier-visibility CSS injection for [data-cake-tier] / [caketier] selectors to support CSS-only layering.
  • Expanded signals (online, prefers-contrast) and enabled a more conservative signal matrix by default.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/runtime.test.ts Adds unit tests for runtime dataset writes and default tier-visibility CSS injection.
src/types.ts Extends signal and signal-matrix condition types with online and prefersContrastMore.
src/signals.ts Detects new signals and subscribes to additional events (online/offline, visibility, pageshow).
src/signal-matrix.ts Adds conservative default matrix rules and matches new signal fields.
src/runtime.ts Adds initCakeRuntime client runtime (merge config, detect signals, resolve tier/features, write dataset, inject CSS, watch signals).
src/jsx.d.ts Adds a React JSX attribute type for cakeTier.
src/index.ts Exposes new runtime/CSS helper exports and the CakeTierSelector type.
src/context.tsx Publishes the new signals to <html data-bcl-*> when using CakeProvider.
src/config.ts Enables the signal matrix by default.
src/cake-tier-visibility.ts Implements tier-visibility CSS generation and injection helper.
README.md Documents “30-second setup” via runtime init + dataset/CSS-only layering notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/signal-matrix.ts Outdated
Comment on lines +141 to +147
typeof (when as CakeSignalMatrixCondition & { online?: boolean }).online === "boolean" &&
!matchesBoolean((signals as CakeSignals & { online?: boolean }).online, (when as CakeSignalMatrixCondition & { online?: boolean }).online as boolean)
) return false;

if (
typeof (when as CakeSignalMatrixCondition & { prefersContrastMore?: boolean }).prefersContrastMore === "boolean" &&
!matchesBoolean((signals as CakeSignals & { prefersContrastMore?: boolean }).prefersContrastMore, (when as CakeSignalMatrixCondition & { prefersContrastMore?: boolean }).prefersContrastMore as boolean)
Comment thread src/types.ts Outdated
prefersContrastMore?: boolean;
}


Comment thread src/cake-tier-visibility.ts Outdated
style.id = STYLE_ID;
style.dataset.bcl = "tier-visibility";
style.textContent = rules.join("\n");
document.head.appendChild(style);
@fabianzimber
Copy link
Copy Markdown
Member Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

@copilot apply changes based on the comments in this thread

Applied all three changes in commit dea7f7c:

  1. src/signal-matrix.ts – Removed the redundant as ... & { online?: boolean } / as ... & { prefersContrastMore?: boolean } casts; both fields are already part of CakeSignalMatrixCondition and CakeSignals, so direct property access now reads cleanly.
  2. src/types.ts – Removed the extra blank line after the CakeSignals closing brace.
  3. src/cake-tier-visibility.ts – Replaced bare document.head.appendChild(style) with a null-safe fallback: document.head ?? document.getElementsByTagName("head")[0] ?? document.documentElement.

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.

3 participants