fix: stop false-positive "Missing records in staticData" SSR warning#3524
fix: stop false-positive "Missing records in staticData" SSR warning#3524Anty0 wants to merge 1 commit into
Conversation
WalkthroughCore now publicly re-exports ChangesSSR Cache Key Standardization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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)
Comment |
useTolgeeSSR (React) and TolgeeProvider (Vue) built the comparison key
inline as `${namespace}:${language}`, the inverse of core's encodeCacheKey
(`${language}:${namespace}`), so every present record was reported missing.
Both sites now reuse the now-exported encodeCacheKey instead of re-deriving
the format, removing the duplication that allowed the drift. The warning is
also emitted only when records are actually missing, so a sufficient
staticData set no longer logs an empty warning.
Adds regression tests in both packages for the false-positive, plus a Vue
test for the empty-list guard (reachable there via function-valued static
data; in React the guard is defensive only, since missing records and the
loaded check derive from the same cache).
0e6f170 to
92eff3d
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@packages/react/src/__integration/useTolgeeSSR.spec.tsx`:
- Around line 34-50: Add a new test that asserts no warning is emitted when all
required SSR records are present: render SsrComponent with data containing both
keys created via encodeCacheKey({ language: 'en', namespace: 'common' }) and
encodeCacheKey({ language: 'en', namespace: 'extra' }) (use enCommon and a
simple { extra: 'Extra' } object), then expect warnSpy.not.toHaveBeenCalled();
place this alongside the existing "warns only..." spec so it validates the
empty-list/no-warning scenario.
- Line 1: Add a second SSR test alongside the existing missing-records test that
supplies all required translation keys so missingRecords is empty and assert
that warnSpy was not called; locate the existing test suite (the one importing
act) and add a new test (e.g., "does not warn when all required records are
provided (SSR)") which sets up the SSR Tolgee provider with the full set of
required keys, renders/executes the same SSR path used by the existing test,
then expect(warnSpy).not.toHaveBeenCalled(); optionally, if you prefer
consistency, import act from `@testing-library/react` instead of react (this is
not necessary for correctness).
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bb95342d-2efd-4b60-9d83-1dda6d5c6d15
📒 Files selected for processing (5)
packages/core/src/index.tspackages/react/src/__integration/useTolgeeSSR.spec.tsxpackages/react/src/useTolgeeSSR.tspackages/vue/src/TolgeeProvider.tspackages/vue/src/__integration/TolgeeProviderSsr.spec.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/core/src/index.ts
- packages/react/src/useTolgeeSSR.ts
- packages/vue/src/TolgeeProvider.ts
- packages/vue/src/__integration/TolgeeProviderSsr.spec.ts
Problem
useTolgeeSSR(React) andTolgeeProvider(Vue) logeven when the required records are present in
staticData. SSR works correctly — the warning is simply wrong, which sends users debugging a non-existent problem.The two sites built the comparison key inline as
`${namespace}:${language}`, but every cache key in@tolgee/coreis produced byencodeCacheKeyas`${language}:${namespace}`. Because the orders are inverted, the lookup never matched and every record was reported missing.This duplicated, hand-rolled encoding is the root cause: the format rule lived in three independent copies, and the two SSR copies silently drifted from the canonical one.
Solution
encodeCacheKeyfrom@tolgee/core(it already flows to@tolgee/webviaexport *) and reuse it at both SSR sites instead of re-deriving the key format. This removes the duplication so the orders can no longer drift apart.staticDataset previously still logged an empty…functionality:message (reachable in Vue via lazy/function-valued static data).encodeCacheKeyso the tests catch any future drift on either side.Out of scope
In React the missing-records check compares against the cache (
getAllRecords()), which never stores function-valued (lazy) static data, so a React app that supplies all required namespaces as lazy loaders would still see a false warning. This is pre-existing behaviour on a different axis (lazy vs. eager) and is left for a separate change; the React empty-records guard here is therefore defensive only, since missing-records and the loaded check derive from the same cache.Supersedes #3518 (external PR; reuses the canonical encoder rather than only correcting the literals, and adds tests).
Summary by CodeRabbit
New Features
Bug Fixes
Tests