Просмотр исходного кода

Make `USE_NEW_DESIGN` deterministic by cache-busting `config.json` in design switcher (#858)

* Initial plan

* Fix design switch config caching for USE_NEW_DESIGN

Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>
Copilot 1 месяц назад
Родитель
Сommit
aa84692df3
2 измененных файлов с 19 добавлено и 1 удалено
  1. 2 1
      design-switch.js
  2. 17 0
      tests/e2e/design-switch.spec.js

+ 2 - 1
design-switch.js

@@ -37,7 +37,8 @@
     try {
         const xhr = new XMLHttpRequest();
         // Use a synchronous request to prevent a flash of the old design before redirecting
-        xhr.open('GET', 'config.json', false);
+        // Bypass stale browser caches so Docker env changes are reflected immediately
+        xhr.open('GET', 'config.json?_=' + Date.now(), false);
         xhr.send(null);
 
         // Check for a successful response, but not 304 Not Modified, which can have an empty response body

+ 17 - 0
tests/e2e/design-switch.spec.js

@@ -26,4 +26,21 @@ test.describe('Design switch behavior', () => {
     await expect(page).toHaveURL(/index-classic\.html\?design=old/);
     await expect(classicStartButton(page)).toBeVisible();
   });
+
+  test('config fetch bypasses browser cache', async ({ page }) => {
+    let configRequestUrl = '';
+
+    await page.route('**/config.json*', async (route) => {
+      configRequestUrl = route.request().url();
+      await route.fulfill({
+        status: 200,
+        contentType: 'application/json',
+        body: JSON.stringify({ useNewDesign: true }),
+      });
+    });
+
+    await page.goto(`${baseUrls.standalone}/index.html`);
+    await expect(page).toHaveURL(/index-modern\.html/);
+    expect(configRequestUrl).toMatch(/config\.json\?_=\d+/);
+  });
 });