From 94934f49f9145af82c708507410fd2872d15d9aa Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 15 Oct 2023 21:58:50 -0700 Subject: [PATCH] webpack_public_path: Replace with webpack 5 publicPath: "auto" setting. Signed-off-by: Anders Kaseorg --- tools/test-js-with-node | 1 - web/src/bundles/common.ts | 1 - web/src/page_params.ts | 1 - web/src/sentry.ts | 7 ++++++- web/src/webpack_public_path.js | 11 ----------- web/webpack.config.ts | 2 +- zerver/context_processors.py | 2 -- zerver/tests/test_home.py | 2 -- 8 files changed, 7 insertions(+), 20 deletions(-) delete mode 100644 web/src/webpack_public_path.js diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 15c05e76bb..ed70721de3 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -273,7 +273,6 @@ EXEMPT_FILES = make_set( "web/src/user_topics.ts", "web/src/user_topics_ui.js", "web/src/views_util.js", - "web/src/webpack_public_path.js", "web/src/zcommand.js", "web/src/zform.js", "web/src/zulip.js", diff --git a/web/src/bundles/common.ts b/web/src/bundles/common.ts index bd09c56b49..0ff5ec97fc 100644 --- a/web/src/bundles/common.ts +++ b/web/src/bundles/common.ts @@ -1,5 +1,4 @@ import "../sentry"; -import "../webpack_public_path"; import "../../debug-require"; import "../alert_popup"; import "../csrf"; diff --git a/web/src/page_params.ts b/web/src/page_params.ts index 2042aed8e3..1a15f8bebe 100644 --- a/web/src/page_params.ts +++ b/web/src/page_params.ts @@ -90,7 +90,6 @@ export const page_params: { show_webathena: boolean; translation_data: Record; user_id: number | undefined; - webpack_public_path: string; zulip_merge_base: string; zulip_plan_is_not_limited: boolean; zulip_version: string; diff --git a/web/src/sentry.ts b/web/src/sentry.ts index 4fb42b36b7..fa6c18be12 100644 --- a/web/src/sentry.ts +++ b/web/src/sentry.ts @@ -31,7 +31,12 @@ export function shouldCreateSpanForRequest(url: string): boolean { } if (page_params.server_sentry_dsn) { - const url_matches = [/^\//, new RegExp("^" + _.escapeRegExp(page_params.webpack_public_path))]; + const url_matches = [/^\//]; + if (document.currentScript instanceof HTMLScriptElement) { + url_matches.push( + new RegExp("^" + _.escapeRegExp(new URL(".", document.currentScript.src).href)), + ); + } if (page_params.realm_uri !== undefined) { url_matches.push(new RegExp("^" + _.escapeRegExp(page_params.realm_uri) + "/")); } diff --git a/web/src/webpack_public_path.js b/web/src/webpack_public_path.js deleted file mode 100644 index b3fc363d35..0000000000 --- a/web/src/webpack_public_path.js +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-env commonjs */ -// eslint-disable-next-line no-unused-vars -/* global __webpack_public_path__:writable */ - -"use strict"; - -const {page_params} = require("./page_params"); - -// Webpack exposes this global for dynamic configuration of publicPath. -// https://webpack.js.org/guides/public-path/#on-the-fly -__webpack_public_path__ = page_params.webpack_public_path; diff --git a/web/webpack.config.ts b/web/webpack.config.ts index ce435da9eb..702c907b31 100644 --- a/web/webpack.config.ts +++ b/web/webpack.config.ts @@ -163,7 +163,7 @@ export default ( }, output: { path: path.resolve(__dirname, "../static/webpack-bundles"), - publicPath: "", + publicPath: "auto", filename: production ? "[name].[contenthash].js" : "[name].js", assetModuleFilename: production ? "files/[name].[hash][ext][query]" diff --git a/zerver/context_processors.py b/zerver/context_processors.py index ef47311405..500229d866 100644 --- a/zerver/context_processors.py +++ b/zerver/context_processors.py @@ -2,7 +2,6 @@ from typing import Any, Dict, Mapping, Optional from urllib.parse import urljoin from django.conf import settings -from django.contrib.staticfiles.storage import staticfiles_storage from django.http import HttpRequest from django.utils.html import escape from django.utils.safestring import SafeString @@ -32,7 +31,6 @@ from zproject.config import get_config DEFAULT_PAGE_PARAMS: Mapping[str, Any] = { "development_environment": settings.DEVELOPMENT, - "webpack_public_path": staticfiles_storage.url(settings.WEBPACK_BUNDLES), } diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 5e02919f40..31f65e2df9 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -226,7 +226,6 @@ class HomeTest(ZulipTestCase): "user_status", "user_topics", "warn_no_email", - "webpack_public_path", "zulip_feature_level", "zulip_merge_base", "zulip_plan_is_not_limited", @@ -368,7 +367,6 @@ class HomeTest(ZulipTestCase): "two_fa_enabled", "two_fa_enabled_user", "warn_no_email", - "webpack_public_path", ] self.assertEqual(actual_keys, expected_keys)