-
Notifications
You must be signed in to change notification settings - Fork 207
Remove redundant calls to normalizeStoreFqdn #6220
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
Conversation
a57a7a0
to
0717a94
Compare
Coverage report
Test suite run success3228 tests passing in 1350 suites. Report generated by 🧪jest coverage report action from a883d5b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the initial normalizeStoreFqdn
take place? Can we guarantee that it always runs before this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first normalizeStoreFqdn
happens at flag parsing. It grabs any store env var whether in a toml or passed in such as --store
. It happens before any other part of a command would require it.
The next time it's called is ensureThemeStore
in which it takes that value and caches it in the local config JSON.
If a brand new user were to install the CLI today, their first run always requires them to pass a store to login initially so it will save that store data and be used when someone calls a theme command without passing a store.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever performance optimization, @EvilGenius13 🔥 Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for removing the redundant normalizeStoreFqdn
calls, Josh!
I tested the PR locally with various scenarios:
theme push --store mystore
→ Works correctly, normalizes tomystore.myshopify.com
theme push --store mystore.myshopify.com
→ Works correctly, no double-normalization- All test scenarios from the PR description passed successfully
Additional Finding
During testing, I added debug logging and noticed normalizeStoreFqdn
is still called twice:
- First with
"mystore"
(correctly adds .myshopify.com during flag parsing) - Then again with
"mystore.myshopify.com"
(the already-normalized value)
The second call happens in ensureAuthenticated
(packages/cli-kit/src/private/node/session.ts:181) and doesn't change the value since it's already normalized. This seems like another redundant call that could be removed for completeness.
[DEBUG] normalizeStoreFqdn called with: "mystore"
Trace: [DEBUG] Call stack:
at normalizeStoreFqdn (file:///packages/cli-kit/dist/public/node/context/fqdn.js:140:13)
at Object.parse (file:///packages/theme/dist/cli/flags.js:32:33)
... (in flag parsing)
[DEBUG] normalizeStoreFqdn called with: "mystore.myshopify.com"
Trace: [DEBUG] Call stack:
at normalizeStoreFqdn (file:///packages/cli-kit/dist/public/node/context/fqdn.js:140:13)
at ensureAuthenticated (file:///packages/cli-kit/dist/private/node/session.js:87:43)
at async ensureAuthenticatedAdmin (file:///packages/cli-kit/dist/public/node/session.js:105:20)
I did some digging and tried some edits. At this current moment I am going to leave it in. Please let me know if you feel differently about this! I am also open to opinions on this. I just didn't want to start changing more logic outside the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for further digging into this! The changes make sense - removing the normalizations in adminRequest
, adminRequestDoc
, and ensureAuthenticatedThemes
since the store is already normalized during flag parsing. I agree and think it's prudent to keep the normalization in ensureAuthenticated
since other packages may pass unnormalized stores to ensureAuthenticatedAdmin
. Nice performance improvement that avoids any breaking changes. LGTM! 🚢
This commit removes additional calls to normalizeStoreFqdn since it is already called in the flag parsing stage.
0717a94
to
a883d5b
Compare
WHY are these changes introduced?
While looking into a separate issue, I noticed that we make a lot of calls to
normalizeStoreFqdn
in certain commands. It's job is to normalize the store name in the CLI.WHAT is this pull request doing?
Removed extra calls to
normalizeStoreFqdn
as it's originally called very early in the command process. This is the flow before fixing.Images below include a

console.log
to illustrate the amount of calls.Before:
After:

How to test your changes?
I would love a 🎩 in case I missed something.
theme push
theme push -e my_store
theme push --store my_store
<- omit the myshopify.com to see if it still adds it properlyPost-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist