Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Import base64 utils directly from js-sdk #12871

Merged
merged 7 commits into from
Aug 7, 2024
Merged

Import base64 utils directly from js-sdk #12871

merged 7 commits into from
Aug 7, 2024

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Aug 6, 2024

sw.js in a production build was previously 1mb almost exactly. With this change, it's 37kb.

@turt2live
Copy link
Member Author

This appears to fix element-hq/element-web#27759, presumably because Webpack changes strategy with a smaller file.

@turt2live turt2live marked this pull request as ready for review August 6, 2024 19:48
@turt2live turt2live requested a review from a team as a code owner August 6, 2024 19:48
@turt2live turt2live requested review from t3chguy and robintown August 6, 2024 19:48
@turt2live
Copy link
Member Author

sigh

image
image

// is used by Element Web's service worker, and importing `matrix` brings in ~1mb of stuff
// we don't need. Instead, we ignore the import restriction and only bring in what we actually
// need.
// eslint-disable-next-line no-restricted-imports
Copy link
Member

Choose a reason for hiding this comment

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

Note that this means that react-sdk builds can be broken by minor releases of the js-sdk. matrix-js-sdk/src/base64 is not a public interface.

Copy link
Member

Choose a reason for hiding this comment

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

encodeUnpaddedBase64 is approximately one line of code, if you don't need to maintain compatibility with node.js. Maybe just redefine it, rather than going all left-pad on it?

Copy link
Member Author

Choose a reason for hiding this comment

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

how do we make it a public interface?

Copy link
Member Author

Choose a reason for hiding this comment

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

ugh, github only showing half the comments is unhelpful :|

I'm a little worried about it breaking in some weird way, but presumably it's been stable for 10 years now, so...

Copy link
Member

Choose a reason for hiding this comment

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

how do we make it a public interface?

js-sdk's public interfaces are defined in its README, https://github.com/matrix-org/matrix-js-sdk?tab=readme-ov-file#entry-points, and in the documentation (http://matrix-org.github.io/matrix-js-sdk/index.html, left sidebar), so in theory, I guess you make a PR to add it.

Personally though, I'm a bit unconvinced this should live as a separate entrypoint.

I'm a little worried about it breaking in some weird way, but presumably it's been stable for 10 years now, so...

base64.js has only existed for a few months, iirc, so no I don't think it's been stable for 10 years.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, having tried to inline: the library claims to export an ArrayBuffer (a node thing), using web APIs, which has an incompatible interface with Uint8Array. The existing js-sdk code does this type checking for us already - it'd be a shame to copy/paste it too.

So, is there a way for us to declare base64 as public interface? If we don't think it belong as js-sdk, maybe we create our own package for it. I'm somewhat biased towards short term solutions though, as I'd like to get this into an RC cycle.

Copy link
Member Author

Choose a reason for hiding this comment

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

(ffs github, show me comments when I reload and not after I post)

I'm going to go the route of README changes then.

Copy link
Member Author

Choose a reason for hiding this comment

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

... though yea, it's a bit silly as its own entrypoint. Maybe we just accept and document the risk?

Copy link
Member

Choose a reason for hiding this comment

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

I get that we should prefer the public interface in the general case, but personally I would think this is an acceptable risk - matrix-react-sdk is continuously deployed with the latest git revision of matrix-js-sdk, and we also have CI that triggers upstream test runs for matrix-react-sdk, so any breaks are caught very early. We also lock the dependency to a specific version when releasing.

@turt2live
Copy link
Member Author

I did not expect that commit to work, but I won't decline a checkmark from the CI. @robintown please take a look at the test stuff and comment quality in particular - I'm not confident it helpfully describes what is actually going on here.

@turt2live turt2live requested a review from robintown August 6, 2024 22:48
Copy link
Member

@robintown robintown left a comment

Choose a reason for hiding this comment

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

Comments make sense to me

@turt2live turt2live enabled auto-merge August 7, 2024 04:19
@turt2live turt2live added this pull request to the merge queue Aug 7, 2024
Merged via the queue into develop with commit 7a4783f Aug 7, 2024
29 checks passed
@turt2live turt2live deleted the travis/sw-size branch August 7, 2024 04:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, enabling or disabling functionality, other engineering tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants