Skip to content
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

Only use legal characters in query config name #197

Merged
merged 4 commits into from
Sep 13, 2016

Conversation

taion
Copy link
Member

@taion taion commented Sep 11, 2016

Fixes #196

@taion taion mentioned this pull request Sep 11, 2016
@@ -109,8 +109,7 @@ export default class QueryAggregator {
});
});

queryConfig.name =
['$$_aggregated', ...Object.keys(queryConfig.queries)].join('-');
queryConfig.name = 'AggregatedReactRouterQueryConfig';
Copy link
Contributor

@denvned denvned Sep 12, 2016

Choose a reason for hiding this comment

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

Don't we still need an unique query config name for a given set of queries, because getRelayQueries uses it as a part of the cache key? Otherwise Relay would probably use the set of queries belonging to the old route after changing the route to a new one (in the case the query params stay the same).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh yes. Hmm.

Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe remove $$_ and give other prefix:
Eg.

['react-router-relay', ...Object.keys(queryConfig.queries)].join('-');

@taion
Copy link
Member Author

taion commented Sep 12, 2016

@denvned I'm afraid of collisions though. What do you think of 2cb9d20?

@denvned
Copy link
Contributor

denvned commented Sep 12, 2016

Maybe generate query config names sequentially and save them in a map where the key is String(Object.keys(queryConfig.queries))?

@taion
Copy link
Member Author

taion commented Sep 12, 2016

I'm a little bit worried about non-determinism there. It means that the query names will end up being different depending on order of rendering. Wonder if this might lead to odd server/client mismatches.

@denvned
Copy link
Contributor

denvned commented Sep 12, 2016

You mean isomorphic rendering? E.g. if some app for some reason renders a query config name in a React component? Then yes, it might cause a markup mismatch.

The other alternative I can propose is just to encode the name using hex or base62.

@taion
Copy link
Member Author

taion commented Sep 12, 2016

That's what I'm doing with generateRQLFieldAlias, though. Are you concerned about the Relay-internal API usage?

@denvned
Copy link
Contributor

denvned commented Sep 12, 2016

I'd prefer to avoid Relay internals, but I'm more concerned about that generateRQLFieldAlias encodes the hash of a name, not the name itself, and that can cause collisions, although the probability is very low.

@taion
Copy link
Member Author

taion commented Sep 12, 2016

Okay, let's go with that: 2c4cbdf

@johntran Can you check if this code works?

@denvned
Copy link
Contributor

denvned commented Sep 13, 2016

👍 for meaningful query config names, but I would use __ (double _) to join query names to avoid some collisions, e.g. between [foo_bar, baz] and [foo, bar_baz]. Maybe I would even check that a query name doesn't contain __ (double _), and doesn't start or end with _, to completely avoid collisions. Checking that query names consist of only /[_a-zA-Z0-9]/ would be also useful for catching user errors early.

@taion
Copy link
Member Author

taion commented Sep 13, 2016

They do have double underscores, because I join with _ and also start the generated query names with _.

I'd rather not do extra validation on user query names. I feel like it's rather unlikely to come up. I still don't have a repro for the reported issue here, even.

@johntran
Copy link

@taion The latest updates work with both default and custom network layers.

@taion taion merged commit 2239c95 into relay-tools:master Sep 13, 2016
@taion taion deleted the update branch September 13, 2016 19:56
@taion
Copy link
Member Author

taion commented Sep 13, 2016

v0.13.5

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.

4 participants