Skip to content

Commit 0eba453

Browse files
simonhaenischmanucorporat
authored andcommitted
fix(context): return values for isPrerender and isClient (#1537)
* fix(context): return values for isPrerender and isClient * Update context.ts * Update context.spec.tsx
1 parent 15bf6e5 commit 0eba453

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/runtime/context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export const getContext = (_elm: HTMLElement, context: string) => {
99
return win;
1010
} else if (context === 'document') {
1111
return doc;
12-
} else if (context === 'isServer') {
12+
} else if (context === 'isServer' || context === 'isPrerender') {
1313
return BUILD.hydrateServerSide;
14+
} else if (context === 'isClient') {
15+
return !BUILD.hydrateServerSide;
1416
} else if (context === 'resourcesUrl' || context === 'publicPath') {
1517
return getAssetPath('.');
1618
} else if (context === 'queue') {

src/runtime/test/context.spec.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ describe('context', () => {
1313
@Prop({ context: 'window' }) win: Window;
1414
@Prop({ context: 'document' }) doc: Document;
1515
@Prop({ context: 'isServer' }) isServer: boolean;
16+
@Prop({ context: 'isPrerender' }) isPrerender: boolean;
17+
@Prop({ context: 'isClient' }) isClient: boolean;
1618
@Prop({ context: 'resourcesUrl' }) resourcesUrl: string;
1719
@Prop({ context: 'publicPath' }) publicPath: string;
1820
@Prop({ context: 'queue' }) queue: QueueApi;
@@ -24,6 +26,9 @@ describe('context', () => {
2426

2527
expect(rootInstance.win).toEqual(win);
2628
expect(rootInstance.doc).toEqual(doc);
29+
expect(rootInstance.isServer).toEqual(false);
30+
expect(rootInstance.isPrerender).toEqual(false);
31+
expect(rootInstance.isClient).toEqual(true);
2732
expect(rootInstance.resourcesUrl).toEqual('/');
2833
expect(rootInstance.publicPath).toEqual('/');
2934
expect(rootInstance.queue.write).toEqual(writeTask);

0 commit comments

Comments
 (0)