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

@loadable/server, Each child in a list should have a unique "key" prop. #628

Closed
kuoruan opened this issue Sep 15, 2020 · 1 comment · Fixed by #631
Closed

@loadable/server, Each child in a list should have a unique "key" prop. #628

kuoruan opened this issue Sep 15, 2020 · 1 comment · Fixed by #631
Assignees

Comments

@kuoruan
Copy link
Contributor

kuoruan commented Sep 15, 2020

🐛 Bug Report

getRequiredChunksScriptElements(extraProps) {
const id = getRequiredChunkKey(this.namespace)
const props = {
type: 'application/json',
...handleExtraProps(null, extraProps),
}
return [
<script
id={id}
dangerouslySetInnerHTML={{
__html: this.getRequiredChunksScriptContent(),
}}
{...props}
/>,
<script
id={`${id}_ext`}
dangerouslySetInnerHTML={{
__html: this.getRequiredChunksNamesScriptContent(),
}}
{...props}
/>,
]
}

getRequiredChunksScriptElements return a JSX array but no unique key satisfied.

To Reproduce

import React, { FC, HTMLProps, ReactNode } from "react";

interface HtmlProps extends HTMLProps<HTMLHtmlElement> {
  bodyProps?: HTMLProps<HTMLBodyElement>;
  titleNode?: ReactNode;
  metaNode?: ReactNode;
  linkNodes?: ReactNode[];
  styleNodes?: ReactNode[];
  scriptNodes?: ReactNode[];
  content?: string;
  preloadedState?: object;
}

const Html: FC<HtmlProps> = function ({
  bodyProps = {},
  titleNode = <title>App</title>,
  metaNode,
  linkNodes = [],
  styleNodes = [],
  scriptNodes = [],
  content = "",
  preloadedState = {},
  ...restProps
}: HtmlProps) {
  return (
    <html {...restProps}>
      <head>
        <meta charSet="utf-8" />
        <link
          rel="shortcut icon"
          href={`${process.env.PUBLIC_URL}/favicon.ico`}
        />
        <meta httpEquiv="X-UA-Compatible" content="IE=Edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="manifest" href={`${process.env.PUBLIC_URL}/manifest.json`} />
        {titleNode}
        {metaNode}
        {linkNodes}
        {styleNodes}
      </head>
      <body {...bodyProps}>
        <div id="app" dangerouslySetInnerHTML={{ __html: content }}></div>
        <script
          key="preload-state"
          dangerouslySetInnerHTML={{
            __html: `window.__PRELOADED_STATE__ = ${JSON.stringify(
              preloadedState
            ).replace(/</g, "\\u003c")}`,
          }}
        ></script>
        {scriptNodes}
      </body>
    </html>
  );
};

export default Html;
const linkElements = clientExtractor.getLinkElements();
const styleElements = clientExtractor.getStyleElements();
const scriptElements = clientExtractor.getScriptElements();

const helmet = Helmet.renderStatic();
const htmlAttributes = helmet.htmlAttributes.toComponent();
const bodyAttributes = helmet.bodyAttributes.toComponent();
const titleComponent = helmet.title.toComponent();
const metaComponent = helmet.meta.toComponent();
const linkComponent = helmet.link.toComponent();

const preloadedState = store.getState();

const html = renderToStaticMarkup(
  <Html
    {...htmlAttributes}
    bodyProps={bodyAttributes}
    titleNode={titleComponent}
    metaNode={metaComponent}
    linkNodes={[linkComponent, ...linkElements]}
    styleNodes={styleElements}
    scriptNodes={scriptElements}
    content={markup}
    preloadedState={preloadedState}
  />
);

Expected behavior

Warning:

Warning: Each child in a list should have a unique "key" prop.

Check the top-level render call using <body>. See https://fb.me/react-warning-keys for more information.
    in script
    in Html
"@loadable/server": "5.13.2"

5.13.1 is OK.

@theKashey
Copy link
Collaborator

Related to #607

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants