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

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

Merged
merged 3 commits into from
Feb 6, 2024
Merged

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

merged 3 commits into from
Feb 6, 2024

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
15 checks passed
@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