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

Self-closing tag ignored by node selector in upgrade-legacy codemod #3641

Closed
Bobberta opened this issue Jul 30, 2022 · 1 comment · Fixed by #3702
Closed

Self-closing tag ignored by node selector in upgrade-legacy codemod #3641

Bobberta opened this issue Jul 30, 2022 · 1 comment · Fixed by #3702
Assignees
Labels
kind/bug Something isn't working status/done

Comments

@Bobberta
Copy link

What is the problem?

I ran into an "unexpected error" while running the upgrade-legacy codemod, at the update imports in the _document file step:
TypeError: Cannot read property 'name' of null

I dug into the code and managed to identify the reason for that error.
See l.941:

.find(j.JSXElement, (node) => node.openingElement.name.name === "DocumentHead")

We are looking for the opening element for DocumentHead

In my case, DocumentHead was empty, and was written as a self-closing tag: <DocumentHead /> , thus making it invisible for this query, since we are looking for a node with an openingElement with a name of DocumentHead.

Changing <DocumentHead /> to <DocumentHead><DocumentHead/> has fixed the issue.

Paste all your error logs here:

✖ update imports in the _document file
TypeError: Cannot read property 'name' of null
This is an unexpected error. Please ask for help in the discord #general-help channel. https://discord.blitzjs.com

Paste all relevant code snippets here:

_document.tsx

import { Document, Html, DocumentHead, Main, BlitzScript } from "next/document";
import React from 'react';
import { DocumentContext } from 'blitz';

class MyDocument extends Document {
  static async getInitialProps(ctx: DocumentContext) {
    const initialProps = await Document.getInitialProps(ctx);
    return {
      ...initialProps,
      styles: React.Children.toArray([initialProps.styles]),
    };
  }

  render() {
    return (
      <Html lang="en">
        <DocumentHead />
        <body>
          <Main />
          <BlitzScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;

What are detailed steps to reproduce this?

  1. Add a self-closing DocumentHead tag in _document.tsx
  2. Run npx @blitzjs/codemod upgrade-legacy

Run blitz -v and paste the output here:

alpha

Please include below any other applicable logs and screenshots that show your problem:

No response

@beerose
Copy link
Contributor

beerose commented Aug 1, 2022

Thanks for the report. Will fix that soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants