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

ref(js): Remove custom usage of DocumentTitle #45165

Merged
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
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