var swapContent = function (swap, container, transition, complete) {
...
if (!transition) {
if (container) {
container.innerHTML = swap.innerHTML;
} else if (swap.classList.contains('content')) {
document.body.appendChild(swap);
} else {
document.body.insertBefore(swap, document.querySelector('.content'));
}
} else {
...
container.parentNode.insertBefore(swap, container);
}
function getReactRootElementInContainer(container) {
if (!container) {
return null;
}
if (container.nodeType === DOC_NODE_TYPE) {
return container.documentElement;
} else {
return container.firstChild;
}
}
function getReactRootElementInContainer(container) {
if (!container) {
return null;
}
if (container.nodeType === DOC_NODE_TYPE) {
return container.documentElement;
} else {
if (container.classlist.contains('content')) {
return container;
} else {
return container.firstChild;
}
}
}
All fixed bars (.bar
) should always be the first thing in the <body>
of the page. This is really important!
.content
Anything that's not a .bar
should be put in a div with the class .content
. Put this div after the bars in the <body>
tag. The .content
div is what actually scrolls in a Ratchet prototype.
So that "bootstrap" DOM looks like this:
<body>
<!-- Make sure all your bars are the first things in your <body> -->
<header class="bar bar-nav">
<h1 class="title">Ratchet</h1>
</header>
<!-- Wrap all non-bar HTML in the .content div (this is actually what scrolls) -->
<div class="content">
But React will use the strategy: first child of the container to obtain the component to swap with the Virtual DOM. This is essential for React to work "all the way down"...
So the problem is not with React but with Push.js being hardcoded to swap in at the body level. Instead it should allow swapping in at one level below the body level IMO.
Conclusion so far: Change push.js swapContent function to not be hardcoded but be configurable as to where in the document to make the content swap.
I will try this in a small demo project ASAP.
Try this minor tweak of push.js > https://gist.github.com/kristianmandrup/062c042d49daca355d1b
// To customize getContainer strategy
PUSH.getContainer = function() {
// your custom get DOM container element logic
}
// See swapContent function
var swapContainer = PUSH.getContainer();