Skip to content

fix: no ime updates in withUnistyles wrapped components#1172

Merged
jpudysz merged 2 commits into
mainfrom
feature/scoped-themes
Apr 23, 2026
Merged

fix: no ime updates in withUnistyles wrapped components#1172
jpudysz merged 2 commits into
mainfrom
feature/scoped-themes

Conversation

@jpudysz
Copy link
Copy Markdown
Owner

@jpudysz jpudysz commented Apr 23, 2026

Summary

Fixes #1162

Summary by CodeRabbit

  • Bug Fixes

    • Improved style sheet update reliability so input method (IME) changes and other dependency updates consistently refresh affected styles.
    • Ensures JS-driven style changes trigger necessary UI refreshes even when native dependency sets appear empty.
  • Refactor

    • Centralized dependency-change handling to make updates more predictable and reduce missed refreshes.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-native-unistyles-2.0 Ready Ready Preview, Comment Apr 23, 2026 9:00pm
react-native-unistyles-docs Ready Ready Preview, Comment Apr 23, 2026 9:00pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Walkthrough

Refactors HybridStyleSheet dependency-change handling: introduces applyDependencyChanges helper; handlers delegate to it; rebuild runs before JS listener notification; short-circuit logic updated to consider both native dependencyMap and computed dependentStyleSheets; shadow/leaf/tree updates guarded by non-empty dependencyMap.

Changes

Cohort / File(s) Summary
HybridStyleSheet implementation
packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp
Added private helper applyDependencyChanges(...); updated onPlatformDependenciesChange, onPlatformNativeDependenciesChange, and onImeChange to delegate to the helper; reorder: call parser.rebuildUnistylesInDependencyMap(...) before notifyJSListeners(...); only run shadow/leaf/tree updates when dependencyMap is non-empty; compute dependentStyleSheets to avoid early return when JS-only stylesheets require refresh.
HybridStyleSheet header
packages/unistyles/cxx/hybridObjects/HybridStyleSheet.h
Included <optional> and declared new private method applyDependencyChanges(jsi::Runtime&, std::vector<UnistyleDependency>&, std::optional<UnistylesNativeMiniRuntime>).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Brentlok
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: no ime updates in withUnistyles wrapped components' directly addresses the main issue being fixed and accurately reflects the primary change.
Linked Issues check ✅ Passed The code changes implement the necessary fix by unifying dependency change handling to ensure IME inset updates propagate correctly to withUnistyles-wrapped components via the new applyDependencyChanges helper.
Out of Scope Changes check ✅ Passed All changes are scoped to the HybridStyleSheet implementation to fix IME inset propagation; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/scoped-themes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp (1)

259-368: Optional: extract the shared dependency-change pipeline.

The three handlers (onPlatformDependenciesChange, onPlatformNativeDependenciesChange, onImeChange) now share nearly identical tail logic: build maps → short-circuit on both-empty → rebuildUnistylesInDependencyMap → guarded rebuildShadowLeafUpdatesnotifyJSListeners → guarded updateShadowTree. Consider extracting a small private helper (e.g., applyDependencyChanges(rt, deps, maybeMiniRuntime)) to reduce drift risk — future fixes to one path are easy to miss in the other two (as this PR itself demonstrates).

Non-blocking; safe to defer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp` around lines 259 -
368, Duplicate dependency-change pipeline logic exists in
onPlatformDependenciesChange, onPlatformNativeDependenciesChange and
onImeChange; extract it into a private helper (e.g.,
HybridStyleSheet::applyDependencyChanges) to centralize: signature should accept
jsi::Runtime& rt, const std::vector<UnistyleDependency>& deps and an optional
UnistylesNativeMiniRuntime; move the shared steps — build dependencyMap via
core::UnistylesRegistry::get().buildDependencyMap, compute dependentStyleSheets
via getStyleSheetsToRefresh, short-circuit when both are empty, call
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, dependentStyleSheets,
maybeMiniRuntime), conditionally call parser.rebuildShadowLeafUpdates(rt,
dependencyMap), call notifyJSListeners(deps), and conditionally call
shadow::ShadowTreeManager::updateShadowTree(rt); then replace the duplicated
tail in onPlatformDependenciesChange, onPlatformNativeDependenciesChange and
onImeChange with a call to applyDependencyChanges from their runOnJSThread
lambdas.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp`:
- Around line 259-368: Duplicate dependency-change pipeline logic exists in
onPlatformDependenciesChange, onPlatformNativeDependenciesChange and
onImeChange; extract it into a private helper (e.g.,
HybridStyleSheet::applyDependencyChanges) to centralize: signature should accept
jsi::Runtime& rt, const std::vector<UnistyleDependency>& deps and an optional
UnistylesNativeMiniRuntime; move the shared steps — build dependencyMap via
core::UnistylesRegistry::get().buildDependencyMap, compute dependentStyleSheets
via getStyleSheetsToRefresh, short-circuit when both are empty, call
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, dependentStyleSheets,
maybeMiniRuntime), conditionally call parser.rebuildShadowLeafUpdates(rt,
dependencyMap), call notifyJSListeners(deps), and conditionally call
shadow::ShadowTreeManager::updateShadowTree(rt); then replace the duplicated
tail in onPlatformDependenciesChange, onPlatformNativeDependenciesChange and
onImeChange with a call to applyDependencyChanges from their runOnJSThread
lambdas.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0b058187-c290-40dc-be05-f729588c7713

