-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[React@18 failing test] fix visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid #196308
Conversation
Pinging @elastic/appex-sharedux (Team:SharedUX) |
@elasticmachine merge upstream |
💔 Build Failed
Failed CI StepsTest FailuresMetrics [docs]Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History |
@elasticmachine merge upstream |
try { | ||
updateTimeBuckets(this, calculateBounds, buckets); | ||
} catch (e) { | ||
// swallow the error even though the agg is misconfigured |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is safe and shouldn't break anything because this is inside the accessor and previosly threw error only on a first attempt to access. Now at least it would be consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-only review, change LGTM from the Data Discovery side. We should also get approval from @elastic/kibana-visualizations too.
@elasticmachine merge upstream |
Starting backport for target branches: 8.x |
…ize area charts date histogram when no time filter interval errors should show error when calendar interval invalid (elastic#196308) ## Summary close elastic#196303 We're working on upgrading Kibana to React@18 (in Legacy Mode). There are a couple failing tests when running React@18 in Legacy mode and this is one of them visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid. [Failure](https://buildkite.com/elastic/kibana-pull-request/builds/236562#019222ec-e8d1-4465-ada3-fd923283b6f4) ![Image](https://github.com/user-attachments/assets/2cdaca3c-9ccf-4208-b6f3-6975588eb5fe) ---- I investigated the problem and understand what is not working and suggesting this simple fix, but open to any other approaches or suggestions. To Reproduce the failing tests: 1. Create aggregation based viz, e.g. Area Chart 2. Add data histogram agg 3. Change minimum interval to a invalid value (for example, "f") 4. Change minimum interval to another invalid value ("ff") React@18 failure: https://github.com/user-attachments/assets/f8684b48-fb24-4500-a762-2a116ed55297 The error is thrown from here in the reducer: https://github.com/elastic/kibana/blob/23e0e1e61c6df451cc38763b53a6e2db5518b9f4/src/plugins/vis_default_editor/public/components/sidebar/state/reducers.ts#L82 When we try to update the state using 2nd invalid value, the error is thrown when we try to serialize the current agg with previous invalid value. This code is exececuted when we call `agg.serialize`: https://github.com/elastic/kibana/blob/5ed698182887e18d2aa6c4b6782cc636a45a1472/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts#L200-L202 **Why don't we see this failure in React@17?** In React@17 we don't see an error screen, but we only see a log in the console. > TypeError: "f" is not a valid interval. It turns out that React@17 consistently executed that reducer twice. first time during dispatch and second time during rendering. This shouldn't be a problem because reducers are supposed to be pure (without side-effects). **But in this case calling `agg.serialize` only throws an error when called the first time**! So in React@17 the reducer was called the first time, the error was swallowed, then it was called the 2nd time and, since the `TimeBucket` was cached, there was no error anymore, so it never bubbled up during rendering. The root cause of inconsitent behaviour is here: https://github.com/elastic/kibana/blob/8afbbc008222dee377aab568a639466d49c56306/src/plugins/data/common/search/aggs/buckets/date_histogram.ts#L111-L121 when `get()` called first time we create buckets and cache them. but we cache them before calling `updateTimeBuckets` which is where the error happens. To fix this issue, we should make the reducer pure. One approach is to swallow that error so that the call to `agg.serialize()` is consistent. Another approach could be to always throw that error, but then a larger refactor is needed and this likely a more risky and impactfull change. (cherry picked from commit feb5b79)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid (#196308) (#197198) # Backport This will backport the following commits from `main` to `8.x`: - [[React@18 failing test] fix visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid (#196308)](#196308) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Anton Dosov","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-22T09:50:15Z","message":"[React@18 failing test] fix visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid (#196308)\n\n## Summary\r\n\r\nclose https://github.com/elastic/kibana/issues/196303\r\n\r\nWe're working on upgrading Kibana to React@18 (in Legacy Mode). There\r\nare a couple failing tests when running React@18 in Legacy mode and this\r\nis one of them\r\n\r\nvisualize app - new charts library visualize area charts date histogram\r\nwhen no time filter interval errors should show error when calendar\r\ninterval invalid.\r\n[Failure](https://buildkite.com/elastic/kibana-pull-request/builds/236562#019222ec-e8d1-4465-ada3-fd923283b6f4)\r\n\r\n\r\n![Image](https://github.com/user-attachments/assets/2cdaca3c-9ccf-4208-b6f3-6975588eb5fe)\r\n\r\n\r\n---- \r\n\r\n\r\nI investigated the problem and understand what is not working and\r\nsuggesting this simple fix, but open to any other approaches or\r\nsuggestions.\r\n\r\n\r\nTo Reproduce the failing tests: \r\n\r\n1. Create aggregation based viz, e.g. Area Chart\r\n2. Add data histogram agg\r\n3. Change minimum interval to a invalid value (for example, \"f\")\r\n4. Change minimum interval to another invalid value (\"ff\")\r\n\r\nReact@18 failure: \r\n\r\n\r\nhttps://github.com/user-attachments/assets/f8684b48-fb24-4500-a762-2a116ed55297\r\n\r\nThe error is thrown from here in the reducer: \r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/23e0e1e61c6df451cc38763b53a6e2db5518b9f4/src/plugins/vis_default_editor/public/components/sidebar/state/reducers.ts#L82\r\n\r\nWhen we try to update the state using 2nd invalid value, the error is\r\nthrown when we try to serialize the current agg with previous invalid\r\nvalue.\r\n\r\nThis code is exececuted when we call `agg.serialize`:\r\n \r\n\r\nhttps://github.com/elastic/kibana/blob/5ed698182887e18d2aa6c4b6782cc636a45a1472/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts#L200-L202\r\n\r\n\r\n**Why don't we see this failure in React@17?**\r\n\r\nIn React@17 we don't see an error screen, but we only see a log in the\r\nconsole.\r\n\r\n> TypeError: \"f\" is not a valid interval.\r\n\r\nIt turns out that React@17 consistently executed that reducer twice.\r\nfirst time during dispatch and second time during rendering. This\r\nshouldn't be a problem because reducers are supposed to be pure (without\r\nside-effects). **But in this case calling `agg.serialize` only throws an\r\nerror when called the first time**! So in React@17 the reducer was\r\ncalled the first time, the error was swallowed, then it was called the\r\n2nd time and, since the `TimeBucket` was cached, there was no error\r\nanymore, so it never bubbled up during rendering.\r\n\r\nThe root cause of inconsitent behaviour is here:\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/8afbbc008222dee377aab568a639466d49c56306/src/plugins/data/common/search/aggs/buckets/date_histogram.ts#L111-L121\r\n\r\nwhen `get()` called first time we create buckets and cache them. but we\r\ncache them before calling `updateTimeBuckets` which is where the error\r\nhappens.\r\n\r\n\r\nTo fix this issue, we should make the reducer pure. One approach is to\r\nswallow that error so that the call to `agg.serialize()` is consistent.\r\nAnother approach could be to always throw that error, but then a larger\r\nrefactor is needed and this likely a more risky and impactfull change.","sha":"feb5b79a96162b0259ecfd5d8216050cd074a3a4","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:SharedUX","backport:prev-minor"],"title":"[React@18 failing test] fix visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid","number":196308,"url":"https://github.com/elastic/kibana/pull/196308","mergeCommit":{"message":"[React@18 failing test] fix visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid (#196308)\n\n## Summary\r\n\r\nclose https://github.com/elastic/kibana/issues/196303\r\n\r\nWe're working on upgrading Kibana to React@18 (in Legacy Mode). There\r\nare a couple failing tests when running React@18 in Legacy mode and this\r\nis one of them\r\n\r\nvisualize app - new charts library visualize area charts date histogram\r\nwhen no time filter interval errors should show error when calendar\r\ninterval invalid.\r\n[Failure](https://buildkite.com/elastic/kibana-pull-request/builds/236562#019222ec-e8d1-4465-ada3-fd923283b6f4)\r\n\r\n\r\n![Image](https://github.com/user-attachments/assets/2cdaca3c-9ccf-4208-b6f3-6975588eb5fe)\r\n\r\n\r\n---- \r\n\r\n\r\nI investigated the problem and understand what is not working and\r\nsuggesting this simple fix, but open to any other approaches or\r\nsuggestions.\r\n\r\n\r\nTo Reproduce the failing tests: \r\n\r\n1. Create aggregation based viz, e.g. Area Chart\r\n2. Add data histogram agg\r\n3. Change minimum interval to a invalid value (for example, \"f\")\r\n4. Change minimum interval to another invalid value (\"ff\")\r\n\r\nReact@18 failure: \r\n\r\n\r\nhttps://github.com/user-attachments/assets/f8684b48-fb24-4500-a762-2a116ed55297\r\n\r\nThe error is thrown from here in the reducer: \r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/23e0e1e61c6df451cc38763b53a6e2db5518b9f4/src/plugins/vis_default_editor/public/components/sidebar/state/reducers.ts#L82\r\n\r\nWhen we try to update the state using 2nd invalid value, the error is\r\nthrown when we try to serialize the current agg with previous invalid\r\nvalue.\r\n\r\nThis code is exececuted when we call `agg.serialize`:\r\n \r\n\r\nhttps://github.com/elastic/kibana/blob/5ed698182887e18d2aa6c4b6782cc636a45a1472/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts#L200-L202\r\n\r\n\r\n**Why don't we see this failure in React@17?**\r\n\r\nIn React@17 we don't see an error screen, but we only see a log in the\r\nconsole.\r\n\r\n> TypeError: \"f\" is not a valid interval.\r\n\r\nIt turns out that React@17 consistently executed that reducer twice.\r\nfirst time during dispatch and second time during rendering. This\r\nshouldn't be a problem because reducers are supposed to be pure (without\r\nside-effects). **But in this case calling `agg.serialize` only throws an\r\nerror when called the first time**! So in React@17 the reducer was\r\ncalled the first time, the error was swallowed, then it was called the\r\n2nd time and, since the `TimeBucket` was cached, there was no error\r\nanymore, so it never bubbled up during rendering.\r\n\r\nThe root cause of inconsitent behaviour is here:\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/8afbbc008222dee377aab568a639466d49c56306/src/plugins/data/common/search/aggs/buckets/date_histogram.ts#L111-L121\r\n\r\nwhen `get()` called first time we create buckets and cache them. but we\r\ncache them before calling `updateTimeBuckets` which is where the error\r\nhappens.\r\n\r\n\r\nTo fix this issue, we should make the reducer pure. One approach is to\r\nswallow that error so that the call to `agg.serialize()` is consistent.\r\nAnother approach could be to always throw that error, but then a larger\r\nrefactor is needed and this likely a more risky and impactfull change.","sha":"feb5b79a96162b0259ecfd5d8216050cd074a3a4"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196308","number":196308,"mergeCommit":{"message":"[React@18 failing test] fix visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid (#196308)\n\n## Summary\r\n\r\nclose https://github.com/elastic/kibana/issues/196303\r\n\r\nWe're working on upgrading Kibana to React@18 (in Legacy Mode). There\r\nare a couple failing tests when running React@18 in Legacy mode and this\r\nis one of them\r\n\r\nvisualize app - new charts library visualize area charts date histogram\r\nwhen no time filter interval errors should show error when calendar\r\ninterval invalid.\r\n[Failure](https://buildkite.com/elastic/kibana-pull-request/builds/236562#019222ec-e8d1-4465-ada3-fd923283b6f4)\r\n\r\n\r\n![Image](https://github.com/user-attachments/assets/2cdaca3c-9ccf-4208-b6f3-6975588eb5fe)\r\n\r\n\r\n---- \r\n\r\n\r\nI investigated the problem and understand what is not working and\r\nsuggesting this simple fix, but open to any other approaches or\r\nsuggestions.\r\n\r\n\r\nTo Reproduce the failing tests: \r\n\r\n1. Create aggregation based viz, e.g. Area Chart\r\n2. Add data histogram agg\r\n3. Change minimum interval to a invalid value (for example, \"f\")\r\n4. Change minimum interval to another invalid value (\"ff\")\r\n\r\nReact@18 failure: \r\n\r\n\r\nhttps://github.com/user-attachments/assets/f8684b48-fb24-4500-a762-2a116ed55297\r\n\r\nThe error is thrown from here in the reducer: \r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/23e0e1e61c6df451cc38763b53a6e2db5518b9f4/src/plugins/vis_default_editor/public/components/sidebar/state/reducers.ts#L82\r\n\r\nWhen we try to update the state using 2nd invalid value, the error is\r\nthrown when we try to serialize the current agg with previous invalid\r\nvalue.\r\n\r\nThis code is exececuted when we call `agg.serialize`:\r\n \r\n\r\nhttps://github.com/elastic/kibana/blob/5ed698182887e18d2aa6c4b6782cc636a45a1472/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts#L200-L202\r\n\r\n\r\n**Why don't we see this failure in React@17?**\r\n\r\nIn React@17 we don't see an error screen, but we only see a log in the\r\nconsole.\r\n\r\n> TypeError: \"f\" is not a valid interval.\r\n\r\nIt turns out that React@17 consistently executed that reducer twice.\r\nfirst time during dispatch and second time during rendering. This\r\nshouldn't be a problem because reducers are supposed to be pure (without\r\nside-effects). **But in this case calling `agg.serialize` only throws an\r\nerror when called the first time**! So in React@17 the reducer was\r\ncalled the first time, the error was swallowed, then it was called the\r\n2nd time and, since the `TimeBucket` was cached, there was no error\r\nanymore, so it never bubbled up during rendering.\r\n\r\nThe root cause of inconsitent behaviour is here:\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/8afbbc008222dee377aab568a639466d49c56306/src/plugins/data/common/search/aggs/buckets/date_histogram.ts#L111-L121\r\n\r\nwhen `get()` called first time we create buckets and cache them. but we\r\ncache them before calling `updateTimeBuckets` which is where the error\r\nhappens.\r\n\r\n\r\nTo fix this issue, we should make the reducer pure. One approach is to\r\nswallow that error so that the call to `agg.serialize()` is consistent.\r\nAnother approach could be to always throw that error, but then a larger\r\nrefactor is needed and this likely a more risky and impactfull change.","sha":"feb5b79a96162b0259ecfd5d8216050cd074a3a4"}}]}] BACKPORT--> Co-authored-by: Anton Dosov <[email protected]>
Summary
close #196303
We're working on upgrading Kibana to React@18 (in Legacy Mode). There are a couple failing tests when running React@18 in Legacy mode and this is one of them
visualize app - new charts library visualize area charts date histogram when no time filter interval errors should show error when calendar interval invalid. Failure
I investigated the problem and understand what is not working and suggesting this simple fix, but open to any other approaches or suggestions.
To Reproduce the failing tests:
React@18 failure:
error.mov
The error is thrown from here in the reducer:
kibana/src/plugins/vis_default_editor/public/components/sidebar/state/reducers.ts
Line 82 in 23e0e1e
When we try to update the state using 2nd invalid value, the error is thrown when we try to serialize the current agg with previous invalid value.
This code is exececuted when we call
agg.serialize
:kibana/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts
Lines 200 to 202 in 5ed6981
Why don't we see this failure in React@17?
In React@17 we don't see an error screen, but we only see a log in the console.
It turns out that React@17 consistently executed that reducer twice. first time during dispatch and second time during rendering. This shouldn't be a problem because reducers are supposed to be pure (without side-effects). But in this case calling
agg.serialize
only throws an error when called the first time! So in React@17 the reducer was called the first time, the error was swallowed, then it was called the 2nd time and, since theTimeBucket
was cached, there was no error anymore, so it never bubbled up during rendering.The root cause of inconsitent behaviour is here:
kibana/src/plugins/data/common/search/aggs/buckets/date_histogram.ts
Lines 111 to 121 in 8afbbc0
when
get()
called first time we create buckets and cache them. but we cache them before callingupdateTimeBuckets
which is where the error happens.To fix this issue, we should make the reducer pure. One approach is to swallow that error so that the call to
agg.serialize()
is consistent. Another approach could be to always throw that error, but then a larger refactor is needed and this likely a more risky and impactfull change.