| « Back to Search | Reader Mode | Switch to Full Retro Site View | Links: Stay in Reader | Retro Mode: ON | Original » |
pkg-pr-new
|
commit: |
The reason will be displayed to describe this comment to others. Learn more .
Thanks for this. The hooks are well scoped, and apps that don't opt in get the same CSS results as before. I traced that through evaluateCssExpressions, _expandCssShorthand and getCssVariable. But one part of the change has a cost that every app pays, and I'd like that fixed before merging.
settleCssVariables now evaluates every custom property twice: once as before, and once more keeping the math. It does the same inside the forward-reference passes. Whenever the two results differ (any variable that contains calc() itself or through an inherited variable), it also stores the second copy in rawScopedCssVariables.
Nothing in core reads that second copy unless a style sets preserveCssMath. If this merges as-is:
:pressed/:hovered, navigation, theme and appearance changes, and orientation. The second pass skips calc(), but it still does the full var() substitution, which walks the parent chain for each reference. Apps with variable-heavy styling (Tailwind themes, design tokens) are hit hardest, and those are exactly the apps where variable settling already costs the most.calc() take extra memory on every view that declares them. That memory is never read without the opt-in.Only compute the second copy once something has enabled it:
// properties/index.ts
let cssMathPreservation = false;
/**
* Keep CSS math available to `Style.preserveCssMath`. Call before any view loads:
* variables settled earlier only keep their evaluated value.
*/
export function enableCssMathPreservation(): void {
cssMathPreservation = true;
}
export function _isCssMathPreservationEnabled(): boolean {
return cssMathPreservation;
}
// style-scope.ts, settleCssVariables (and the same gate in the forward-reference loop) const authored = cssExpsProperties[property]; const value = evaluateCssVariable(view, property, authored, false); const rawValue = _isCssMathPreservationEnabled() ? evaluateCssVariable(view, property, authored, true) : value; view.style.setScopedCssVariable(property, value, rawValue);
With the flag off, rawValue === value, so setScopedCssVariable never allocates the second map. The forward-reference comparison also becomes a single check. MasonKit would call enableCssMathPreservation() when its entry module is imported, which runs before Application.run.
Why not turn it on automatically when a style sets preserveCssMath? Ancestors settle their variables before a child is installed. An opted-in child would then inherit the calc-evaluated value for something like --inset: calc(...) declared on the root, and fail silently. Making it explicit and early avoids that ordering trap.
Please also add a spec for the off state: with preservation disabled, settling variables never allocates the second map, and getCssVariable(name, true) returns the evaluated value.
converterForStyle affects the whole app. MasonKit's draft re-registers core's transform shorthand with converterForStyle. _expandCssShorthand can't know the target style when the stylesheet is parsed, so with MasonKit installed, every transform: declaration (including on views MasonKit doesn't own) is no longer expanded once per rule. It is expanded per view each time styles are applied. That isn't a core regression, but it makes Mason apps slower everywhere, so it's worth checking whether Mason can avoid overriding transform. Its base converter already emits -mason-transform-declaration, so Mason views might be able to ignore the core longhands in valueChanged instead. At minimum, the JSDoc on converterForStyle should warn that using it on a shorthand makes every declaration of that shorthand per view.preserveCssMath, converterForStyle, and the new parameters on getCssVariable/setScopedCssVariable become public API that core has to support. Marking them @experimental until MasonKit's cutover settles would keep room to change them.test-ios failed. The cascade starts at PAGE.test_WhenModalPageShownShowModalEventsRaisedOnRootModalTabView (modal tab frame count expected 2, got 1), and about 270 waitUntilReady timeouts follow. That looks unrelated to this change: Android passed with the same code and main's iOS run is green. It still needs a green re-run before merge.
With the gate in place, I'm happy to approve.
|
I'd say this is very problematic as a feature. Not only it pushes core further away from standards, but it costs everyone. What you want is what NativeScript doesn't have and the solution is to move further away from CSS. How it works on the web:
And this is also resolved by a graph of dependencies internally, meaning that This is fundamentally different from how we use CSS in NativeScript. Our style is the computed style already, so for us to support this feature it'd be better to properly implement the "flat" styles (queriable by the user), maintaining .style as the computed one and introducing As is, I believe this PR introduces a behavioural change masked as a opt-in feature. Anyone querying a style that a plugin overrode with this "math preserving" feature will break with this change. |
The reason will be displayed to describe this comment to others. Learn more .
Should be closed or properly implemented for all properties onto a different API
Merge branch 'main' into feat/core-css-math-handoff
cc42a6f
|
@aleclarson main just took the TypeScript 6 / Nx 24 / lint changes (#11588 , #11684 , #11685 ), and this PR now conflicts with it. I merged main into your branch, but I can't push to the git fetch https://github.com/NativeScript/NativeScript.git update/11668-main git merge --ff-only FETCH_HEAD git push What the merge did:
Checked locally: core tests 782 passed (main's 778 plus your 4). The core, webpack5 and vite builds pass. Lint has no errors. |
Merge branch 'main' into feat/core-css-math-handoff
70a490a
# Conflicts: # packages/core/ui/core/properties/index.ts
Merge branch 'main' into feat/core-css-math-handoff
705bf3c
|
Fast-forwarded the PR to The startup opt-in and default-off regression test are still open. The fresh iOS and Android checks are running. |