📥 Commits

Reviewing files that changed from the base of the PR and between f117d52 and 353fbd2.

📒 Files selected for processing (1)
  • packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/unistyles/cxx/hybridObjects/HybridStyleSheet.h (1)

73-73: Consider passing maybeMiniRuntime by const reference.

std::optional<UnistylesNativeMiniRuntime> is taken by value, which copies the entire mini runtime struct on every dependency-change event. Since applyDependencyChanges is private and only forwards the optional to Parser::rebuildUnistylesInDependencyMap / unwrapStyleSheet (which already accept std::optional<UnistylesNativeMiniRuntime> — see packages/unistyles/cxx/parser/Parser.h:28 and packages/unistyles/cxx/parser/Parser.cpp:177), accepting const std::optional<UnistylesNativeMiniRuntime>& here would avoid the copy without changing call-site semantics.

♻️ Proposed refactor
-    void applyDependencyChanges(jsi::Runtime& rt, std::vector<UnistyleDependency>& dependencies, std::optional<UnistylesNativeMiniRuntime> maybeMiniRuntime);
+    void applyDependencyChanges(jsi::Runtime& rt, std::vector<UnistyleDependency>& dependencies, const std::optional<UnistylesNativeMiniRuntime>& maybeMiniRuntime);

Note: if downstream callees mutate or move out of the optional, this change won't apply — keep value semantics in that case.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/unistyles/cxx/hybridObjects/HybridStyleSheet.h` at line 73, The
private method applyDependencyChanges currently takes maybeMiniRuntime by value
causing unnecessary copies; change its signature in HybridStyleSheet.h (and the
matching implementation in HybridStyleSheet.cpp) from
std::optional<UnistylesNativeMiniRuntime> to const
std::optional<UnistylesNativeMiniRuntime>& and forward that const reference to
Parser::rebuildUnistylesInDependencyMap / unwrapStyleSheet (which already accept
std::optional<UnistylesNativeMiniRuntime>), ensuring no callers need to change
unless they rely on moving/mutating the optional.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/unistyles/cxx/hybridObjects/HybridStyleSheet.h`:
- Line 73: The private method applyDependencyChanges currently takes
maybeMiniRuntime by value causing unnecessary copies; change its signature in
HybridStyleSheet.h (and the matching implementation in HybridStyleSheet.cpp)
from std::optional<UnistylesNativeMiniRuntime> to const
std::optional<UnistylesNativeMiniRuntime>& and forward that const reference to
Parser::rebuildUnistylesInDependencyMap / unwrapStyleSheet (which already accept
std::optional<UnistylesNativeMiniRuntime>), ensuring no callers need to change
unless they rely on moving/mutating the optional.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d5d85d2f-59e6-4992-81f3-f2097779809f

📥 Commits

Reviewing files that changed from the base of the PR and between 353fbd2 and 5e66c35.

📒 Files selected for processing (2)
  • packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp
  • packages/unistyles/cxx/hybridObjects/HybridStyleSheet.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp

@jpudysz jpudysz merged commit e4a16fc into main Apr 23, 2026
5 checks passed
@jpudysz jpudysz deleted the feature/scoped-themes branch April 23, 2026 21:01
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.

IME inset is always 0 when used in a style passed to a withUnistyles component

1 participant