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

Commit

Permalink
fix: remove invalid inheritance #4
Browse files Browse the repository at this point in the history
  • Loading branch information
weyheyhey committed May 18, 2020
1 parent 446d28e commit 8b9f411
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/with-fork.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from "react";
import NextDocument, { DocumentContext, DocumentProps } from "next/document";
import { fork, serialize, allSettled } from "effector/fork";
import cookies from "next-cookies";
Expand All @@ -24,7 +25,12 @@ export interface WithForkConfig {

export function withFork({ debug }: WithForkConfig = {}) {
return (Document: typeof NextDocument) =>
class WithForkDocument extends Document {
class WithForkDocument extends React.Component<WrappedDocumentProps> {
static renderDocument = Document.renderDocument;
static headTagsMiddleware = Document.headTagsMiddleware;
static bodyTagsMiddleware = Document.bodyTagsMiddleware;
static htmlPropsMiddleware = Document.htmlPropsMiddleware;

static async getInitialProps(ctx: DocumentContext) {
const originalRenderPage = ctx.renderPage;
const startUnits = getStartUnits(originalRenderPage);
Expand Down Expand Up @@ -79,5 +85,9 @@ export function withFork({ debug }: WithForkConfig = {}) {

props.__NEXT_DATA__[INITIAL_STATE_KEY] = props.initialState;
}

render() {
return <Document {...this.props} />;
}
};
}
13 changes: 10 additions & 3 deletions src/with-hydrate.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from "react";
import NextApp, { AppProps } from "next/app";
import { hydrate } from "effector/fork";

Expand All @@ -13,15 +14,21 @@ declare global {
export function withHydrate() {
const isServer = typeof window === "undefined";

return function (App: typeof NextApp) {
return class WithHydrateApp extends App {
return (App: typeof NextApp) =>
class WithHydrateApp extends React.Component<AppProps> {
static origGetInitialProps = App.origGetInitialProps;
static getInitialProps = App.getInitialProps;

constructor(props: AppProps) {
super(props);

if (isServer) return;

hydrate(domain, { values: window.__NEXT_DATA__[INITIAL_STATE_KEY] });
}

render() {
return <App {...this.props} />;
}
};
};
}
8 changes: 5 additions & 3 deletions src/with-start.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { NextPage } from "next";
import { NextPageContext, NextComponentType } from "next";
import { AppContext } from "next/app";
import { Unit } from "effector";
import App from "next/app";

import { PageContext } from "./types";
import { START_UNIT_KEY } from "./lib";

/* eslint-disable @typescript-eslint/no-explicit-any */

type TargetComponentType<C> = NextComponentType<C, any, any>;

export function withStart(unit: Unit<PageContext>) {
return (component: typeof App | NextPage<any>) => {
return (component: TargetComponentType<AppContext> | TargetComponentType<NextPageContext>) => {
const originalGetInitialProps = component.getInitialProps;

// We cancel static optimization for a component
Expand Down

0 comments on commit 8b9f411

Please sign in to comment.