Repository: go-gitea/gitea
File: web_src/js/features/repo-graph.ts (TypeScript)

Code before:
    toggleClass(elColorColored, 'active', mode === 'colored');

    const params = new URLSearchParams(window.location.search);
    params.set('mode', mode);
    window.history.replaceState(null, '', `?${params.toString()}`);
    for (const link of document.querySelectorAll('#pagination .pagination a')) {
      const href = link.getAttribute('href');
      if (!href) continue;
      const url = new URL(href, window.location.href);
      const params = url.searchParams;
      params.set('mode', mode);
      url.search = `?${params.toString()}`;
      link.setAttribute('href', url.href);
    }
  };
  elColorMonochrome.addEventListener('click', () => toggleColorMode('monochrome'));
  elColorColored.addEventListener('click', () => toggleColorMode('colored'));

  const elGraphBody = document.querySelector<HTMLElement>('#git-graph-body');
  const url = new URL(window.location.href);
  const params = url.searchParams;
  const loadGitGraph = async () => {
    const queryString = params.toString();
    const ajaxUrl = new URL(url);
    ajaxUrl.searchParams.set('div-only', 'true');
    window.history.replaceState({}, '', queryString ? `?${queryString}` : window.location.pathname);

    elGraphBody.classList.add('is-loading');
    try {
      const resp = await GET(ajaxUrl.toString());
      elGraphBody.innerHTML = await resp.text();
    } finally {
      elGraphBody.classList.remove('is-loading');
    }
  };

  const dropdownSelected = params.getAll('branch');
  if (params.has('hide-pr-refs') && params.get('hide-pr-refs') === 'true') {
    dropdownSelected.splice(0, 0, '...flow-hide-pr-refs');
  }

  const $dropdown = fomanticQuery('#flow-select-refs-dropdown');
  $dropdown.dropdown({clearable: true});
  $dropdown.dropdown('set selected', dropdownSelected);
  // must add the callback after setting the selected items, otherwise each "selected" item will trigger the callback
  $dropdown.dropdown('setting', {
    onRemove(toRemove: string) {
      if (toRemove === '...flow-hide-pr-refs') {
        params.delete('hide-pr-refs');
      } else {
        const branches = params.getAll('branch');

Review comment (suggestion):
```suggestion
    window.history.replaceState(null, '', queryString ? `?${queryString}` : window.location.pathname);
```

Check if those are all cases in the file.

Code after:
    toggleClass(elColorColored, 'active', mode === 'colored');

    const params = new URLSearchParams(window.location.search);
    params.set('mode', mode);
    window.history.replaceState(null, '', `?${params.toString()}`);
    for (const link of document.querySelectorAll('#pagination .pagination a')) {
      const href = link.getAttribute('href');
      if (!href) continue;
      const url = new URL(href, window.location.href);
      const params = url.searchParams;
      params.set('mode', mode);
      url.search = `?${params.toString()}`;
      link.setAttribute('href', url.href);
    }
  };
  elColorMonochrome.addEventListener('click', () => toggleColorMode('monochrome'));
  elColorColored.addEventListener('click', () => toggleColorMode('colored'));

  const elGraphBody = document.querySelector<HTMLElement>('#git-graph-body');
  const url = new URL(window.location.href);
  const params = url.searchParams;
  const loadGitGraph = async () => {
    const queryString = params.toString();
    const ajaxUrl = new URL(url);
    ajaxUrl.searchParams.set('div-only', 'true');
    window.history.replaceState(null, '', queryString ? `?${queryString}` : window.location.pathname);

    elGraphBody.classList.add('is-loading');
    try {
      const resp = await GET(ajaxUrl.toString());
      elGraphBody.innerHTML = await resp.text();
    } finally {
      elGraphBody.classList.remove('is-loading');
    }
  };

  const dropdownSelected = params.getAll('branch');
  if (params.has('hide-pr-refs') && params.get('hide-pr-refs') === 'true') {
    dropdownSelected.splice(0, 0, '...flow-hide-pr-refs');
  }

  const $dropdown = fomanticQuery('#flow-select-refs-dropdown');
  $dropdown.dropdown({clearable: true});
  $dropdown.dropdown('set selected', dropdownSelected);
  // must add the callback after setting the selected items, otherwise each "selected" item will trigger the callback
  $dropdown.dropdown('setting', {
    onRemove(toRemove: string) {
      if (toRemove === '...flow-hide-pr-refs') {
        params.delete('hide-pr-refs');
      } else {
        const branches = params.getAll('branch');