Skip to content

Commit

Permalink
ref(js): Remove custom usage of DocumentTitle (#45165)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser authored Feb 27, 2023
1 parent 3be7d5e commit e81b9f4
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions static/app/views/projects/projectContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Component, createRef} from 'react';
import DocumentTitle from 'react-document-title';
import {Component} from 'react';
import styled from '@emotion/styled';

import {fetchOrgMembers} from 'sentry/actionCreators/members';
Expand All @@ -10,6 +9,7 @@ import * as Layout from 'sentry/components/layouts/thirds';
import LoadingError from 'sentry/components/loadingError';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import MissingProjectMembership from 'sentry/components/projects/missingProjectMembership';
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
import {t} from 'sentry/locale';
import SentryTypes from 'sentry/sentryTypes';
import MemberListStore from 'sentry/stores/memberListStore';
Expand Down Expand Up @@ -101,7 +101,7 @@ class ProjectContext extends Component<Props, State> {
}
}

componentDidUpdate(prevProps: Props, prevState: State) {
componentDidUpdate(prevProps: Props, _prevState: State) {
if (prevProps.projectId !== this.props.projectId) {
this.fetchData();
}
Expand All @@ -116,32 +116,13 @@ class ProjectContext extends Component<Props, State> {
if (prevProps.projects.length !== this.props.projects.length) {
this.fetchData();
}

// Call forceUpdate() on <DocumentTitle/> if either project or organization
// state has changed. This is because <DocumentTitle/>'s shouldComponentUpdate()
// returns false unless props differ; meaning context changes for project/org
// do NOT trigger renders for <DocumentTitle/> OR any subchildren. The end result
// being that child elements that listen for context changes on project/org will
// NOT update (without this hack).
// See: https://github.com/gaearon/react-document-title/issues/35

// intentionally shallow comparing references
if (prevState.project !== this.state.project) {
const docTitle = this.docTitleRef.current;
if (!docTitle) {
return;
}
docTitle.forceUpdate();
}
}

componentWillUnmount() {
this.unsubscribeMembers();
this.unsubscribeProjects();
}

docTitleRef = createRef<DocumentTitle>();

unsubscribeProjects = ProjectsStore.listen(
(projectIds: Set<string>) => this.onProjectChange(projectIds),
undefined
Expand Down Expand Up @@ -287,9 +268,9 @@ class ProjectContext extends Component<Props, State> {

render() {
return (
<DocumentTitle ref={this.docTitleRef} title={this.getTitle()}>
<SentryDocumentTitle noSuffix title={this.getTitle()}>
{this.renderBody()}
</DocumentTitle>
</SentryDocumentTitle>
);
}
}
Expand Down

0 comments on commit e81b9f4

Please sign in to comment.