Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 068062f

Browse files
committed
refactor: remove browser polyfill objects
1 parent 62ecc95 commit 068062f

File tree

2 files changed

+10
-56
lines changed

2 files changed

+10
-56
lines changed

framework/react/renderer.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,8 @@ export async function renderPage(
6969
const useDenUrl = `useDeno://${url.pathname}`
7070
const useDenoAsyncCalls: Array<Promise<any>> = []
7171

72-
Object.assign(window, {
72+
Object.assign(globalThis, {
7373
[`__asyncData_${useDenUrl}`]: {},
74-
location: {
75-
protocol: 'http:',
76-
host: 'localhost',
77-
hostname: 'localhost',
78-
port: '',
79-
href: 'https://localhost' + url.pathname + url.query.toString(),
80-
origin: 'https://localhost',
81-
pathname: url.pathname,
82-
search: url.query.toString(),
83-
hash: '',
84-
reload() { },
85-
replace() { },
86-
toString() { return this.href },
87-
}
8874
})
8975

9076
events.on(useDenUrl, (id: string, ret: any, async: boolean) => {

server/project.ts

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -579,45 +579,8 @@ export class Project {
579579
log.info(colors.bold('- Global'))
580580
await this._loadConfig()
581581

582-
// inject virtual browser gloabl objects
583-
Object.assign(globalThis, {
584-
navigator: {
585-
connection: {
586-
downlink: 1.5,
587-
effectiveType: "3g",
588-
onchange: null,
589-
rtt: 300,
590-
saveData: false,
591-
},
592-
cookieEnabled: false,
593-
deviceMemory: 0,
594-
hardwareConcurrency: 0,
595-
language: this.config.defaultLocale,
596-
maxTouchPoints: 0,
597-
onLine: true,
598-
userAgent: `Deno/${Deno.version.deno}`,
599-
vendor: "Deno Land",
600-
},
601-
location: {
602-
protocol: 'http:',
603-
host: 'localhost',
604-
hostname: 'localhost',
605-
port: '',
606-
href: 'https://localhost/',
607-
origin: 'https://localhost',
608-
pathname: '/',
609-
search: '',
610-
hash: '',
611-
reload() { },
612-
replace() { },
613-
toString() { return this.href },
614-
},
615-
innerWidth: 1920,
616-
innerHeight: 1080,
617-
devicePixelRatio: 1,
618-
$RefreshReg$: () => { },
619-
$RefreshSig$: () => (type: any) => type,
620-
})
582+
// change current work dir to appDoot
583+
Deno.chdir(this.appRoot)
621584

622585
// inject env variables
623586
Object.entries({
@@ -626,8 +589,13 @@ export class Project {
626589
__buildMode: this.mode,
627590
}).forEach(([key, value]) => Deno.env.set(key, value))
628591

629-
// change current work dir to appDoot
630-
Deno.chdir(this.appRoot)
592+
// add react refresh helpers for ssr
593+
if (this.isDev) {
594+
Object.assign(globalThis, {
595+
$RefreshReg$: () => { },
596+
$RefreshSig$: () => (type: any) => type,
597+
})
598+
}
631599

632600
// check custom components
633601
for await (const { path: p, } of walk(this.srcDir, { ...walkOptions, maxDepth: 1, exts: [...walkOptions.exts, '.tsx', '.jsx'] })) {

0 commit comments

Comments
 (0)