Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to

### Fixed

- Fix issue where back button must be pressed 3 times to go back once from the
Workflow canvas [#4812](https://github.com/OpenFn/lightning/issues/4812)
- Fix `purge_deleted` Oban job crashing when a soft-deleted project has
associated OAuth clients. The `project_oauth_clients` join rows are now
cleaned up alongside the other project-scoped deletes in
Expand Down
4 changes: 4 additions & 0 deletions assets/js/react/lib/use-url-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class URLStore {
const newURL = new URL(window.location.pathname, window.location.origin);
newURL.search = newParams.toString();
newURL.hash = window.location.hash;
// Skip no-op writes so mount-time normalization doesn't stack
// duplicate browser history entries (a no-op pushState never notifies
// subscribers anyway, due to the guard in updateParams).
if (newURL.href === window.location.href) return;
history.pushState({}, '', newURL);
};

Expand Down
37 changes: 36 additions & 1 deletion assets/test/react/lib/use-url-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { renderHook, act } from '@testing-library/react';
import { describe, test, expect, beforeEach } from 'vitest';
import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest';

import { useURLState } from '../../../js/react/lib/use-url-state';

Expand Down Expand Up @@ -201,6 +201,41 @@ describe('useURLState', () => {
});
});

describe('updateSearchParams - no-op writes', () => {
afterEach(() => {
vi.restoreAllMocks();
});

test('does not push a history entry when params are unchanged', () => {
history.replaceState({}, '', '/workflow?panel=run&job=abc');

const { result } = renderHook(() => useURLState());
const pushSpy = vi.spyOn(history, 'pushState');

act(() => {
// Same values that are already in the URL -> a no-op
result.current.updateSearchParams({ panel: 'run', job: 'abc' });
});

expect(pushSpy).not.toHaveBeenCalled();
expect(window.location.search).toBe('?panel=run&job=abc');
});

test('still pushes a history entry when a param actually changes', () => {
history.replaceState({}, '', '/workflow?panel=run');

const { result } = renderHook(() => useURLState());
const pushSpy = vi.spyOn(history, 'pushState');

act(() => {
result.current.updateSearchParams({ panel: 'inspector' });
});

expect(pushSpy).toHaveBeenCalledTimes(1);
expect(result.current.params.panel).toBe('inspector');
});
});

describe('replaceSearchParams', () => {
test('replaces all params with new ones (clears unspecified params)', () => {
history.replaceState({}, '', '/workflow?panel=run&job=abc&step=5');
Expand Down