Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inserting a node before a body tag with other siblings #640

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ export function renderer(renderer: () => RenderResult): Renderer {
let domNode = nextSibling.domNode;
if ((isWNodeWrapper(nextSibling) || isVirtualWrapper(nextSibling)) && nextSibling.childDomWrapperId) {
const childWrapper = _idToWrapperMap.get(nextSibling.childDomWrapperId);
if (childWrapper) {
if (childWrapper && !isBodyWrapper(childWrapper)) {
domNode = childWrapper.domNode;
}
}
Expand Down
49 changes: 49 additions & 0 deletions tests/core/unit/vdom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4035,6 +4035,55 @@ jsdomDescribe('vdom', () => {
assert.isNull(root.querySelector('#my-body-node-2'));
});

it('can attach body and have widgets inserted nodes that are positioned after the body', () => {
const factory = create({ icache });
const Button = factory(function Button({ children }) {
return (
<div>
<button>{children()}</button>
</div>
);
});
const Body = factory(function Button({ children }) {
return (
<body>
<div id="body-node">{children()}</div>
</body>
);
});
const App = factory(function App({ middleware }) {
const open = middleware.icache.getOrSet('open', false);
return (
<div>
<div>first</div>
{open && <Button>Close</Button>}
{open && <Body>Body</Body>}
<div>
<button
onclick={() => {
middleware.icache.set('open', !middleware.icache.getOrSet('open', false));
}}
>
Click Me
</button>
</div>
</div>
);
});

const r = renderer(() => w(App, {}));
r.mount({ domNode: root });
(root as any).children[0].children[1].children[0].click();
resolvers.resolve();
assert.strictEqual(
root.innerHTML,
'<div><div>first</div><div><button>Close</button></div><div><button>Click Me</button></div></div>'
);
const bodyNode = document.getElementById('body-node');
assert.isNotNull(bodyNode);
assert.strictEqual(bodyNode!.outerHTML, '<div id="body-node">Body</div>');
});

it('should detach nested body nodes from dom', () => {
let doShow: any;

Expand Down