Next.js: TypeError: Cannot read property 'join' of undefined

Created on 28 Jan 2017  路  19Comments  路  Source: vercel/next.js

This occurs only when including preact.

Steps to reproduce:

  • Run the preact example app
  • Add nextjs's Head helper element to a page
  • Give the page a title; then that happens.

The problem arose from the header-manager's method(updateTitle). Preact's VNode exposes just attributes to props with no children, the VNode itself exposes children.

upstream

Most helpful comment

Just confirmed using your repro (thanks again btw!) that it is in fact working now:
screen shot 2017-01-28 at 6 12 20 pm

All 19 comments

I'll have a look 馃憤

Ok I get what you mean. We read component.props.children which is set in React, but not in preact. in preact it's component.children Looks like something that would have to be added to preact-compat. I'll check that now 馃憤

Looks like it's handled here already 馃 https://github.com/developit/preact-compat/blob/master/src/index.js#L109

@developit could you have a look? 鉂わ笍

@timneutkens I just checked and I'm not sure I can reproduce the above issue - here's the JSFiddle I set up: https://jsfiddle.net/developit/n144pt7m/

I might be going about the repro wrong though!

FWIW I'm not sure L45 of <HeadManager> accounts for the case where a single element is passed. In React (and thus in preact-compat), that will result in props.children being a reference to the Virtual DOM Element, rather than an Array.

That is to say, this line:

typeof children==='string' ? children : children.join('')

...if rendered like this:

<HeadManager><AnyThing /><HeadManager>

... will throw an exception, because children is an Object (VNode), not a String or Array.

It seems like this would be an issue when running under React as well, since preact-compat's behavior here is just mimicking React's. Adding an Array check before the join would at least circumvent any exception.

That is a fair point, we will have to update that. The most minimal example where I can reproduce this is this: https://github.com/timneutkens/next-issue-910. In this case, props.children is undefined. That's why it logs an error.

Ah perfect @timneutkens that gives me a great repro. It looks like the bit that adds props.children is only being applied to Component vnodes, not element VNodes. We can remedy that quickly :)

Much appreciated 鉂わ笍

Should be fixed in [email protected]

Thank you very much @developit 馃憤 馃挴

Thanks @developit

Just confirmed using your repro (thanks again btw!) that it is in fact working now:
screen shot 2017-01-28 at 6 12 20 pm

@developit confirmed it too 鉂わ笍

Great, thanks a million for surfacing this Tim!

I am seeing this with:

  • React 15.6.1
  • React DOM 15.6.1
  • Next.js 3.2.2

I want to have a page title containing a bullet character (&bull;). If I do:

<Head><title>foo &bull; bar</title></Head>

... then the title appears as "foo &bull; bar" because the &bull; gets escaped to &amp;bull;.

When I switch to:

<title dangerouslySetInnerHTML={{ __html: "foo &bull; bar" }} />

... the title is set correctly, but this error starts appearing in the browser console, ostensibly because <title></title> has no children at all?

ping @timneutkens @rauchg

@atuttle I am running on the same issue with updating title tag. Did you find a fix or workaround please ? tanks in adavnce

I'm seeing this issue whenever I navigate on the client-side. If I do a refresh it doesn't occur and the title of the page is correct.

@donaminos no, no solution or workaround has been provided yet. It's possible that this is not a problem in a more recent version of Next, but I haven't had the chance to upgrade yet. I am just not using any HTML entities in my title, as annoying as that is.

Does this have any ramifications, or can it be treated as a warning for now? I am using dangerouslySetInnerHTML to unescape special characters in the page's server render, which I suppose isn't a huge deal if I were to stop using it. But I'd prefer to have nice clean titles for the Google.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

irrigator picture irrigator  路  3Comments

sospedra picture sospedra  路  3Comments

renatorib picture renatorib  路  3Comments

kenji4569 picture kenji4569  路  3Comments

pie6k picture pie6k  路  3Comments