Coder Social home page Coder Social logo

Comments (12)

surma avatar surma commented on September 7, 2024 1

Not using innerHTML was a conscious decision. Using innerHTML serializes the entire DOM to a string just to deserialize it right after. The current code should be doing exactly the same.

I took the current advanced-router code and changed line 38 of about/index.html to

<sc-view class="view-about visible" route="^/about/(.*)">
  <div>About <a href="x.com">lol</a></div>
</sc-view>

and it still works fine, both on initial page load as well as on navigation.

So I canโ€™t reproduce, but I am curious as to what is going wrong on your end.

from ui-element-samples.

oldergod avatar oldergod commented on September 7, 2024

Could you show a not working solution? Maybe fork the repo and show a branch of yours?

from ui-element-samples.

itsMattShull avatar itsMattShull commented on September 7, 2024

Sure: https://github.com/derekshull/styleguide

Should be able to pull it down and run npm install and gulp watch to see what I'm talking about. You can see what I'm talking about. Whenever you choose a link inside the the sidenav look in the console and you'll see that the xhr is pulling in the correct with the proper content inside the element.

from ui-element-samples.

oldergod avatar oldergod commented on September 7, 2024

Can you reproduce it with the ui-element-samples code?

from ui-element-samples.

itsMattShull avatar itsMattShull commented on September 7, 2024

Yeah: https://github.com/derekshull/ui-element-samples/tree/gh-pages/router-advanced

If you pull it down, go to the router-advanced folder in terminal, run python -m SimpleHTTPServer 8000, and go to localhost:8000. If you try to go to the About page you'll get nothing, just like my styleguide example. Then if you go to localhost:8000/about you'll see the About content but if you click on Home you won't see that content.

from ui-element-samples.

oldergod avatar oldergod commented on September 7, 2024

I see your problem and it does not work because you broke the code.

inside the index.html file, you removed the visible class and added the remote attribute for view-home, and vice-versa for view-about. Here is the diff.
You should not do this, as the index.html is when you access the page via the root /. Fix this and it works fine.

You would need to fix the other html files accordingly as well.

from ui-element-samples.

itsMattShull avatar itsMattShull commented on September 7, 2024

I believe I had it set up properly. I'll have a look. What appears to work is what I did here: #54

By using this.innerHTML = newView.innerHTML; instead of

newView.childNodes.forEach(node => {
    this._view.appendChild(node);
});

this.appendChild(newView.innerHTML);

Seems to work well. Would there be any reason not to do this?

from ui-element-samples.

itsMattShull avatar itsMattShull commented on September 7, 2024

@oldergod I see where you were referring to. I had it mixed up for a bit, but it doesn't appear to be the cause of what I was experiencing.

from ui-element-samples.

surma avatar surma commented on September 7, 2024

Ah I think I found the issue and I also found a solution ๐Ÿ’ƒ

After changing about/index.html:38 to

<sc-view class="view-about visible" route="^/about/(.*)">
  <div>About <a href="x.com">lol</a></div>
  <a href="kek.com">kek</a>
</sc-view>

I could reproduce the issue as in the โ€œkekโ€ link never showed up.

HTMLElement.prototype.appendChild() is a smart beast in that it detaches a node from its previous parent before attaching it to the new one. forEach() doesnโ€™t handle mutating the iterable it is iterating over very well (see this JSBin)

My solution is changing this

      newView.childNodes.forEach(node => {
        this._view.appendChild(node);
      });
      this.appendChild(this._view)

to

      newView.childNodes.forEach(node => {
        this._view.appendChild(node.cloneNode(true));
      });
      this.appendChild(this._view)

@derekshull Do you want to do the honors to fix this in your PR or do you want me to do it?

from ui-element-samples.

surma avatar surma commented on September 7, 2024

Actually, even better would be:

      while(newView.firstChild) {
         this._view.appendChild(newView.firstChild);
      }
      this.appendChild(this._view);

from ui-element-samples.

itsMattShull avatar itsMattShull commented on September 7, 2024

Great! I'll fix this in my local, test, then change the pull request to reflect the changes. Thanks @surma!

from ui-element-samples.

itsMattShull avatar itsMattShull commented on September 7, 2024

I've made the changes in the pull request. I'll go ahead and close the issue.

from ui-element-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.