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

fix(buildSrcSet): ensure operation is idempotent #167

Closed
wants to merge 2 commits into from

Conversation

ericdeansanchez
Copy link
Contributor

@ericdeansanchez ericdeansanchez commented Sep 30, 2020

The purpose of this PR is to ensure the buildSrcSet operation is
idempotent. Prior to this PR, code modified the input-parameters,
params, causing identical calls to buildSrcSet to produce different
results.

Now, the input params are copied into a new queryParams object and
this object is passed to callers requiring params. A test has been
written to show that the behavior has changed from the behavior detailed
in issue #158––the input params object remains unchanged after calling
buildSrcSet and that calling buildSrcSet multiple times produces
the same result (given the same inputs).

I also ripgrep'd through the repo with rg 'params.[:alpha:]' and with
rg 'params\[' to ensure params is never mutated (i.e. it never
appears on the left hand side of any expression).

Closes #158

@ericdeansanchez ericdeansanchez requested a review from a team as a code owner September 30, 2020 22:46
Copy link
Contributor

@frederickfogerty frederickfogerty left a comment

Choose a reason for hiding this comment

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

Looks good @ericdeansanchez! Only a few small things, overall looks great ☺️

src/imgix-core-js.js Outdated Show resolved Hide resolved
test/test-buildSrcSet.js Show resolved Hide resolved
@frederickfogerty
Copy link
Contributor

No change needed and it's not a big thing, but we don't usually include the changes to dist in a PR, and usually only commit them when doing a release.

@frederickfogerty
Copy link
Contributor

Also it looks like you're going to need to rebase onto main before merging to keep the history clean 😄

@ericdeansanchez
Copy link
Contributor Author

Thanks for the great feedback! I think what happened with dist was I ran npm install after making a couple changes. Then I wondered if changing dist was preferred/or not, but you've answered that question. TIL

The purpose of this PR is to ensure the buildSrcSet operation is
idempotent. Prior to this PR, code modified the input-parameters,
params, causing identical calls to buildSrcSet to produce different
results.

Now, the input params are copied into a new queryParams object and
this object is passed to callers requiring params. A test has been
written to show that the behavior has changed from the behavior detailed
in issue #158––the input params object remains unchanged after calling
buildSrcSet and that calling buildSrcSet multiple times produces
the same result (given the same inputs).

I also ripgrep'd through the repo with `rg 'params.[:alpha:]'` and with
`rg 'params\['` to ensure params is never mutated (i.e. it never
appears on the left hand side of any expression).

Closes #158
@ericdeansanchez
Copy link
Contributor Author

I'm closing this PR in favor of fix(buildURL): ensure operation is idempotent #168.

In the above PR, I tried to use git to clean up some commits, but there were a couple casualty-commits (that were undone unfortunately 🙃.

@ericdeansanchez ericdeansanchez deleted the mitigate-mutation branch October 6, 2020 18:48
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.

buildSrcSet mutates params argument when building either fluid or fixed-width srcset.
3 participants