🩺(project) reload app if front and back unsync#2276
Conversation
f253792 to
d8136b6
Compare
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
|
Size Change: 0 B Total Size: 4.24 MB 📦 View Changed
|
WalkthroughThis PR implements automatic app reload when frontend and backend versions become unsynchronized. The backend config API now exposes Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts`:
- Around line 159-175: Register the page.route handler for /users/me/ before
performing the actions that trigger a version-mismatch reload, replace the fixed
waitForTimeout with a deterministic wait that polls sessionStorage (e.g. await
page.waitForFunction(() => sessionStorage.getItem('reload-version') ===
'0.0.0')), and then assert the route hit count in a stable way (either assert
counterReload >= 2 or assert counterReload === 2 only if you guarantee the first
hit cannot be missed). Update references: the page.route handler that increments
counterReload, the sessionStorage.getItem('reload-version') check, and the final
expect on counterReload.
In `@src/frontend/apps/e2e/__tests__/app-impress/utils-common.ts`:
- Line 7: The RELEASE_VERSION is currently imported from the e2e app
package.json (packageJsonVersion from '../../package.json') which can diverge
from NEXT_PUBLIC_APP_VERSION; change the import to read the Impress app's
package.json (the apps/impress package.json used to build
NEXT_PUBLIC_APP_VERSION) and use that value for RELEASE_VERSION instead, and
update the second occurrence at the other import/site (line referenced by the
review) so both places reference the Impress package.json version; locate
occurrences by the identifier RELEASE_VERSION and the import named
packageJsonVersion and replace their source to the Impress package.json.
In `@src/frontend/apps/impress/src/core/config/ConfigProvider.tsx`:
- Around line 101-107: sessionStorage access in ConfigProvider.tsx (the
RELOAD_VERSION_KEY check comparing to conf.RELEASE_VERSION) can throw in
restricted/security contexts; wrap both
sessionStorage.getItem(RELOAD_VERSION_KEY) and
sessionStorage.setItem(RELOAD_VERSION_KEY, conf.RELEASE_VERSION) in a try/catch
so a SecurityError doesn’t abort boot, and only call window.location.reload()
when the get succeeded and revealed a different version (fallback to skipping
reload on error). Ensure you reference RELOAD_VERSION_KEY, conf.RELEASE_VERSION,
and the reload call so the guard surrounds those operations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4a3887a4-db1d-4b67-8411-f14e79830d91
📒 Files selected for processing (9)
CHANGELOG.mdsrc/backend/core/api/viewsets.pysrc/backend/core/tests/test_api_config.pysrc/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.tssrc/frontend/apps/e2e/__tests__/app-impress/utils-common.tssrc/frontend/apps/impress/next.config.jssrc/frontend/apps/impress/src/core/config/ConfigProvider.tsxsrc/frontend/apps/impress/src/core/config/api/useConfig.tsxsrc/frontend/apps/impress/src/services/PosthogAnalytic.tsx
| let counterReload = 0; | ||
| await page.route(/.*\/users\/me\/$/, async (route) => { | ||
| counterReload += 1; | ||
| await route.continue(); | ||
| }); | ||
|
|
||
| await page.waitForTimeout(1000); | ||
|
|
||
| // The sessionStorage guard should be set to the mismatched backend version. | ||
| const reloadVersion = await page.evaluate(() => | ||
| sessionStorage.getItem('reload-version'), | ||
| ); | ||
| expect(reloadVersion).toBe('0.0.0'); | ||
|
|
||
| // The page should have reloaded once | ||
| expect(counterReload).toBe(2); | ||
| }); |
There was a problem hiding this comment.
Make the reload assertion deterministic to avoid flaky CI failures.
Line 165 uses a fixed sleep, and Line 174 expects an exact /users/me/ count. This is timing-sensitive and can intermittently fail with retries/background refetches. Also, register the route before triggering mismatch logic so the first hit is never missed.
Suggested stabilization
test('checks redirect if unsync version', async ({ page }) => {
+ let counterReload = 0;
+ await page.route(/.*\/users\/me\/$/, async (route) => {
+ counterReload += 1;
+ await route.continue();
+ });
+
await overrideConfig(page, {
RELEASE_VERSION: '0.0.0',
});
- let counterReload = 0;
- await page.route(/.*\/users\/me\/$/, async (route) => {
- counterReload += 1;
- await route.continue();
- });
-
- await page.waitForTimeout(1000);
-
- // The sessionStorage guard should be set to the mismatched backend version.
- const reloadVersion = await page.evaluate(() =>
- sessionStorage.getItem('reload-version'),
- );
- expect(reloadVersion).toBe('0.0.0');
-
- // The page should have reloaded once
- expect(counterReload).toBe(2);
+ await expect
+ .poll(
+ () => page.evaluate(() => sessionStorage.getItem('reload-version')),
+ { timeout: 10000 },
+ )
+ .toBe('0.0.0');
+
+ // At least 2 calls proves initial load + post-reload load.
+ await expect.poll(() => counterReload, { timeout: 10000 }).toBeGreaterThanOrEqual(2);
});🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts` around lines
159 - 175, Register the page.route handler for /users/me/ before performing the
actions that trigger a version-mismatch reload, replace the fixed waitForTimeout
with a deterministic wait that polls sessionStorage (e.g. await
page.waitForFunction(() => sessionStorage.getItem('reload-version') ===
'0.0.0')), and then assert the route hit count in a stable way (either assert
counterReload >= 2 or assert counterReload === 2 only if you guarantee the first
hit cannot be missed). Update references: the page.route handler that increments
counterReload, the sessionStorage.getItem('reload-version') check, and the final
expect on counterReload.
| import { Locator, Page, TestInfo, expect } from '@playwright/test'; | ||
|
|
||
| import theme_customization from '../../../../../backend/impress/configuration/theme/default.json'; | ||
| import { version as packageJsonVersion } from '../../package.json'; |
There was a problem hiding this comment.
Use the Impress package version, not the E2E package version, for RELEASE_VERSION.
../../package.json resolves to the e2e app package, which can diverge from NEXT_PUBLIC_APP_VERSION (built from apps/impress/package.json) and cause false mismatch/reload behavior in tests.
✅ Suggested fix
-import { version as packageJsonVersion } from '../../package.json';
+import { version as packageJsonVersion } from '../../../impress/package.json';Also applies to: 44-44
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/frontend/apps/e2e/__tests__/app-impress/utils-common.ts` at line 7, The
RELEASE_VERSION is currently imported from the e2e app package.json
(packageJsonVersion from '../../package.json') which can diverge from
NEXT_PUBLIC_APP_VERSION; change the import to read the Impress app's
package.json (the apps/impress package.json used to build
NEXT_PUBLIC_APP_VERSION) and use that value for RELEASE_VERSION instead, and
update the second occurrence at the other import/site (line referenced by the
review) so both places reference the Impress package.json version; locate
occurrences by the identifier RELEASE_VERSION and the import named
packageJsonVersion and replace their source to the Impress package.json.
169c47c to
40dbbaa
Compare
40dbbaa to
bc8bc4a
Compare
We observe some cases where the frontend and backend versions can get out of sync, which can cause issues. To mitigate this, we want to implement a mechanism that detects when the frontend and backend versions are mismatched and triggers a reload of the application to ensure they are in sync.
We add the app version in Posthog events to be able to track which versions are being used and identify potential issues related to specific versions.
bc8bc4a to
d340c8f
Compare
Added - ⚡️(frontend) add skeleton on content loading #2254 - ⚡️(frontend) close websocket connection when user change tab #2264 Changed - 🏗️(core) migrate from pip to uv Fixed - 🩺(project) reload app if front and back unsync #2276 - 🐛(frontend) fix patch and comments #2273 - 🐛(frontend) interlinking are exported correctly in print mode #2269 - 💬(frontend) add missing link in onboarding description #2233 - 🐛(frontend) sanitize pasted and dropped content in document title #2210 - 🐛(frontend) Emoji menu doesn't display above comment box #2229 - 🐛(frontend) Block menu doesn't stay open on 1st line #2229 - 🐛(frontend) The "+" on the first line of a new doc doesn't work #2229 - 🐛(backend) manage race condition between GET and PATCH content #2271 - 🐛(backend) replace document creation table locks with retry strategy #2274 Security - 🔒️(frontend) sanitize color during collaboration #2270
Added - ⚡️(frontend) add skeleton on content loading #2254 - ⚡️(frontend) close websocket connection when user change tab #2264 Changed - 🏗️(core) migrate from pip to uv Fixed - 🩺(project) reload app if front and back unsync #2276 - 🐛(frontend) fix patch and comments #2273 - 🐛(frontend) interlinking are exported correctly in print mode #2269 - 💬(frontend) add missing link in onboarding description #2233 - 🐛(frontend) sanitize pasted and dropped content in document title #2210 - 🐛(frontend) Emoji menu doesn't display above comment box #2229 - 🐛(frontend) Block menu doesn't stay open on 1st line #2229 - 🐛(frontend) The "+" on the first line of a new doc doesn't work #2229 - 🐛(backend) manage race condition between GET and PATCH content #2271 - 🐛(backend) replace document creation table locks with retry strategy #2274 Security - 🔒️(frontend) sanitize color during collaboration #2270
Added - ⚡️(frontend) add skeleton on content loading #2254 - ⚡️(frontend) close websocket connection when user change tab #2264 Changed - 🏗️(core) migrate from pip to uv Fixed - 🩺(project) reload app if front and back unsync #2276 - 🐛(frontend) fix patch and comments #2273 - 🐛(frontend) interlinking are exported correctly in print mode #2269 - 💬(frontend) add missing link in onboarding description #2233 - 🐛(frontend) sanitize pasted and dropped content in document title #2210 - 🐛(frontend) Emoji menu doesn't display above comment box #2229 - 🐛(frontend) Block menu doesn't stay open on 1st line #2229 - 🐛(frontend) The "+" on the first line of a new doc doesn't work #2229 - 🐛(backend) manage race condition between GET and PATCH content #2271 - 🐛(backend) replace document creation table locks with retry strategy #2274 Security - 🔒️(frontend) sanitize color during collaboration #2270
Purpose
We observe some cases where the frontend and backend versions can get out of sync, which can cause issues.
To mitigate this, we want to implement a mechanism that detects when the frontend and backend versions are mismatched and triggers a reload of the application to ensure they are in sync.