question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Namespaces not applying during ember `loading` states

See original GitHub issue

Having a strange issue where the styles don’t seem to apply to the route templates when they are in a loading state as described here:

https://guides.emberjs.com/v2.15.0/routing/loading-and-error-substates/

Not sure if I am doing something wrong but code looks roughly like:

<div class="{{styleNamespace}}__content">
...
</div>

Any components have their css namespace classes applied so it seems like whatever is hooking in to generate the namespace is not triggered until loading is complete.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Turbo87commented, Apr 25, 2019

the problem we’re seeing is this: when we access route foo.bar and bar has a loading template then even the class for the foo route will only be applied once bar has loaded (aka. the transition has finished)

this seems like a major caveat to using this addon with per-route style files and should at least be mentioned in the README if we can’t find a solution.


after writing the above lines I experimented a bit and I think I might have found a solution. instead of using the regular route style assignment code I’m using this:

Route.reopen({
  activate() {
    this._super(...arguments);

    let applicationController = getOwner(this).lookup('controller:application');

    let activeRoutes = applicationController.activeRoutes.slice();
    activeRoutes.push(this.routeName);

    applicationController.set('activeRoutes', activeRoutes);
  },

  deactivate() {
    this._super(...arguments);

    let applicationController = getOwner(this).lookup('controller:application');

    let activeRoutes = applicationController.activeRoutes.slice();
    let index = activeRoutes.indexOf(this.routeName);
    activeRoutes.splice(index, 1);

    applicationController.set('activeRoutes', activeRoutes);
  },
});

and the application controller looks like this:

import Controller from '@ember/controller';
import { computed } from '@ember/object';
import podNames from 'ember-component-css/pod-names';

export default Controller.extend({
  routeStyleNamespaceClassSet: computed('activeRoutes', function() {
    return this.activeRoutes
      .map(routeName => podNames[routeName.replace(/\./g, '/')])
      .filter(Boolean)
      .join(' ');
  }),

  init() {
    this._super(...arguments);
    this.set('activeRoutes', []);
  },
});

caveat: this workaround does not assign the styleNamespace to controllers yet. we don’t use that feature so I didn’t care much about it. it should be possible to implement that part too though.

0reactions
webarkcommented, Jun 24, 2019

@Turbo87 I just released a 0.7.4 and I am using it with error and loading states. do you have any more info into how you are setting up the loading state, and how you are getting there?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Namespaces not applying during ember loading states #286
Having a strange issue where the styles don't seem to apply to the route templates when they are in a loading state as...
Read more >
Route - 4.9 - Ember API Documentation
This event is triggered when the router enters the route. It is not executed when the model for the route changes. app/routes/application.js ...
Read more >
Why do nested resource routes reset the namespace in Ember?
It's because when you transition to routes you don't explicitly call out an entire path. this.transitionTo('photo', photo); {{#link-to ' ...
Read more >
ember-engines - npm
The only difference is that lazily loaded Engines will enter a loading state while the assets for the Engine are loaded and can...
Read more >
The State of the Ember Addon Ecosystem in 2019 - Salsify
Build-time Build-time addons provide command-line tools that help developers during the creation of the application. An example is ember-cli- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found