fix: strip language prefix from full_slug when Translatable Slugs app is not installed - #119
Merged
Merged
Conversation
… is not installed
Stories fetched with ?language= return a language-prefixed full_slug
("en/about-us") when the Translatable Slugs app is not installed
(default_full_slug is null). ResolveControllerListener fed that prefixed
slug back into StoriesApi::bySlug() for its second fetch (link/relation
resolving), which the Content Delivery API answers with 404 - breaking
every non-default-locale page whose controller declares resolveLinks or
resolveRelations.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.x #119 +/- ##
============================================
+ Coverage 94.30% 94.32% +0.01%
- Complexity 476 480 +4
============================================
Files 54 54
Lines 1493 1498 +5
============================================
+ Hits 1408 1413 +5
Misses 85 85 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Data-provider test pinning the slug used for the second story fetch: with the app installed (default_full_slug wins, even for translated slugs), without the app (language prefix stripped, incl. nested slugs), and the edge cases: unprefixed full_slug for a non-default language, missing lang key, and a real story path whose first segment equals a language code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a story is fetched with the
?language=parameter and the Translatable Slugs app is not installed in the space, the Content Delivery API returns:default_full_slug:nullfull_slug: prefixed with the requested language, e.g.en/about-usResolveControllerListeneruses$story['default_full_slug'] ?? $story['full_slug']and feeds that slug back intoStoriesApi::bySlug()for its second fetch (when the controller declaresresolveRelations/resolveLinks) and into the controller registry slug lookup. The API does not know the language-prefixed slug and responds with 404 — so every non-default-locale page whose controller declaresresolveRelationsorresolveLinksthrows aStoryNotFoundException, while the default locale keeps working (itsfull_slugis never prefixed).With
ascending_redirect_fallbackenabled the symptom is even more confusing: the fallback then requests the parent slug (usually a folder) and surfaces its 404, e.g.HTTP/2 404 returned for "https://api.storyblok.com/v2/cdn/stories/raeume?language=en".Fix
When
default_full_slugisnulland the story'slangis notdefault, strip the{lang}/prefix fromfull_slugbefore the slug is reused. Spaces with the Translatable Slugs app installed are unaffected (default_full_slugtakes precedence as before).Testing
default_full_slug: null,full_slug: "en/…",lang: "en"and a controller declaringresolveLinks— asserts bothbySlug()calls receive the unprefixed slug and the controller still resolves by slug.🤖 Generated with Claude Code