Skip to content

Commit

Permalink
Add automatic fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos committed Oct 23, 2024
1 parent bacbd82 commit 07deb71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@croct/content": "^1.0.0",
"@croct/plug": "^0.16.2",
"@croct/plug-react": "^0.9.0",
"@croct/sdk": "^0.17.4",
Expand Down
5 changes: 5 additions & 0 deletions src/server/fetchContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@ export function fetchContent<I extends VersionedSlotId, C extends JsonObject>(
},
...commonOptions,
...rest,
}).catch(error => {
const locale = options.preferredLocale ?? null;
const file = `${slotId}${locale !== null ? `.${locale}` : ''}.json`;

return import(`@croct/content/${file}`).catch(() => Promise.reject(error));
});
}

0 comments on commit 07deb71

Please sign in to comment.