fix(core): replace previous inline declarations when assigning view.style by edusperoni · Pull Request #11672 · NativeScript/NativeScript
Repository navigation
fix(core): replace previous inline declarations when assigning view.style - #11672
Merged
NathanWalker merged 2 commits into main from fix/inline-style-replace Nov 27, 2026
Merged
fix(core): replace previous inline declarations when assigning view.style #11672 NathanWalker merged 2 commits into main from fix/inline-style-replace
Conversation
edusperoni commented Nov 24, 2026
Copy link Copy Markdown
Contributor
PR Checklist
- The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/main/tools/notes/CONTRIBUTING.md#commit-messages .
- There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
- You have read and signed the CLA (first-time contributors can sign directly on the PR by commenting
I have read the CLA and I hereby sign the CLA). - All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/main/tools/notes/DevelopmentWorkflow.md#unit-testing .
- Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/main/tools/notes/WritingUnitTests.md .
What is the current behavior?
Assigning an inline style string merges into the previous inline declarations instead of replacing them:
view.style = 'color: red; margin: 4'; view.style = 'color: blue'; // margin is still 4
On the web, el.style = '...' forwards to cssText and replaces every inline declaration. applyInlineStyle wrote each declaration as a local value but never released the ones the previous string set and the new one omits (only unscoped css variables were reset).
What is the new behavior?
A new inline string replaces the previous one. applyInlineStyle remembers, per view, which properties the last string declared (longhand names, since shorthands, including pending var() shorthands, are expanded while parsing). On the next assignment it sets unsetValue on the properties the new string no longer declares, before applying the new ones:
- A dropped property falls back to the stylesheet value (via the cascade fallback from fix(core): restore the css value when a local style value is reset #11520 ), or the inherited/default value when the stylesheet sets none. Covered for
CssProperty,InheritedCssPropertyandCssAnimationProperty(background-color,opacity). - Dropping a shorthand (
margin: 4→color: red) clears its longhands. Narrowing it (margin: 4→margin-top: 4) leavesmargin-topuntouched. - A property the new string still declares is not unset and re-applied, so it gets no extra change events or native writes.
view.style = ''clears every previously inlined property.- Properties applied through the view rather than the style (the
view[property]branch) are unset the same way. - A property whose declarations in the new string are all invalid counts as not declared: it is released if the previous string set it, and it is not tracked. An earlier valid declaration in the same string still wins (
color: red; color: oops→ red). - Css variables keep their existing reset.
All callers go through applyInlineStyle via setInlineStyle / the style setter: the XML style="..." attribute (including style="{{ expr }}" bindings, which now replace on every update), Angular's static style attribute (_applyXmlAttribute), and renderers that assign view.style = string or setAttribute('style', ...) (react-nativescript, svelte-native's cssText). Per-property framework bindings (view.style[prop] = ...) are unaffected.
Known limitations
- Values set from code (
view.style.color = ...,view.color = ...) and from XML attributes share the same local slot as inline values. If an inline string dropscolorwhile code had also setcolor, the unset clears the code value too. Separating the slots is a planned, separate refactor. Values set only from code are untouched. - A dropped property applied through the view (not the style) falls back to its default, not the stylesheet value, because view properties have no separate css/local source tracking.
Tests
packages/core/ui/styling/inline-style.spec.ts: 17 specs. 13 fail onmain; the 4 that pass onmainare guards (a kept property is not re-applied, values set only from code are left alone, and two invalid-declaration cases).- Full core suite: 61 files, 697 passed, 1 skipped.
apps/automated: addedtest_setInlineStyle_replacesPreviousDeclarationsnext totest_setInlineStyle_setsLocalValues. Not run (no device/simulator available).
fix(core): replace previous inline declarations when assigning view.s...
0d3852d
...tyle Assigning an inline style string merged into the previous inline declarations. Like the web's cssText, a new string now replaces them: properties the previous string set and the new one omits are unset and fall back to the stylesheet value (or the default/inherited value).
nx-cloud
Bot
commented
Nov 24, 2026
·
edited
Loading
Copy link Copy Markdown
|
View your CI Pipeline Execution ↗ for commit 180eaa2
💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗ ☁️ Nx Cloud last updated this comment at |
pkg-pr-new
Bot
commented
Nov 24, 2026
·
edited
Loading
Copy link Copy Markdown
commit: |
test(core): cover every registered shorthand in inline style replacement
180eaa2
Table-driven over margin, padding, gap, transform, background, border-color, border-width, border-radius, font, flex-flow, flex and android-content-inset: dropping the shorthand unsets every longhand, falls back to the stylesheet longhands, and changing its value moves each longhand at most once. Also covers shorthand/longhand order within one string, narrowing a shorthand to one of its longhands, a shorthand that expands to fewer longhands, and unexpanded shorthand values.This was referenced Nov 24, 2026 fix(core): keep var() and calc() in local style values current #11673 Merged feat(core): inlineStyle, attributeStyleMap, computedStyleMap and getComputedStyle #11674 Draft NathanWalker approved these changes Nov 25, 2026
View reviewed changes
NathanWalker left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Looks good. Replace semantics match cssText, and I checked the edge cases with throwaway specs: stylesheet var()/calc() fallback, pending var() shorthands, inherited fallback to a parent's inline value, a string assigned before load, invalid/unparsable declarations, the view-branch (text), and all 12 registered shorthands. Framework callers look fine: Vue 3 / react-nativescript set per property, Angular's static style goes through once, Svelte 5 builds a full cssText.
Verified: core vitest 739 passed / 1 skipped, tsc -p packages/core/tsconfig.lib.json clean, prettier clean. The original 17 specs do give 13 fail / 4 pass on main.
Nits (inline), plus:
- The description's numbers are stale (17 specs / 697 passed; it's 59 specs / 739 now).
- Worth deciding whether this gets a changelog note: apps that relied on merging (
view.style = 'a'thenview.style = 'b'to add rules) now losea. - Agree with the documented limitation about the shared local slot (a dropped inline property also clears a code-set value); fine to land ahead of the slot refactor IMO, but it's the case users will notice with
style="{{ }}"bindings plus overlapping attributes.
| }); | ||
| } | ||
| if (declared) { | ||
| inlineStyleProperties.set(view, declared); |
| return importSourceParts.join(path.separator); | ||
| } | ||
|
|
||
| // Holds longhand names, as declarations are expanded while parsing. |
| } | ||
| } | ||
|
|
||
| function loaded(css: string): { view: any; root: any } { |
61bf4fe
into
main
Nov 27, 2026
13 checks passed
NathanWalker
deleted the
fix/inline-style-replace
branch
November 27, 2026 22:28
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment