Skip to content

Commit f1591d3

Browse files
authored
Dedupe unknown query params from feature flag query params. (#6824)
Since #6784 we have seen the unusual behavior where query params for feature flags will be duplicated on the command line. For example, if we load `localhost:6006/?showFlags=` it will be rewritten as `localhost:6006/?showFlags=&showFlags=`. This change fixes this by deduplicating "unknown" flags with known feature flag query params.
1 parent c3fd2b5 commit f1591d3

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

tensorboard/webapp/routes/dashboard_deeplink_provider.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
import {Injectable} from '@angular/core';
1616
import {Store} from '@ngrx/store';
1717
import {combineLatest, Observable} from 'rxjs';
18-
import {map} from 'rxjs/operators';
18+
import {combineLatestWith, map} from 'rxjs/operators';
1919
import {DeepLinkProvider} from '../app_routing/deep_link_provider';
2020
import {SerializableQueryParams} from '../app_routing/types';
2121
import {State} from '../app_state';
@@ -152,16 +152,18 @@ export class DashboardDeepLinkProvider extends DeepLinkProvider {
152152
return [{key: RUN_FILTER_KEY, value}];
153153
})
154154
),
155-
store
156-
.select(selectors.getUnknownQueryParams)
157-
.pipe(
158-
map((queryParams) =>
159-
Object.entries(queryParams).map(([key, value]) => ({key, value}))
160-
)
161-
),
162155
]).pipe(
163-
map((queryParamList) => {
164-
return queryParamList.flat();
156+
combineLatestWith(store.select(selectors.getUnknownQueryParams)),
157+
map(([queryParamList, unknownQueryParams]) => {
158+
// Filter out any known params from unknownQueryParams.
159+
const knownQueryParamKeys = new Set(
160+
queryParamList.flat().map((qp) => qp.key)
161+
);
162+
const filteredUnknownQueryParams = Object.entries(unknownQueryParams)
163+
.filter(([key]) => !knownQueryParamKeys.has(key))
164+
.map(([key, value]) => ({key, value}));
165+
166+
return [...queryParamList, ...filteredUnknownQueryParams].flat();
165167
})
166168
);
167169
}

tensorboard/webapp/routes/dashboard_deeplink_provider_test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,30 @@ describe('core deeplink provider', () => {
400400
]);
401401
});
402402

403+
it('dedupes unknown query params with feature flags', () => {
404+
store.overrideSelector(selectors.getOverriddenFeatureFlags, {
405+
enabledExperimentalPlugins: ['foo', 'bar', 'baz'],
406+
showFlags: '',
407+
});
408+
store.overrideSelector(selectors.getUnknownQueryParams, {
409+
unknown1: 'unknown1_value',
410+
unknown2: 'unknown2_value',
411+
// Should be ignored since it is also a feature flag query param.
412+
experimentalPlugin:
413+
'this_is_known_but_has_different_value_for_some_reason',
414+
// Should be ignored since it is also a feature flag query param.
415+
showFlags: 'this_is_also_known_and_also_has_different_value',
416+
});
417+
store.refreshState();
418+
419+
expect(queryParamsSerialized[queryParamsSerialized.length - 1]).toEqual([
420+
{key: 'experimentalPlugin', value: 'foo,bar,baz'},
421+
{key: 'showFlags', value: ''},
422+
{key: 'unknown1', value: 'unknown1_value'},
423+
{key: 'unknown2', value: 'unknown2_value'},
424+
]);
425+
});
426+
403427
describe('runs', () => {
404428
describe('color group', () => {
405429
it('does not put state in the URL when user set color group is null', () => {

0 commit comments

Comments
 (0)