Skip to content

Commit

Permalink
fix: Next.js Error document is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenChang618 committed Aug 12, 2019
1 parent 2fda562 commit 12ee736
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-keep-alive",
"version": "2.3.0",
"version": "2.4.0",
"description": "Package will allow components to maintain their status, to avoid repeated re-rendering.",
"author": "Shen Chang",
"homepage": "https://github.com/StructureBuilder/react-keep-alive",
Expand Down
10 changes: 9 additions & 1 deletion src/components/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface IKeepAliveProviderProps {
export default class KeepAliveProvider extends React.PureComponent<IKeepAliveProviderProps> implements IKeepAliveProviderImpl {
public static displayName = keepAliveProviderTypeName;

public storeElement = createStoreElement();
public storeElement: HTMLElement;

// Sometimes data that changes with setState cannot be synchronized, so force refresh
public cache: ICache = Object.create(null);
Expand All @@ -64,6 +64,11 @@ export default class KeepAliveProvider extends React.PureComponent<IKeepAlivePro

public providerIdentification: string = createUniqueIdentification();

public componentDidMount() {
this.storeElement = createStoreElement();
this.forceUpdate();
}

public componentDidUpdate() {
if (this.needRerender) {
this.needRerender = false;
Expand Down Expand Up @@ -124,6 +129,9 @@ export default class KeepAliveProvider extends React.PureComponent<IKeepAlivePro
include,
exclude,
} = this.props;
if (!storeElement) {
return null;
}
return (
<KeepAliveContext.Provider
value={{
Expand Down

0 comments on commit 12ee736

Please sign in to comment.