Skip to content

Commit

Permalink
fix: make context prop optional in Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
staylor committed Nov 21, 2023
1 parent 9c1cc27 commit b903f50
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 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-helmet-async",
"version": "2.0.0",
"version": "2.0.1",
"description": "Thread-safe Helmet for React 16+ and friends",
"sideEffects": false,
"main": "./lib/index.js",
Expand Down
8 changes: 7 additions & 1 deletion src/HelmetData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ interface HelmetDataContext {
helmet: HelmetServerState;
}

export const isDocument = !!(
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
);

export default class HelmetData implements HelmetDataType {
instances = [];
canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
canUseDOM = isDocument;
context: HelmetDataContext;

value = {
Expand Down
8 changes: 3 additions & 5 deletions src/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import type { PropsWithChildren } from 'react';
import React, { Component } from 'react';

import HelmetData from './HelmetData';
import HelmetData, { isDocument } from './HelmetData';
import type { HelmetServerState } from './types';

const defaultValue = {};

export const Context = React.createContext(defaultValue);

interface ProviderProps {
context: {
context?: {
helmet: HelmetServerState;
};
}

const canUseDOM = typeof document !== 'undefined';

export default class HelmetProvider extends Component<PropsWithChildren<ProviderProps>> {
static canUseDOM = canUseDOM;
static canUseDOM = isDocument;

helmetData: HelmetData;

Expand Down

0 comments on commit b903f50

Please sign in to comment.