Skip to content

Commit

Permalink
feat(inbound-filters): Add react hydration errors
Browse files Browse the repository at this point in the history
  • Loading branch information
priscilawebdev committed Mar 1, 2023
1 parent b27ef04 commit deacd7d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/sentry/api/endpoints/project_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ def put(self, request: Request, project) -> Response:
"sentry:reprocessing_active",
bool(options["sentry:reprocessing_active"]),
)
if "filters:react-hydration-errors" in options:
project.update_option(
"filters:react-hydration-errors",
bool(options["filters:react-hydration-errors"]),
)
if "filters:blacklisted_ips" in options:
project.update_option(
"sentry:blacklisted_ips",
Expand Down
1 change: 1 addition & 0 deletions src/sentry/api/serializers/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def format_options(attrs: defaultdict(dict)):
"sentry:performance_issue_creation_rate"
),
"filters:blacklisted_ips": "\n".join(options.get("sentry:blacklisted_ips", [])),
"filters:react-hydration-errors": bool(options.get("filters:react-hydration-errors", True)),
f"filters:{FilterTypes.RELEASES}": "\n".join(
options.get(f"sentry:{FilterTypes.RELEASES}", [])
),
Expand Down
23 changes: 20 additions & 3 deletions src/sentry/relay/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,31 @@ def get_filter_settings(project: Project) -> Mapping[str, Any]:
settings = _load_filter_settings(flt, project)
filter_settings[filter_id] = settings

error_messages = []
if features.has("projects:custom-inbound-filters", project):
invalid_releases = project.get_option(f"sentry:{FilterTypes.RELEASES}")
if invalid_releases:
filter_settings["releases"] = {"releases": invalid_releases}

error_messages = project.get_option(f"sentry:{FilterTypes.ERROR_MESSAGES}")
if error_messages:
filter_settings["errorMessages"] = {"patterns": error_messages}
error_messages += project.get_option(f"sentry:{FilterTypes.ERROR_MESSAGES}") or []

enable_react = project.get_option("filters:react-hydration-errors")
if enable_react:
error_messages += [
# Hydration failed because the initial UI does not match what was rendered on the server.
"https://reactjs.org/docs/error-decoder.html?invariant=418",
# The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.
"https://reactjs.org/docs/error-decoder.html?invariant=419",
# There was an error while hydrating this Suspense boundary. Switched to client rendering.
"https://reactjs.org/docs/error-decoder.html?invariant=422",
# There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
"https://reactjs.org/docs/error-decoder.html?invariant=423",
# Text content does not match server-rendered HTML.
"https://reactjs.org/docs/error-decoder.html?invariant=425",
]

if error_messages:
filter_settings["errorMessages"] = {"patterns": error_messages}

blacklisted_ips = project.get_option("sentry:blacklisted_ips")
if blacklisted_ips:
Expand Down
2 changes: 1 addition & 1 deletion static/app/data/forms/inboundFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const globHelpText = tct('Allows [link:glob pattern matching].', {
link: <ExternalLink href="https://en.wikipedia.org/wiki/Glob_(programming)" />,
});

const getOptionsData = (data: object) => ({options: data});
export const getOptionsData = (data: object) => ({options: data});

const formGroups: JsonFormObject[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
PanelItem,
} from 'sentry/components/panels';
import Switch from 'sentry/components/switchButton';
import filterGroups, {customFilterFields} from 'sentry/data/forms/inboundFilters';
import filterGroups, {
customFilterFields,
getOptionsData,
} from 'sentry/data/forms/inboundFilters';
import {t} from 'sentry/locale';
import HookStore from 'sentry/stores/hookStore';
import ProjectsStore from 'sentry/stores/projectsStore';
Expand Down Expand Up @@ -359,6 +362,31 @@ class ProjectFiltersSettings extends AsyncComponent<Props, State> {
</PanelItem>
);
})}
<PanelItem noPadding>
<NestedForm
apiMethod="PUT"
apiEndpoint={projectEndpoint}
initialData={{
'filters:react-hydration-errors':
project.options?.['filters:react-hydration-errors'],
}}
saveOnBlur
onSubmitSuccess={this.handleSubmit}
>
<FieldFromConfig
getData={getOptionsData}
field={{
type: 'boolean',
name: 'filters:react-hydration-errors',
label: t('Filter out hydration errors'),
help: t(
'React falls back to do a full re-render on a page and these errors are often not actionable.'
),
disabled: !hasAccess,
}}
/>
</NestedForm>
</PanelItem>
</PanelBody>
</Panel>

Expand Down

0 comments on commit deacd7d

Please sign in to comment.