You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Custom components within other custom components: occasionally not loaded "in time" and ignoring css #1639
I have a page where a custom component is included within another custom component as follows
Page -> 1st level custom component (child of Page) -> 2nd level custom component (child of 1st level custom component)
With 1st-level only custom components I do not have the following issues, but with nested ones yes. Particularly:
the css class applied to the 2nd level custom component is ignored
on the 1st level component (pagePart), loaded event is sometimes triggered before the 2nd level custom component (switchComponent) is actually available and therefore I can't make any init code, resulting in various errors. It seems happening the 2nd time the containing the 1st level custom component is loaded. e.g. as in:
Page with components -> (another) Page -> Page with components
Note: I tried to apply loaded=loaded event in <switchComponent:switchComponent id="first-switch" /> in pagePart.xml but it's not triggered (I guess because that applies only to )
exports.loaded = function() {
// here goes init code which involves pagePart with id "first-part"
// --> ISSUE: from time to time (usually when the view at **Page level** is loaded while another view was loading) 2nd level component (switchComponent) is not available resulting in various errors depending on the init code
}
CSS is being properly loaded and applied to the root Page and elements in the 1st level custom components from their respective stylesheets. CSS is NOT being properly loaded and applied from the 2nd level custom components stylesheets.
I tried "forcing" the 2nd level CSS to load by using the page.addCssFile method on the root page. Styles still do not apply.
If I manually copy the styles from the 2nd level stylesheet and paste them in the root stylesheet (app.css) OR the 1st level component stylesheet, they DO get applied properly to the 2nd level components.
I would like to keep my styles separated for better maintenance, so any idea why these 2nd level stylesheets are not being loaded/applied?
Doing some digging in the {N} source, I think this could be happening when loading custom components in Views that do not have a Page element.
The loadCustomComponent method of the ui/builder won't load a CSS file for a custom component unless parentPage exists. My hunch is that a custom component loaded from another custom component does not pass this "parentPage" test WHEN the root element is not a page.
CSS loads fine for myPage.css and myView.css, but does not load for myWidget.css. I'm assuming this is because parentPage is undefined by the time the ui/builder gets to myWidget.
I don't know enough about the loading system to fix this bug, but hopefully this "inspires" someone that knows more to take a closer look.
@toddanglin I personally haven’t hit this before. I’ve only nested custom components with Angular, and with ng2 in the mix this all works differently.
I’m not super familiar with this area of the code, but at a glance I think you’re right—it looks like the parent page is not getting preserved, so the custom CSS gets lost.
@toddanglin I am not sure whether it will land in the next release. We have to merge a huge refactoring into master first and then I will be able to merge my 5-6 pull requests.
@tsonevn This still isn't working right in 3.0.1 even though it's marked fixed and closed. No CSS files are applied from the 2nd level and further on. "Error: CSS file found but no page specified. Please specify page in the options!" is shown in the logs. Should I open a new bug report?
$ tns info
All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬─────────────┐
│ Component │ Current version │ Latest version │ Information │
│ nativescript │ 3.0.3 │ 3.0.3 │ Up to date │
│ tns-core-modules │ 3.0.1 │ 3.0.1 │ Up to date │
│ tns-android │ 3.0.1 │ 3.0.1 │ Up to date │
│ tns-ios │ 3.0.1 │ 3.0.1 │ Up to date │
└──────────────────┴─────────────────┴────────────────┴─────────────┘
Hi @Clifte@na2axl,
If you still facing the problem with the latest NativeScript version, please open a new issue while providing a sample project, which can be used for debugging.
Activity
dragGH102 commentedon Feb 28, 2016
UPDATE
Apparently initializing the custom Switch under a
setTimeout(function(){ // init code }, 0)on loaded event of top-level container, seems to have solved the problem (except for the CSS issue)
toddanglin commentedon Jul 1, 2016
I am experiencing the same CSS issue.
That is: CSS files for "2nd level" custom components are not being loaded (or at the very least, not being applied).
I have an app that has a structure like this:
CSS is being properly loaded and applied to the root Page and elements in the 1st level custom components from their respective stylesheets. CSS is NOT being properly loaded and applied from the 2nd level custom components stylesheets.
I tried "forcing" the 2nd level CSS to load by using the
page.addCssFilemethod on the root page. Styles still do not apply.If I manually copy the styles from the 2nd level stylesheet and paste them in the root stylesheet (
app.css) OR the 1st level component stylesheet, they DO get applied properly to the 2nd level components.I would like to keep my styles separated for better maintenance, so any idea why these 2nd level stylesheets are not being loaded/applied?
@tjvantoll @jlooper Have you encountered this yet?
toddanglin commentedon Jul 2, 2016
Doing some digging in the {N} source, I think this could be happening when loading custom components in Views that do not have a Page element.
The
loadCustomComponentmethod of theui/builderwon't load a CSS file for a custom component unlessparentPageexists. My hunch is that a custom component loaded from another custom component does not pass this "parentPage" test WHEN the root element is not a page.For example:
myPage.xml
views/myView.xml
views/widgets/myWidget.xml
CSS loads fine for
myPage.cssandmyView.css, but does not load formyWidget.css. I'm assuming this is becauseparentPageis undefined by the time theui/buildergets tomyWidget.I don't know enough about the loading system to fix this bug, but hopefully this "inspires" someone that knows more to take a closer look.
tjvantoll commentedon Jul 5, 2016
@toddanglin I personally haven’t hit this before. I’ve only nested custom components with Angular, and with ng2 in the mix this all works differently.
I’m not super familiar with this area of the code, but at a glance I think you’re right—it looks like the parent page is not getting preserved, so the custom CSS gets lost.
3rror404 commentedon Sep 13, 2016
Has there been any progress with this CSS issue? I've just come across the same situation.
alexrainman commentedon Nov 7, 2016
Same issue here
hamorphis commentedon Dec 12, 2016
I will take a look...
Added UI test for nested components CSS application
8 remaining items
hamorphis commentedon Dec 14, 2016
@toddanglin I am not sure whether it will land in the next release. We have to merge a huge refactoring into master first and then I will be able to merge my 5-6 pull requests.
Fix: Custom components within other custom components: occasionally n…
sserdyuk commentedon Jun 15, 2017
@tsonevn This still isn't working right in 3.0.1 even though it's marked fixed and closed. No CSS files are applied from the 2nd level and further on. "Error: CSS file found but no page specified. Please specify page in the options!" is shown in the logs. Should I open a new bug report?
toddanglin commentedon Nov 17, 2017
Confirmed that this still isn't working as expected for 2nd level CSS with {N} 3.3.0.
@vchimev Any updates?
na2axl commentedon Apr 13, 2018
I'm facing the same issue with {N} 4.0.0
Clifte commentedon Oct 13, 2018
I'm facing the same issue with {N} 4.2.0
tsonevn commentedon Oct 15, 2018
Hi @Clifte @na2axl,
If you still facing the problem with the latest NativeScript version, please open a new issue while providing a sample project, which can be used for debugging.
lock commentedon Oct 15, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.