question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Portals [React-Compat] missing field and rendering problem

See original GitHub issue

[+] Check if updating to the latest Preact version resolves the issue

React Portals has a property called “containerInfo” which can return the container itself. This is documented somewhere for sure, but I only found out from the Dart docs. https://pub.dev/documentation/react/latest/react_client.react_interop/ReactPortal-class.html This problem occurred while integrating with this proprietary library:

https://bryntum.com/docs/scheduler/#
https://bryntum.com/docs/scheduler/guide/Scheduler/integration/react/guide#rendering-react-components-in-column-cells

Where there is a React wrapper for the components, which uses Portals to move cells around. Relevant snippet:

if (portal) {
    // Move portal container back to the cell if we have one
    renderElement.appendChild(portal.containerInfo);
    renderElement.portalContainer = portal.containerInfo;
} else {
    // Create new portal container
    ...
    renderElement.portalContainer = _portalContainer; // Create a new portal in the portal container
    portal = ReactDOM.createPortal(reactNode, _portalContainer, portalId); // Add the new portal to Map

Here is what React produces:

kép

A portal, with a component inside, with its children.

What Preact produces:

kép

The container is okay, it but the children are missing from it:

kép

Which is also part of the component:

kép

The props children never shows up on the output.

Expected behavior

The compat library to incorporate this functions.

** Steps to reproduces **

  1. Get the 45 day trial, and based of the doc, just override the cell renderer method with JSX

** Partial solution **

During debugging I already managed to link up the missing field with this code snippet, but this is sub optimal.

compat/src/portals.js

export function createPortal(vnode, container) {
	return createElement(Portal, { _vnode: vnode, _container: container, _expose: "containerInfo" });
}

compat/src/render.js

let oldVNodeHook = options.vnode;
options.vnode = vnode => {
	let type = vnode.type;
	let props = vnode.props;
	let normalizedProps = props;
	if (vnode.props._expose === "containerInfo") {
		vnode.containerInfo = vnode.props._container;
	}

I can do more debugging, just the output of the preact bundle is minified, and thats not ideal tracking whats not working as expected.

Any help would be useful, and would prevent a React switch. 😃

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JoviDeCroockcommented, Apr 7, 2022

@wahur666 your test has a typo, I think you meant to do this

	it('should render into a different root node', () => {
		let root = document.createElement('div');
		document.body.appendChild(root);

		const A = () => <span>A</span>

		function Foo(props) {
			const portal = createPortal(props.children, root);
			return <div>{portal}</div>;
		}
		render(<Foo><A /></Foo>, scratch);

		expect(root.innerHTML).to.equal('<span>A</span>');

		root.parentNode.removeChild(root);
	});

As you are not using Foo so we can’t render anything, this test succeeds

0reactions
wahur666commented, Apr 7, 2022

The screenshots aren’t really telling me why that’s happening but given your initial code-snippet I assume it’s because of missing the containerInfo property? Would this addition fix it? like #3508

Please if you can, merge the fix, maybe someone besides me will make use of it, and you can close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Portals - React
Portals. Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component....
Read more >
React-cool-portal: What it is and how to use it - LogRocket Blog
React -cool-portal is a new, Hooks-based abstraction over React portals that allows you to render elements outside the root node.
Read more >
ReactDOM.render is no longer supported in React 18 - Stack ...
ReactDOM.render has been deprecated in React 18 and currently issues a warning and runs in a compatible mode. Deprecations. Deprecations.
Read more >
React-test-renderer: support for portal · Issue #11565 - GitHub
This usually means a return statement is missing. Or, to render nothing, return null. This test passes if I wrap createPortal in a...
Read more >
Using React Portals to Render Children Outside the DOM ...
Step 1: Create the Portal element. The first line of a React application will tell you that an App element is rendered on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found