-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add domain sharding to js runtime #268
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mattcompiles
reviewed
Dec 9, 2024
marcins
reviewed
Dec 9, 2024
marcins
reviewed
Dec 9, 2024
JakeLane
reviewed
Dec 9, 2024
} | ||
|
||
function getDomainShardIndex(str: string, maxShards: number) { | ||
let shard = str.split('').reduce((a, b) => { |
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.
nit: a conventional for loop would be faster
JakeLane
approved these changes
Dec 9, 2024
yamadapc
reviewed
Dec 9, 2024
benjervis
force-pushed
the
add-domain-sharding-to-js-runtime
branch
2 times, most recently
from
December 12, 2024 05:56
ec74432
to
71b04c2
Compare
benjervis
force-pushed
the
add-domain-sharding-to-js-runtime
branch
from
December 12, 2024 06:16
71b04c2
to
89d074e
Compare
mattcompiles
approved these changes
Dec 12, 2024
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.
Nice one bud!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In order to support domain sharding for HTTP1.1 users, we need to apply shards in two places. Firstly, in the generated HTML, which is done at request time by the SSR server (as we need to know whether this is a 1.1 request or not). Secondly, when requesting bundles from within other bundles we need to shard those requests as well, and not just rely on the parent shard.
To support this, I've made some changes to the JS Runtime, adding in a sharded version of
helpers/bundle-url
which is activated if the domain sharding config is provided in a build.bundle-url-shards
started out as a copy ofbundle-url
, but has been refactored a bit to make the more complicated logic easier to work with. That number of functions also became a little tricky to track, so the file is now a TypeScript file which will be compiled in the client build.There was a todo in here to migrate
getOrigin
to just using the URL constructor once we didn't need to support IE 11 anymore, which we don't, so I've made that change and brought it across tobundle-url
also.Lastly there are a bunch of tests to make sure the sharding logic does what it's meant to, and that the runtime generates the call with the right arguments.