Skip to content

fix: restore macOS transparency and defer CSS errors (3.1.1) - #89

Merged
NuPlay merged 5 commits into
mainfrom
release/3.1.1
Aug 29, 2026
Merged

fix: restore macOS transparency and defer CSS errors (3.1.1)#89
NuPlay merged 5 commits into
mainfrom
release/3.1.1

Conversation

@NuPlay

@NuPlay NuPlay commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Patch release. Fixes two regressions shipped in 3.1.0.

🐛 macOS backgrounds were no longer transparent

3.1.0 guarded the drawsBackground KVC call with responds(to:):

if webview.responds(to: NSSelectorFromString("setDrawsBackground:")) {
    webview.setValue(false, forKey: "drawsBackground")
} else {
    conf.errorHandler?(.webViewConfigurationFailed)
}

The premise was wrong. setValue(_:forKey:) does not need a setDrawsBackground: method — KVC falls back to _setDrawsBackground: and then to the _drawsBackground ivar. So the guard always took the else branch:

  • the background was never made transparent
  • every macOS launch emitted a spurious webViewConfigurationFailed

A guard intended to prevent a crash disabled the feature it was guarding.

Replaced with underPageBackgroundColor, which is public WebKit API available on iOS 15 and macOS 12 — exactly this package's deployment targets. No KVC, no private selectors.

🐛 cssGenerationFailed fired during a SwiftUI view update

The handler was called synchronously from loadHTMLIfNeeded, which runs inside makeUIView and updateUIView. A handler that mutates state there produces "Modifying state during view update, this will cause undefined behavior" — the exact warning #72 reported and #74 fixed. 3.1.0 reintroduced it.

Errors are now delivered on the next main-queue turn via reportError(_:).

🧪 Why 3.1.0 shipped without catching either

The 3.1.0 tests compared generated strings. Neither defect is visible that way.

The new tests check behavior instead:

  • macOS transparency is asserted against a real WKWebView found inside a hosted NSHostingView
  • callback timing is asserted by capturing whether the reporting call had already returned when the handler ran

📖 Documentation

Examples that did not compile:

  • .blue / .cyan were ambiguous between the Color and NSColor/UIColor overloads → qualified as Color.blue
  • let css was declared twice in one scope
  • fullScreenCover(item:) was bound to a String?, which is not Identifiable, and is iOS-only → replaced with an Identifiable wrapper and .sheet

Also removed 18 trailing-whitespace errors, and normalized 17 British spellings (colour, behaviour) that disagreed with the API on the same line:

"Invalid hex colour in fontColor or linkColor"

📦 Release prep

  • CHANGELOG entry for 3.1.1
  • documented version floor raised to 3.1.1, since 3.1.0 is opaque on macOS

NuPlay added 5 commits August 29, 2026 22:39
Use WKWebView's public under-page background API instead of probing a private KVC selector that is not exposed as a method. Deliver CSS errors on the next main-queue turn so handlers cannot mutate state during a SwiftUI representable update.

Add macOS rendering and callback timing regression tests.
Qualify SwiftUI colors, use an Identifiable sheet item, and give generated CSS examples distinct names so the snippets compile on iOS and macOS.

Remove the 18 trailing-whitespace errors introduced in the release changes.
3.1.0 shipped with an opaque background on macOS, so new integrations should
not start there.
The public API is spelled the American way throughout — `Color`, `ColorSet`,
`fontColor`, `colorPreference`, `underPageBackgroundColor` — but comments and
documentation had picked up British spellings, so prose and identifiers
disagreed on the same line:

    "Invalid hex colour in fontColor or linkColor"

Normalized 17 occurrences of colour/colours/colouring and behaviour across
sources, tests, README, CHANGELOG, docs/ and the sample app README. Only prose,
comments and test names changed; no identifier was touched.
Copilot AI lite review requested due to automatic review settings August 29, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@NuPlay NuPlay self-assigned this Aug 29, 2026
@NuPlay NuPlay added the bug Something isn't working label Aug 29, 2026
@NuPlay
NuPlay merged commit d9c3439 into main Aug 29, 2026
1 check passed
@NuPlay
NuPlay deleted the release/3.1.1 branch August 29, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants