Comments (12)
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.
Could you show a not working solution? Maybe fork the repo and show a branch of yours?
from ui-element-samples.
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.
Can you reproduce it with the ui-element-samples code?
from ui-element-samples.
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.
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.
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.
@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.
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.
Actually, even better would be:
while(newView.firstChild) {
this._view.appendChild(newView.firstChild);
}
this.appendChild(this._view);
from ui-element-samples.
Great! I'll fix this in my local, test, then change the pull request to reflect the changes. Thanks @surma!
from ui-element-samples.
I've made the changes in the pull request. I'll go ahead and close the issue.
from ui-element-samples.
Related Issues (20)
- Update examples URL HOT 1
- Infinite Scroller: reverse infinite scrolling? HOT 2
- Path mistake in Router part ||
- Documentation on how to use? HOT 1
- firebase-firestore-comments: FF issue
- we have a question about asynchronous request data issues? HOT 3
- When I load all the data, how to make the components do not scroll?this question is about infinite-scroller
- We have a question about infinite-scroller?
- [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive HOT 1
- Infinite Scrolling, Adding anchor tags for SEO?
- Infinity Scroll: some mistakes in calculating the items height and the items transform
- Uncaught TypeError: document.registerElement is not a function at sc-view.js:100
- Menu clip smudgy on Edge
- Bottom top infinite scroll
- Firefox: Custom scrollbar flickers when any ancestor is "position: fixed"
- animated-clip: creating the stylesheet with keyframes takes too long HOT 3
- Cannot read property 'bind' of undefined HOT 2
- 3d card flip not working on Safari HOT 1
- Horizontal scrolling with swipable cards
- side-nav implementation executes transitionend on wrong transitions (bug + solution) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ui-element-samples.