Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Новая версия with-fork не может быть использована на кастомизированном Document #4

Closed
7iomka opened this issue May 18, 2020 · 0 comments
Assignees

Comments

@7iomka
Copy link

7iomka commented May 18, 2020

мой код _document.tsx содержит определенную кастомизацию и выглядит так

import cx from 'clsx';
import { DocumentInitialProps } from 'next/dist/next-server/lib/utils';
import Document, { DocumentContext, DocumentProps, Head, Main, NextScript } from 'next/document';
import React from 'react';
import { DEFAULT_LOCALE } from '@i18n/i18n';
import { withFork } from '@lib/effector-next';

/**
 * Additional props depending on our App
 *
 * Must be returned by getInitialProps and will be available in render function
 */
type Props = {
  locale: string;
  lang: string;
};

type DocumentGetInitialPropsOutput = Props & DocumentInitialProps;
type DocumentRenderProps = Props & DocumentProps;

/**
 * XXX Is only rendered on the server side and not on the client side
 *
 * Used to inject <html lang=""> tag
 *
 * See https://github.com/zeit/next.js/#custom-document
 */
class AppDocument extends Document<DocumentRenderProps> {
  // `Document's getInitialProps function is not called during client-side transitions, nor when a page is statically optimized`
  static async getInitialProps(ctx: DocumentContext): Promise<DocumentGetInitialPropsOutput> {
    const initialProps: DocumentInitialProps = await Document.getInitialProps(ctx);
    const { query } = ctx;
    const hasLocaleFromUrl = !!query?.locale;
    const locale: string = hasLocaleFromUrl ? (query?.locale as string) : DEFAULT_LOCALE; // If the locale isn't found (e.g: 404 page)
    const lang: string = locale.split('-')?.[0];

    return {
      ...initialProps,
      locale,
      lang,
    };
  }

  render(): JSX.Element {
    const { lang, locale }: DocumentRenderProps = this.props;

    return (
      <html lang={lang}>
        <Head />
        <body className={cx(`locale-${locale}`, `lang-${lang}`)}>
          <Main />
          <NextScript />
        </body>
      </html>
    );
  }
}

// To load the initial state on the server, we attached withFork wrapper to _document component
const enhance = withFork({ debug: false });

export default enhance(AppDocument);

Новая версия содержащая измененный with-fork не работает так как судя по всему ожидает "чистый" Document.
Выдает такие ошибки
image

@weyheyhey weyheyhey self-assigned this May 18, 2020
weyheyhey added a commit that referenced this issue May 18, 2020
@7iomka 7iomka closed this as completed May 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants