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

Consolidate webasset bundle to single chunks #38706

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

avatus
Copy link
Contributor

@avatus avatus commented Feb 27, 2024

Refer to the "Why" section of this RFD for info on the issue solved with this PR.

This PR will configure vite to pipe all code chunks together. So techincally, this isn't removing code splitting, but in reality just not splitting the code. The benefits of this way are

  1. we do not have to remove any of our dynamically imported code as it will just import it all at build time
  2. in the future, we can take advantage of the code splitting function (right now its essentially an empty anonymous function) to have more fine grained control over the code splitting in the future.

This ignores fonts/images/wasm, and only affects javascript and css files. We will now have a single javascript and css file load on initial page load. This will increase latency slightly as there is a larger file to download but it will remove any other network requests for javascript files after (since it has the entire bundle) and usually the javascript file and css file will be cached by the browser anyway so this initial latency increase should only happen once per version (or however their browser may be set up).

Quick loom videos showing the error and fix
https://www.loom.com/share/bcae5d79b14a4e6e8df8e0603ace0f04
https://www.loom.com/share/2ce5386941c849dca6a142089d927aa3

@avatus
Copy link
Contributor Author

avatus commented Feb 28, 2024

Updated with some loom videos showing it work/not-work
https://www.loom.com/share/bcae5d79b14a4e6e8df8e0603ace0f04
https://www.loom.com/share/2ce5386941c849dca6a142089d927aa3

Please help me break this!

@avatus
Copy link
Contributor Author

avatus commented Feb 28, 2024

I did toy with the idea of keeping the hashing for index.js and index.css ONLY, just to make sure those are "in sync" since they are loaded at the same time. I think I went without just to make sure something is always loaded rather than a rare case that the instant one loads it load balances to the other version. Slightly broken css might not be as bad as "page didn't load at all, refresh"

@ryanclark
Copy link
Contributor

I did toy with the idea of keeping the hashing for index.js and index.css ONLY, just to make sure those are "in sync" since they are loaded at the same time. I think I went without just to make sure something is always loaded rather than a rare case that the instant one loads it load balances to the other version. Slightly broken css might not be as bad as "page didn't load at all, refresh"

index.css only contains the fonts so it'll very rarely change

Comment on lines 74 to 75
// This removes code splitting.
inlineDynamicImports: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove React.lazy and all the default exports instead? Otherwise we're wrapping the loading of all route components in a promise for no reason

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed react lazy on everything except access graph/assist. Was getting really weird "React Markdown" errors unless it was lazy loaded. like 40+ of them during testing. I'll keep inspecting but for now, every other lazy is removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could something like with manualChunks to programmatically choose which chunks are split and remove hashing that way for those specifically, or we can keep this line to handle the assist/access graph and call it a day. I dont know much about assist's internals I think to know what to chunk out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

e update if we stick with these changes https://github.com/gravitational/teleport.e/pull/3566

@avatus
Copy link
Contributor Author

avatus commented Feb 28, 2024

Another loom of a "upgrade in process" with multiple sessions. There was an error that showed up but its because my second proxy couldn't reach the auth server (which is running with my first proxy) during an upgrade but thats not related to my webassets https://www.loom.com/share/1cd8dd618b054b63ac2462387ba32b07

@avatus avatus force-pushed the avatus/remove_code_splitting branch from ff4b1ee to 5fc46ed Compare February 28, 2024 19:38
@avatus
Copy link
Contributor Author

avatus commented Feb 29, 2024

Another way to help review this is to build the UI and just poke around to make sure everything works still. I made large changes to imports of features and while I tried to check most it'd be nice to have another set of eyes to check for regressions

Copy link
Contributor

@ibeckermayer ibeckermayer left a comment

Choose a reason for hiding this comment

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

The linked-to RFD is still open, and this change appears to be talked about as an aside at the end. Was it decided somewhere that this is the approach that we're going with? If yes, have we characterized the performance impact?

@@ -69,6 +69,18 @@ export function createViteConfig(
outDir: outputDirectory,
assetsDir: 'app',
emptyOutDir: true,
rollupOptions: {
output: {
// This removes code splitting.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This removes code splitting.
// This prevents code splitting.

Comment on lines 78 to 80
// this will remove hashing from asset (non-js) files. We will keep the javascript file
// hashed in order to avoid a cache issue between versions. `no-cache` headers are set
// for our html file
Copy link
Contributor

Choose a reason for hiding this comment

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

We will keep the javascript file hashed

doesn't this contradict the previous comment of

removes hashing from our entry point file

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, an older version and I left the comments in. thanks

@@ -16,5 +16,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// export as default for use with React.lazy
export { AwsOidc as default } from './AwsOidc';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we keeping this one?

@@ -16,5 +16,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// export as default for use with React.lazy
export { LockCheckout as default } from './LockCheckout';
Copy link
Contributor

Choose a reason for hiding this comment

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

And this one?

Comment on lines 36 to 43
import LoginFailed from './Login/LoginFailed';
import LoginSuccess from './Login/LoginSuccess';
import Login from './Login';
import Welcome from './Welcome';

import type { History } from 'history';
import Console from './Console';
import Player from './Player';
import DesktopSession from './DesktopSession';
Copy link
Contributor

Choose a reason for hiding this comment

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

These are all default exports

Comment on lines 19 to +20
import TrustedClusters from './TrustedClusters';
export default TrustedClusters;
export { TrustedClusters };
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use this PR to clean these up all the way through to the component?

That way we can have a consistent

export { TrustedClusters } from './TrustedClusters';

I know it's slightly increasing the scope of this PR, but we'd never get round to the cleanup otherwise

Feel free to ignore

Comment on lines 54 to 55
import Account from './Account';
import Support from './Support';
Copy link
Contributor

Choose a reason for hiding this comment

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

Still default

Copy link
Contributor

@ryanclark ryanclark left a comment

Choose a reason for hiding this comment

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

Approving as it LGTM, pending the last default export changes

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from kimlisa March 4, 2024 19:23
@avatus avatus added this pull request to the merge queue Mar 4, 2024
@avatus avatus removed this pull request from the merge queue due to a manual request Mar 4, 2024
@avatus avatus force-pushed the avatus/remove_code_splitting branch 5 times, most recently from 10bf931 to 0159477 Compare March 5, 2024 17:05
This will prevent the react bundle from being code split. This means
that our entire javascript bundle will be a single file as well as our
css file. It also removes hashing from the included webassets. The reason
for this change is to allow different versioned proxies to coexist behind a
load balancer. If we remove code splitting, then the only time our bundle
will load is on initial hit, and the web client will then have the entire
bundle.

This also removes React.lazy. React.lazy wrapped components in a promise
to allow for dynamic imports during runtime. This is no longer needed.

Lastly, to clean up the default exports used by react lazy, this removes
(most) default exports for feature components. Assist and telemetry-boot
are not included in the javascript bundle
@avatus avatus force-pushed the avatus/remove_code_splitting branch from 0159477 to 82d1a4e Compare March 5, 2024 17:18
@avatus avatus added this pull request to the merge queue Mar 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2024
@avatus avatus added this pull request to the merge queue Mar 5, 2024
Merged via the queue into master with commit e922db0 Mar 5, 2024
34 checks passed
@avatus avatus deleted the avatus/remove_code_splitting branch March 5, 2024 19:52
@public-teleport-github-review-bot

@avatus See the table below for backport results.

Branch Result
branch/v15 Create PR

avatus added a commit that referenced this pull request Mar 11, 2024
This will prevent the react bundle from being code split. This means
that our entire javascript bundle will be a single file as well as our
css file. It also removes hashing from the included webassets. The reason
for this change is to allow different versioned proxies to coexist behind a
load balancer. If we remove code splitting, then the only time our bundle
will load is on initial hit, and the web client will then have the entire
bundle.

This also removes React.lazy. React.lazy wrapped components in a promise
to allow for dynamic imports during runtime. This is no longer needed.

Lastly, to clean up the default exports used by react lazy, this removes
(most) default exports for feature components. Assist and telemetry-boot
are not included in the javascript bundle
github-merge-queue bot pushed a commit that referenced this pull request Mar 27, 2024
* Prevent code splitting (#38706)

This will prevent the react bundle from being code split. This means
that our entire javascript bundle will be a single file as well as our
css file. It also removes hashing from the included webassets. The reason
for this change is to allow different versioned proxies to coexist behind a
load balancer. If we remove code splitting, then the only time our bundle
will load is on initial hit, and the web client will then have the entire
bundle.

This also removes React.lazy. React.lazy wrapped components in a promise
to allow for dynamic imports during runtime. This is no longer needed.

Lastly, to clean up the default exports used by react lazy, this removes
(most) default exports for feature components. Assist and telemetry-boot
are not included in the javascript bundle

* Fix the import on the account settings page (#39015)

* Fix auth connector imports (#39019)

* Init discover resources inside the discover component (#39166)

* Use ETag headers for served javascript files (#39251)

---------

Co-authored-by: Bartosz Leper <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v15 backport-required no-changelog Indicates that a PR does not require a changelog entry size/sm ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants