open-next icon indicating copy to clipboard operation
open-next copied to clipboard

null is not an object (evaluating 'b.parentNode') in production

Open leog opened this issue 2 months ago • 2 comments

I'm having the following issue using opennext-aws: https://github.com/vercel/next.js/discussions/70048. Copying the details as-is from it. In my case, Sentry is reporting this happening in every browser.

I don't know how to reproduce but it seems it only happen in Safari.

My Sentry keeps receiving reports from users like this

app:///xxxx(path-to-the-page) in $RS at line 1:119385

with error message:

null is not an object (evaluating 'b.parentNode')

I search the HTML document reporting the error, I see

<script>$RS=function(a,b){a=document.getElementById(a);b=document.getElementById(b);for(a.parentNode.removeChild(a);a.firstChild;)b.parentNode.insertBefore(a.firstChild,b);b.parentNode.removeChild(b)};

This indicates that param b, which is document.getElementById(b) is somehow null.

This code seems to be replated to streaming rendering and this is how the server-sent data push to the client suspense <template id="xxx"/> slot.

Is it possible? how come $RS() calling tries to to insert a non-existing template slot id?

I stand by my last message in that discussion:

Created a PR for my app which has a PR preview upgrading to Next.js 15.5.6 and still happening. Managed to move things around to rely on server side loading.tsx file and still happening. The app continues to work well, but Sentry is going crazy with this error.

Maybe there is a way the line mentioned above and the other flavors (bun, etc) like the following

https://github.com/vercel/next.js/blob/bc59f210b02256e63b93d9f473c97ae130568e63/packages/next/src/compiled/react-dom/cjs/react-dom-server.bun.production.js#L6523

can be patched to not throw an error when there is no elements in a or b which results in a null reference. Seems like an oversight to me, even if it is not expected to have an empty element, it's safer to assume it could not have an element and not apply the change instead of erroring out. I could create a PR to patch those files but doesn't seem right; those are part of the compiled version of next.js under the react-dom dependency. Found this other instance of the same issue facebook/react#25710 by @tannerlinsley.

Logging this issues here as it could be that the issue is being exacerbated by the OpenNext architecture.

leog avatar Oct 18 '25 00:10 leog

I've been getting the same error as you since I upgraded from version 15.3.5 to 15.5.6.

QuentinFontenay avatar Nov 05 '25 13:11 QuentinFontenay

For the sake of linking things together, this issue should be fixed by this https://github.com/facebook/react/pull/34996

leog avatar Nov 05 '25 14:11 leog