Skip to content

Comments

fix(dev)!: rework _server.tsx#486

Merged
mkilpatrick merged 3 commits intomainfrom
server-index
Feb 6, 2024
Merged

fix(dev)!: rework _server.tsx#486
mkilpatrick merged 3 commits intomainfrom
server-index

Conversation

@mkilpatrick
Copy link
Collaborator

This reworks the exports of _server.tsx. According to this transformIndexHtml should be called on the index.html (which is provided automatically) and not the entire result of calling render (after the server code is injected). It hasn’t actually posed a problem but I’d like to get ahead of it and make sure we’re doing it the right way. It really only affects local dev but it’s breaking since what’s exported from _server.tsx has changed.

_server.tsx is now expected to export 3 things:

export const render = async (pageContext: PageContext<any>) => {
  const { Page, pageProps } = pageContext;

  return ReactDOMServer.renderToString(<Page {...pageProps} />);
};

export const replacementTag = "<!--YEXT-SERVER-->";

export const indexHtml = `<!DOCTYPE html>
    <html lang="<!--app-lang-->">
      <head></head>
      <body>
        <div id="reactele">${replacementTag}</div>
      </body>
    </html>`;

Specifically, indexHtml is now split out from the server render. It also requires a replacementTag to know where the server html should be injected into the indexHtml.

@mkilpatrick mkilpatrick requested a review from a team as a code owner February 2, 2024 19:40
@asanehisa
Copy link
Contributor

lgtm but some tests failing

@mkilpatrick mkilpatrick merged commit f187078 into main Feb 6, 2024
@mkilpatrick mkilpatrick deleted the server-index branch February 6, 2024 20:25
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 this pull request may close these issues.

2 participants