Skip to content

Commit 8ba5896

Browse files
committed
fix: check if page was already translated
This prevent loops between two onCreatePage implementations.
1 parent b76b086 commit 8ba5896

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/onCreatePage/translatePage.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,20 @@ describe('translatePage', () => {
238238
},
239239
});
240240
});
241+
242+
it('should skip already translated pages', () => {
243+
const page: Page = {
244+
path: '/imprint',
245+
component: {} as any,
246+
context: {
247+
locale: 'de-CH',
248+
localePagesId: 'imprint',
249+
},
250+
};
251+
252+
translatePage({ page, actions } as any, options);
253+
254+
expect(actions.deletePage).not.toBeCalled();
255+
expect(actions.createPage).not.toBeCalled();
256+
});
241257
});

src/onCreatePage/translatePage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { generatePageContextByPath, translatePagePath, translatePagePaths } from
66
export const translatePage = async ({ page, actions }: CreatePageArgs<SitePageContext>, options: PluginOptions) => {
77
const { createPage, deletePage } = actions;
88

9+
// If this page was already translated, we skip it.
10+
if (page.context?.locale && page.context.localePagesId) {
11+
return;
12+
}
13+
914
// Translate statefully created pages from `/src/pages` or gatsby-plugin-page-creator
1015
if (options && page.isCreatedByStatefulCreatePages) {
1116
const paths = translatePagePaths(page.path, options);

0 commit comments

Comments
 (0)