datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 50 forks source link

fix: scope locale context to current query and not reuse globally #211

Closed pieh closed 1 year ago

pieh commented 1 year ago

https://github.com/datocms/gatsby-source-datocms/issues/209 describe how sometimes nested fields don't honor locale settings. This happens because the context.sourceDatocms object is actually reused between all the queries that run in given process and state there is scope to just field paths within the query. Gatsby can execute multiple queries in parallel (especially for the builds as it does batching of all queries), so this shared state object is a problem as one query for one page might change the context that query for other page rely on.

Proposed fix provide fresh locale and localeFallback for each query seperately - I implemented this in shortest way possible, there is opportunity for some optimisation as right now there is a lot of repeated .get lookups which I kept for visibilty and easier to follow proposed changes

Possibly fixes #209

matjack1 commented 1 year ago

Hey @pieh thank you very much for this! We are going to check it and get back to you later during the week as we cannot sooner.