• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kiva / ui / 19147367510

06 Nov 2025 07:26PM UTC coverage: 91.443% (+41.5%) from 49.902%
19147367510

push

github

emuvente
test: refactor category-row-arrows-visible-mixin test with runner method

3722 of 3979 branches covered (93.54%)

Branch coverage included in aggregate %.

18923 of 20785 relevant lines covered (91.04%)

78.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.85
/src/server-app-render.js
1
/* eslint-disable vue/multi-word-component-names, no-throw-literal */
1✔
2
import { renderSSRHead } from '@unhead/ssr';
×
3
import { renderToString } from 'vue/server-renderer';
×
4
import createApp from '#src/main';
×
5
import createRouter from '#src/router';
×
6
import getCDNHeaders from '#src/rendering/cdnHeaders';
×
7
import fillTemplate from '#src/rendering/fillTemplate';
×
8
import { renderExternals } from '#src/rendering/externals';
×
9
import renderGlobals from '#src/rendering/globals';
×
10
import renderConfigGlobal from '#src/rendering/kvConfig';
×
11
import { renderPreloadLinks } from '#src/rendering/preloadLinks';
×
12
import { preFetchAll } from '#src/util/apolloPreFetch';
×
13
import { authenticationGuard } from '#src/util/authenticationGuard';
×
14
import setBasketCookie from '#src/util/basketCookie';
×
15
import logFormatter from '#src/util/logFormatter';
×
16
import { buildUserDataGlobal } from '#src/util/optimizelyUserMetrics';
×
17
import setVisitorIdCookie from '#src/util/visitorCookie';
×
18

19
const isDev = process.env.NODE_ENV !== 'production';
×
20

21
export default async function renderPage({
×
22
        cookieStore,
×
23
        context,
×
24
        fetch,
×
25
        kvAuth0,
×
26
}) {
×
27
        const s = isDev && Date.now();
×
28

29
        const {
×
30
                url,
×
31
                cdnNotedLoggedIn,
×
32
                config,
×
33
                kivaUserAgent,
×
34
                locale,
×
35
                device,
×
36
                ssrManifest,
×
37
                template,
×
38
                forceHeader,
×
39
        } = context;
×
40

41
        // Create a new router instance. This will set the initial route and potentially redirect or 404.
42
        const router = await createRouter({ isServer: true, url });
×
43

44
        const {
×
45
                app,
×
46
                head,
×
47
                apolloClient,
×
48
                renderConfig,
×
49
        } = await createApp({
×
50
                name: '',
×
51
                appConfig: config,
×
52
                apollo: {
×
53
                        uri: config.graphqlUri,
×
54
                        types: config.graphqlPossibleTypes
×
55
                },
×
56
                cdnNotedLoggedIn,
×
57
                cookieStore,
×
58
                device,
×
59
                kvAuth0,
×
60
                locale,
×
61
                fetch,
×
62
                kivaUserAgent,
×
63
                router,
×
64
                isServer: true,
×
65
                forceHeader,
×
66
        });
×
67

68
        try {
×
69
                if (!renderConfig.useCDNCaching) {
×
70
                        // Set the visitor id cookie
71
                        setVisitorIdCookie(cookieStore);
×
72

73
                        // Set the basket cookie
74
                        await setBasketCookie(cookieStore, apolloClient);
×
75
                }
×
76

77
                // Use route meta property to determine if route needs authentication
78
                // authenticationGuard will reject promise with a redirect to login if
79
                // required authentication query fails
80
                await authenticationGuard({ route: router.currentRoute.value, apolloClient, kvAuth0 });
×
81

82
                // Pre-fetch graphql queries from the components (and all of their child components)
83
                // matched by the route
84
                // preFetchAll dispatches the queries with Apollo and returns a Promise,
85
                // which is resolved when the action is complete and apollo cache has been updated.
86
                await preFetchAll(router.currentRoute.value.matched, apolloClient, {
×
87
                        cookieStore,
×
88
                        kvAuth0,
×
89
                        route: router.currentRoute.value,
×
90
                        device,
×
91
                        renderConfig,
×
92
                });
×
93

94
                let sp; // Vue serverPrefetch timing start
×
95
                if (isDev) {
×
96
                        logFormatter(`data pre-fetch: ${Date.now() - s}ms`);
×
97
                        sp = new Date();
×
98
                }
×
99

100
                // render the app
101
                const appHtml = await renderToString(app, context);
×
102

103
                if (isDev) logFormatter(`vue serverPrefetch: ${Date.now() - sp}ms`);
×
104

105
                // After all preFetch hooks are resolved, our store is now
106
                // filled with the state needed to render the app.
107
                // Expose the state on the render context, and let the request handler
108
                // inline the state in the HTML response. This allows the client-side
109
                // store to pick-up the server-side state without having to duplicate
110
                // the initial data fetching on the client.
111
                const globals = {
×
112
                        __APOLLO_STATE__: apolloClient.cache.extract(),
×
113
                };
×
114
                if (!router.currentRoute.value.meta?.useCDNCaching) {
×
115
                        const pageData = buildUserDataGlobal(router.currentRoute.value, cookieStore, apolloClient);
×
116
                        if (pageData) {
×
117
                                globals.pageData = pageData;
×
118
                        }
×
119
                }
×
120
                const appState = renderGlobals(globals);
×
121

122
                // render head tags
123
                const payload = await renderSSRHead(head);
×
124

125
                // render preload links
126
                const preloadLinks = renderPreloadLinks(context.modules, ssrManifest);
×
127

128
                const templateData = {
×
129
                        ...payload,
×
130
                        // Turn off SSR for local development to prevent component FOUC (Flash of Unstyled Content)
131
                        // https://github.com/vitejs/vite/issues/6887#issuecomment-1038664078
132
                        appHtml: isDev ? '' : appHtml,
×
133
                        appState,
×
134
                        appConfig: renderConfigGlobal(config),
×
135
                        externals: renderExternals(config),
×
136
                        googleTagmanagerId: config.googleTagmanagerId,
×
137
                        preloadLinks,
×
138
                        // Do not add manifest for local development, as the urls in the manifest do not match their
139
                        // correct location in the vite dev server and cause 404s.
140
                        webManifest: isDev ? '' : '<link rel="manifest" href="/static/manifest.webmanifest">',
×
141
                };
×
142

143
                return {
×
144
                        cdnHeaders: getCDNHeaders(renderConfig),
×
145
                        html: fillTemplate(template, templateData),
×
146
                        setCookies: cookieStore.getSetCookies(),
×
147
                };
×
148
        } catch (error) {
×
149
                if (error instanceof Error) {
×
150
                        throw error;
×
151
                } else {
×
152
                        context.setCookies = cookieStore.getSetCookies();
×
153
                        throw {
×
154
                                url: router.resolve(error).href,
×
155
                        };
×
156
                }
×
157
        }
×
158
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc