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

Check body for attached nodes #579

Merged
merged 3 commits into from
Nov 6, 2019
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
6 changes: 5 additions & 1 deletion src/core/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,11 @@ export const node = factory(({ id }) => {
widgetMeta.nodeMap = widgetMeta.nodeMap || new Map();
const mountNode = widgetMeta.mountNode;
const node = widgetMeta.nodeMap.get(key);
if (node && mountNode.contains(node)) {
if (
node &&
(mountNode.contains(node) ||
(global.document.body !== mountNode && global.document.body.contains(node)))
) {
return node;
}
requestedDomNodes.add(`${widgetId}-${key}`);
Expand Down
15 changes: 15 additions & 0 deletions tests/core/unit/vdom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3565,6 +3565,21 @@ jsdomDescribe('vdom', () => {
assert.strictEqual(root.childNodes[0].childNodes[0], divNode);
});

it('should invalidate widget once body node is available', () => {
const createWidget = create({ node });
let divNode: any;
const App = createWidget(({ middleware }) => {
divNode = middleware.node.get('div');
return v('div', [undefined, v('body', [v('div', { key: 'div' })]), undefined]);
});
const r = renderer(() => App({}));
const root = document.createElement('div');
r.mount({ domNode: root });
assert.isNull(divNode);
resolvers.resolve();
assert.strictEqual(document.body.lastElementChild, divNode);
});

it('should remove nodes from the map', () => {
const createWidget = create({ node, invalidator });
let divNode: any;
Expand Down