Skip to content

Commit 489ac3e

Browse files
author
Alex Lohr
committed
remove remaining server.ts files
1 parent d2bfe3b commit 489ac3e

File tree

10 files changed

+59
-118
lines changed

10 files changed

+59
-118
lines changed

packages/page-visibility/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { createSharedRoot } from "@solid-primitives/rootless";
1414
* ```
1515
*/
1616
export const createPageVisibility = (): Accessor<boolean> => {
17+
if (process.env.SSR) {
18+
return () => true;
19+
}
1720
const [state, setState] = createSignal(document.visibilityState === "visible");
1821
const cb = () => setState(document.visibilityState === "visible");
1922
document.addEventListener("visibilitychange", cb);
@@ -35,4 +38,6 @@ export const createPageVisibility = (): Accessor<boolean> => {
3538
* })
3639
* ```
3740
*/
38-
export const usePageVisibility = /*#__PURE__*/ createSharedRoot(createPageVisibility);
41+
export const usePageVisibility = process.env.SSR
42+
? /*#__PURE__*/ () => () => true
43+
: /*#__PURE__*/ createSharedRoot(createPageVisibility);

packages/page-visibility/src/server.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/platform/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const ua = navigator.userAgent;
2-
const w = window as any;
1+
const w = process.env.SSR ? { document: {}, navigator: { userAgent: '' } } : window as any;
2+
const n = w.navigator
3+
const ua = process.env.SSR ? '' : n.userAgent;
34

45
//
56
// Devices
@@ -18,7 +19,7 @@ export const isMac: boolean = /*#__PURE__*/ /(macintosh|macintel|macppc|mac68k|m
1819
export const isIPhone: boolean = /*#__PURE__*/ /iphone/i.test(ua);
1920

2021
/** Is IPad Device */
21-
export const isIPad: boolean = /*#__PURE__*/ /ipad/i.test(ua) && navigator.maxTouchPoints > 1;
22+
export const isIPad: boolean = /*#__PURE__*/ /ipad/i.test(ua) && n.maxTouchPoints > 1;
2223

2324
/** Is IPod Device */
2425
export const isIPod: boolean = /*#__PURE__*/ /ipod/i.test(ua);
@@ -49,7 +50,7 @@ export const isSafari: boolean =
4950
w.safari?.pushNotification + "" === "[object SafariRemoteNotification]";
5051

5152
/** Browser is Internet Explorer 6-11 */
52-
export const isIE = /*@cc_on!@*/ false || !!(document as any).documentMode;
53+
export const isIE = /*@cc_on!@*/ false || !!(w.document as any).documentMode;
5354

5455
/** is Chromium-based browser */
5556
export const isChromium: boolean = !!w.chrome;
@@ -59,7 +60,7 @@ export const isEdge: boolean = /*#__PURE__*/ /Edg/.test(ua) && isChromium;
5960

6061
/** Browser is Chrome */
6162
export const isChrome: boolean =
62-
isChromium && navigator.vendor === "Google Inc." && !isOpera && !isEdge;
63+
isChromium && n.vendor === "Google Inc." && !isOpera && !isEdge;
6364

6465
//
6566
// Rendering Engines

packages/platform/src/server.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/upload/src/createDropzone.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { noop } from "@solid-primitives/utils";
12
import { createSignal, JSX, onCleanup, onMount } from "solid-js";
23
import { transformFiles } from "./helpers";
34
import { UploadFile, Dropzone, DropzoneOptions } from "./types";
@@ -28,6 +29,15 @@ import { UploadFile, Dropzone, DropzoneOptions } from "./types";
2829
function createDropzone<T extends HTMLElement = HTMLElement>(
2930
options?: DropzoneOptions
3031
): Dropzone<T> {
32+
if (process.env.SSR) {
33+
return {
34+
setRef: noop,
35+
files: () => [],
36+
isDragging: () => false,
37+
removeFile: noop,
38+
clearFiles: noop
39+
}
40+
}
3141
const [files, setFiles] = createSignal<UploadFile[]>([]);
3242
const [isDragging, setIsDragging] = createSignal(false);
3343

packages/upload/src/createFileUploader.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { noop } from "@solid-primitives/utils";
12
import { createSignal, JSX } from "solid-js";
23
import { transformFiles, createInputComponent } from "./helpers";
34
import { FileUploader, FileUploaderOptions, UploadFile, UserCallback } from "./types";
@@ -22,6 +23,14 @@ import { FileUploader, FileUploaderOptions, UploadFile, UserCallback } from "./t
2223
* ```
2324
*/
2425
function createFileUploader(options?: FileUploaderOptions): FileUploader {
26+
if (process.env.SSR) {
27+
return {
28+
files: () => [],
29+
selectFiles: noop,
30+
removeFile: noop,
31+
clearFiles: noop
32+
};
33+
}
2534
const [files, setFiles] = createSignal<UploadFile[]>([]);
2635

2736
let userCallback: UserCallback = () => {};

packages/upload/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ declare module "solid-js" {
1111
}
1212

1313
export const fileUploader = (element: HTMLInputElement, options: () => FileUploaderDirective) => {
14+
if (process.env.SSR) {
15+
return;
16+
}
1417
const { userCallback, setFiles } = options();
1518

1619
onMount(() => {

packages/upload/src/server.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/workers/src/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import { cjs, setup, KILL, RPC } from "./utils";
1010
* @returns An array with worker, start and stop methods
1111
*/
1212
export function createWorker(...args: (Function | object)[]): WorkerExports {
13+
if (process.env.SSR) {
14+
return [
15+
new EventTarget() as unknown as Worker,
16+
() => {},
17+
() => {},
18+
new Set()
19+
]
20+
}
1321
const exports = new Set<string>();
1422
let code = "";
1523
let options = {};
@@ -69,6 +77,13 @@ export const createWorkerPool = (
6977
concurrency: number = 1,
7078
...args: (Function | object)[]
7179
): WorkerExports => {
80+
if (process.env.SSR) {
81+
return [
82+
new EventTarget() as unknown as Worker,
83+
() => {},
84+
() => {}
85+
]
86+
}
7287
let current = -1;
7388
let workers: WorkerExports[] = [];
7489
const start = () => {
@@ -113,6 +128,16 @@ export type WorkerInstruction = {
113128
export const createSignaledWorker = (
114129
...args: WorkerInstruction[]
115130
): [start: () => void, stop: () => void] => {
131+
if (process.env.SSR) {
132+
return [
133+
() => {
134+
/*noop*/
135+
},
136+
() => {
137+
/*noop*/
138+
}
139+
];
140+
}
116141
let fns = [];
117142
for (const i in args) {
118143
const { input, output, func } = args[i];

packages/workers/src/server.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)