fix: no ime updates in withUnistyles wrapped components#1172
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughRefactors 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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→ guardedrebuildShadowLeafUpdates→notifyJSListeners→ guardedupdateShadowTree. 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
📒 Files selected for processing (1)
packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/unistyles/cxx/hybridObjects/HybridStyleSheet.h (1)
73-73: Consider passingmaybeMiniRuntimeby const reference.
std::optional<UnistylesNativeMiniRuntime>is taken by value, which copies the entire mini runtime struct on every dependency-change event. SinceapplyDependencyChangesis private and only forwards the optional toParser::rebuildUnistylesInDependencyMap/unwrapStyleSheet(which already acceptstd::optional<UnistylesNativeMiniRuntime>— seepackages/unistyles/cxx/parser/Parser.h:28andpackages/unistyles/cxx/parser/Parser.cpp:177), acceptingconst 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
📒 Files selected for processing (2)
packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpppackages/unistyles/cxx/hybridObjects/HybridStyleSheet.h
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/unistyles/cxx/hybridObjects/HybridStyleSheet.cpp
Summary
Fixes #1162
Summary by CodeRabbit
Bug Fixes
Refactor