Skip to content

Conversation

dprgarner
Copy link
Contributor

Resolves #62 . This is a follow-on from issue #54 and PR #61 , but the fix doesn't require history to have history.location defined, so now works with tests outside a browser.

The approach I took was to move the refs up. Rather than each useQueryParam/s hook maintaining its own ref of the last version of the location it received, the top level provider should maintain a single location ref instead, and updates to the location should work with this shared ref. (The previous approach in #61 was like a shared ref approach, too: when it exists, refHistory.current.location is up-to-date everywhere in the app because there's only one history, but refLocation.current isn't guaranteed to be up-to-date if two different hooks call setQuery without re-rendering between calls.) I introduced a new internal-only LocationProvider component to manage this ref and provide down a single cached updater callback.

QueryParamProvider,
QueryParamContext,
QueryParamContextValue,
} from './QueryParamProvider';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes I made modify the parameters of updateUrlQuery and the signature of QueryParamContext and the type QueryParamContextValue, which are library exports. However, these aren't documented in the README or included in any examples. Would taking these out of the library exports be considered a breaking change? They seem like internal details of the library to me.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine

import { QueryParamProvider } from '../QueryParamProvider';
import { makeMockLocation, makeMockHistory } from './helpers';

// ¯\_(ツ)_/¯
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I do with these tests? I wanted to make sure the history-generating code in QueryParamProvider was still working, but I'm no longer passing history down via context.

@pbeshai
Copy link
Owner

pbeshai commented Apr 17, 2020

Ooo cool, I wanted to get around to reworking how location/history were provided after I realized location needs to be requested at the last minute. I've made a ton of changes to the lib today (spent the day on it) that will make merging this ... difficult. But it seems like it would be worthwhile at first glance. I'll need to read through it more carefully later

@pbeshai
Copy link
Owner

pbeshai commented Apr 17, 2020

if you have some bandwidth to fix the merge conflicts, that'd be great too! Let me know if so, otherwise I'll probably look at it tonight or this weekend

@pbeshai
Copy link
Owner

pbeshai commented Apr 17, 2020

Ok going to take a look, thanks

@pbeshai
Copy link
Owner

pbeshai commented Apr 17, 2020

Continuing in #86

@pbeshai pbeshai closed this Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Concurrent updates fail with mocked and in-memory histories
2 participants