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

Commit 7a4783f

Browse files
turt2liverobintown
andauthored
Import base64 utils directly from js-sdk (#12871)
* Import base64 utils directly from js-sdk See comments in code * Use the authenticated routes (because the service worker said so) * Revert "Use the authenticated routes (because the service worker said so)" This reverts commit 835806d. * Use the authenticated routes (because the service worker said so) * Continue fighting Playwright * Document who is at fault if the import breaks (it's us) * Update playwright/e2e/timeline/timeline.spec.ts Co-authored-by: Robin <[email protected]> --------- Co-authored-by: Robin <[email protected]>
1 parent 8285283 commit 7a4783f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: playwright/e2e/timeline/timeline.spec.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,16 @@ test.describe("Timeline", () => {
720720
).toBeVisible();
721721
});
722722

723-
test("should render url previews", async ({ page, app, room, axe, checkA11y }) => {
723+
test("should render url previews", async ({ page, app, room, axe, checkA11y, context }) => {
724724
axe.disableRules("color-contrast");
725725

726-
await page.route(
727-
"**/_matrix/media/v3/thumbnail/matrix.org/2022-08-16_yaiSVSRIsNFfxDnV?*",
726+
// Element Web uses a Service Worker to rewrite unauthenticated media requests to authenticated ones, but
727+
// the page can't see this happening. We intercept the route at the BrowserContext to ensure we get it
728+
// post-worker, but we can't waitForResponse on that, so the page context is still used there. Because
729+
// the page doesn't see the rewrite, it waits for the unauthenticated route. This is only confusing until
730+
// the js-sdk (and thus the app as a whole) switches to using authenticated endpoints by default, hopefully.
731+
await context.route(
732+
"**/_matrix/client/v1/media/thumbnail/matrix.org/2022-08-16_yaiSVSRIsNFfxDnV?*",
728733
async (route) => {
729734
await route.fulfill({
730735
path: "playwright/sample-files/riot.png",
@@ -750,6 +755,7 @@ test.describe("Timeline", () => {
750755

751756
const requestPromises: Promise<any>[] = [
752757
page.waitForResponse("**/_matrix/media/v3/preview_url?url=https%3A%2F%2Fcall.element.io%2F&ts=*"),
758+
// see context.route above for why we listen for the unauthenticated endpoint
753759
page.waitForResponse("**/_matrix/media/v3/thumbnail/matrix.org/2022-08-16_yaiSVSRIsNFfxDnV?*"),
754760
];
755761

Diff for: src/utils/tokens/pickling.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ See the License for the specific language governing permissions and
1717
limitations under the License.
1818
*/
1919

20-
import { encodeUnpaddedBase64 } from "matrix-js-sdk/src/matrix";
20+
// Note: we don't import the base64 utils from `matrix-js-sdk/src/matrix` because this file
21+
// is used by Element Web's service worker, and importing `matrix` brings in ~1mb of stuff
22+
// we don't need. Instead, we ignore the import restriction and only bring in what we actually
23+
// need.
24+
// Note: `base64` is not public in the js-sdk, so if it changes/breaks, that's on us. We should
25+
// be okay with our frequent tests, locked versioning, etc though. We'll pick up problems well
26+
// before release.
27+
// eslint-disable-next-line no-restricted-imports
28+
import { encodeUnpaddedBase64 } from "matrix-js-sdk/src/base64";
2129
import { logger } from "matrix-js-sdk/src/logger";
2230

2331
/**

0 commit comments

Comments
 (0)