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: make context prop optional in Provider #200

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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