From b8d8110994ecb5a882e89ae10e7b13070ae4d709 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Tue, 15 Jun 2021 18:00:07 -0300 Subject: [PATCH 1/2] fix: stop leaking style scopes (#9444) fixes #9311 * fix: stop leaking style scopes * fix: don't leak scoped styles in production --- .../core/ui/styling/css-selector/index.ts | 1 + packages/core/ui/styling/style-scope.ts | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/core/ui/styling/css-selector/index.ts b/packages/core/ui/styling/css-selector/index.ts index c735dce98..32a69df57 100644 --- a/packages/core/ui/styling/css-selector/index.ts +++ b/packages/core/ui/styling/css-selector/index.ts @@ -501,6 +501,7 @@ export namespace Selector { export class RuleSet { tag: string | number; + scopedTag: string; constructor(public selectors: SelectorCore[], public declarations: Declaration[]) { this.selectors.forEach((sel) => (sel.ruleset = this)); } diff --git a/packages/core/ui/styling/style-scope.ts b/packages/core/ui/styling/style-scope.ts index 43dc92508..582a2f524 100644 --- a/packages/core/ui/styling/style-scope.ts +++ b/packages/core/ui/styling/style-scope.ts @@ -76,6 +76,8 @@ export function mergeCssSelectors(): void { let applicationCssSelectors: RuleSet[] = []; let applicationCssSelectorVersion = 0; let applicationSelectors: RuleSet[] = []; +let tagToScopeTag: Map = new Map(); +let currentScopeTag: string = null; const applicationAdditionalSelectors: RuleSet[] = []; const applicationKeyframes: any = {}; const animationsSymbol = Symbol('animations'); @@ -312,12 +314,17 @@ export function removeTaggedAdditionalCSS(tag: string | number): boolean { export function addTaggedAdditionalCSS(cssText: string, tag?: string | number): boolean { const parsed: RuleSet[] = CSSSource.fromDetect(cssText, applicationKeyframes, undefined).selectors; + let tagScope = currentScopeTag || (tag && tagToScopeTag.has(tag) && tagToScopeTag.get(tag)) || null; + if (tagScope && tag) { + tagToScopeTag.set(tag, tagScope); + } let changed = false; if (parsed && parsed.length) { changed = true; - if (tag != null) { + if (tag != null || tagScope != null) { for (let i = 0; i < parsed.length; i++) { parsed[i].tag = tag; + parsed[i].scopedTag = tagScope; } } applicationAdditionalSelectors.push(...parsed); @@ -699,6 +706,7 @@ export class StyleScope { private _localCssSelectorsAppliedVersion = 0; private _applicationCssSelectorsAppliedVersion = 0; private _keyframes = new Map(); + private _cssFiles: string[] = []; get css(): string { return this._css; @@ -720,8 +728,11 @@ export class StyleScope { if (!cssFileName) { return; } + this._cssFiles.push(cssFileName); + currentScopeTag = cssFileName; const cssSelectors = CSSSource.fromURI(cssFileName, this._keyframes); + currentScopeTag = null; this._css = cssSelectors.source; this._localCssSelectors = cssSelectors.selectors; this._localCssSelectorVersion++; @@ -743,8 +754,13 @@ export class StyleScope { if (!cssString && !cssFileName) { return; } + if (cssFileName) { + this._cssFiles.push(cssFileName); + currentScopeTag = cssFileName; + } const parsedCssSelectors = cssString ? CSSSource.fromSource(cssString, this._keyframes, cssFileName) : CSSSource.fromURI(cssFileName, this._keyframes); + currentScopeTag = null; this._css = this._css + parsedCssSelectors.source; this._localCssSelectors.push(...parsedCssSelectors.selectors); this._localCssSelectorVersion++; @@ -788,7 +804,7 @@ export class StyleScope { @profile private _createSelectors() { const toMerge: RuleSet[][] = []; - toMerge.push(applicationCssSelectors); + toMerge.push(applicationCssSelectors.filter((v) => !v.scopedTag || this._cssFiles.indexOf(v.scopedTag) >= 0)); this._applicationCssSelectorsAppliedVersion = applicationCssSelectorVersion; toMerge.push(this._localCssSelectors); this._localCssSelectorsAppliedVersion = this._localCssSelectorVersion; From f6faa4509a51436baeaf16d6f62903b56361cd05 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Tue, 15 Jun 2021 23:07:07 +0200 Subject: [PATCH 2/2] chore(release): @nativescript/core@8.0.8 --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- packages/core/package.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5493b7192..b26f74865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [8.0.8](https://github.com/NativeScript/NativeScript/compare/8.0.7-core...8.0.8) (2021-06-15) + + +### Bug Fixes + +* stop leaking style scopes ([#9444](https://github.com/NativeScript/NativeScript/issues/9444)) ([b8d8110](https://github.com/NativeScript/NativeScript/commit/b8d8110994ecb5a882e89ae10e7b13070ae4d709)), closes [#9311](https://github.com/NativeScript/NativeScript/issues/9311) +* **android:** accessibilityIdentifier ([#9432](https://github.com/NativeScript/NativeScript/issues/9432)) ([9f582ba](https://github.com/NativeScript/NativeScript/commit/9f582ba168dd6f4366e2591a9fed10e1c2443ca4)) + + + ## [8.0.7](https://github.com/NativeScript/NativeScript/compare/8.0.6-core...8.0.7) (2021-06-02) diff --git a/package.json b/package.json index 5174782b5..aa848eb06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript", - "version": "8.0.7", + "version": "8.0.8", "license": "MIT", "scripts": { "clean": "git clean -f -X -d --exclude=!.idea/ --exclude=!.vscode/*", diff --git a/packages/core/package.json b/packages/core/package.json index 762af31fd..df09665d3 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -3,7 +3,7 @@ "main": "index", "types": "index.d.ts", "description": "A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.", - "version": "8.0.7", + "version": "8.0.8", "homepage": "https://nativescript.org", "repository": { "type": "git",