Skip to content

Commit c5317c8

Browse files
authored
Merge pull request #162 from gadget-inc/another-qf
making the code a bit more efficient
2 parents d642ee5 + d94d264 commit c5317c8

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

shopify/product-quiz-public-remix-ssr/web/routes/_app.install.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,30 @@ export async function loader({ context }: LoaderFunctionArgs) {
5454
id: themes.nodes[0].id.split("/").pop(),
5555
};
5656

57+
const themeRaw = {
58+
rawQuizPageLiquid: "",
59+
rawProductQuizJs: "",
60+
};
61+
5762
// If the theme isn't Online Store 2.0, we need to fetch the raw files for the quiz page and JavaScript.
58-
if (!themes.nodes[0].files.nodes.length) theme.onlineStore2 = false;
63+
if (!themes.nodes[0].files.nodes.length) {
64+
theme.onlineStore2 = false;
65+
66+
const [rawQuizPageLiquid, rawProductQuizJs] = await Promise.all([
67+
fs.readFile(
68+
path.join(process.cwd(), "extensions", "quiz", "blocks", "quiz.liquid"),
69+
"utf-8"
70+
),
71+
fs.readFile(
72+
path.join(process.cwd(), "extensions", "quiz", "assets", "quiz.js"),
73+
"utf-8"
74+
),
75+
]);
76+
77+
themeRaw.rawQuizPageLiquid = rawQuizPageLiquid;
78+
79+
themeRaw.rawProductQuizJs = rawProductQuizJs;
80+
}
5981

6082
// Returns an object with the theme information and the shop domain.
6183
return json({
@@ -66,14 +88,7 @@ export async function loader({ context }: LoaderFunctionArgs) {
6688
domain: true,
6789
},
6890
}),
69-
rawQuizPageLiquid: await fs.readFile(
70-
path.join(process.cwd(), "extensions", "quiz", "blocks", "quiz.liquid"),
71-
"utf-8"
72-
),
73-
rawProductQuizJs: await fs.readFile(
74-
path.join("extensions", "quiz", "assets", "quiz.js"),
75-
"utf-8"
76-
),
91+
...themeRaw,
7792
});
7893
}
7994

0 commit comments

Comments
 (0)