Load scratch projects in correct locale - #1010
Conversation
In most places in editor we only have one locale per project. One place this isn't true is the new Preview page for Experience CS scratch projects- there are multiple projects that share one identifier with translated content. Elsewhere we are loading projects we use ProjectLoader, make sure we use it here to load Scratch projects too. Since we have limited ways that we can alter Scratch, we can't easily pass in a param with the locale. Instead use a header. An alternative would be to use a cookie (this is what ExCS currently does). I received an n plus one warning for loading Scratch Components - putting an include in here causes bullet to warn elsewhere as we don't always need to load the Scratch component. Since this is just a 1+1 query, I think this is fine to ignore.
Test coverage93.55% line coverage reported by SimpleCov. |
There was a problem hiding this comment.
🟡 Changes recommended
The new locale-based lookup can incorrectly 404 when the preferred-locale record is non-scratch but a scratch project exists for the same identifier in a fallback locale (regression vs the prior scratch-type-scoped lookup).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the Scratch projects API to load projects in the locale requested by the client (via X-Project-Locale), aligning Scratch project loading with the existing ProjectLoader locale-selection behavior used elsewhere in the app (notably for Experience CS preview scenarios).
Changes:
- Update Scratch
load_projectto useProjectLoader+ a scratch-type guard instead of a directfind_by!. - Add a request spec ensuring the locale header is preferred when multiple translated projects share the same identifier.
- Extend Bullet safelist configuration (dev/test) to reduce Bullet noise around
Project#scratch_component.
File summaries
| File | Description |
|---|---|
| spec/features/scratch/showing_a_scratch_project_spec.rb | Adds coverage for choosing the project matching X-Project-Locale when multiple locales exist for one identifier. |
| config/initializers/bullet.rb | Adds a dev/test Bullet safelist for Project#scratch_component and refactors the conditional block. |
| app/controllers/api/scratch/projects_controller.rb | Switches Scratch project lookup to use ProjectLoader and a scratch_project? check, enabling locale-aware selection. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Status
Points for consideration:
In most places in editor we only have one locale per project. One place this isn't true is the new Preview page for Experience CS scratch projects- there are multiple projects that share one identifier with translated content.
Use the existing ProjectLoader to load the project in the correct locale. See commits for more