Skip to content

Commit

Permalink
[Discover] Switch from "at" to "charAt" for better browser support (e…
Browse files Browse the repository at this point in the history
…lastic#156474)

From the community forum: users can't access Discover on older browsers.

```
TypeError: t.at is not a function
at http://xxx:5601/61109/bundles/plugin/data/kibana/data.plugin.js:1:312992
at Array.forEach ()
at n (http://xxx:5601/61109/bundles/plugin/data/kibana/data.plugin.js:1:312956)
at s (http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:10138)
at http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:10215
at Array.map ()
at a (http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:10207)
at http://xxx:5601/61109/bundles/plugin/discover/kibana/discover.chunk.0.js:1:8442
at http://xxx:5601/61109/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:334:27724
at t.s._next (http://xxx:5601/61109/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:6:33456)
```

- https://discuss.elastic.co/t/update-to-8-7-0/329525
-
https://discuss.elastic.co/t/elastic-8-7-0-error-in-discover-tab/332329/2

## Summary

This PR replaces `String` `.at` usage with `.charAt` so it does not
require a polyfill for older browsers.
  • Loading branch information
jughosta authored May 4, 2023
1 parent 0a9bbe7 commit 396a2b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/plugins/data/common/search/tabify/tabify_docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ describe('tabify_docs', () => {
_size: 12,
_score: 77,
_source: {},
invalid_meta: 'test',
},
],
},
Expand All @@ -216,7 +217,7 @@ describe('tabify_docs', () => {
},
},
},
metaFields: ['_id', '_index', '_score', '_type', '_size'],
metaFields: ['_id', '_index', '_score', '_type', '_size', 'invalid_meta'],
fieldFormats: fieldFormats as any,
});
const table = tabifyDocs(responsePlugin, dataView);
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/common/search/tabify/tabify_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export function flattenHit(hit: Hit, indexPattern?: DataView, params?: TabifyDoc

// Merge all valid meta fields into the flattened object
indexPattern?.metaFields?.forEach((fieldName) => {
const isExcludedMetaField = EXCLUDED_META_FIELDS.includes(fieldName) || fieldName.at(0) !== '_';
const isExcludedMetaField =
EXCLUDED_META_FIELDS.includes(fieldName) || fieldName.charAt(0) !== '_';
if (isExcludedMetaField) {
return;
}
Expand Down

0 comments on commit 396a2b6

Please sign in to comment.