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

Commit 3790a33

Browse files
author
X
authored
Merge pull request #20 from alephjs/browser-navigator-polyfill
feat: add browser `navigator` polyfill for SSR
2 parents e2cf869 + 88c61b8 commit 3790a33

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

project.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export class Project {
9090
},
9191
buildTarget: mode === 'development' ? 'es2018' : 'es2015',
9292
sourceMap: false,
93-
reactUrl: 'https://esm.sh/react@16.14.0',
94-
reactDomUrl: 'https://esm.sh/react-dom@16.14.0',
93+
reactUrl: 'https://esm.sh/react@17.0.1',
94+
reactDomUrl: 'https://esm.sh/react-dom@17.0.1',
9595
plugins: [],
9696
postcss: {
9797
plugins: [
@@ -466,7 +466,7 @@ export class Project {
466466
Object.assign(this.importMap, { imports: Object.assign({}, this.importMap.imports, imports) })
467467
}
468468

469-
const { ALEPH_IMPORT_MAP } = globalThis as any
469+
const { ALEPH_IMPORT_MAP, navigator } = globalThis as any
470470
if (ALEPH_IMPORT_MAP) {
471471
const { imports } = ALEPH_IMPORT_MAP
472472
Object.assign(this.importMap, { imports: Object.assign({}, this.importMap.imports, imports) })
@@ -525,6 +525,7 @@ export class Project {
525525
Object.assign(this.config, { sourceMap })
526526
}
527527
if (util.isNEString(defaultLocale)) {
528+
navigator.language = defaultLocale
528529
Object.assign(this.config, { defaultLocale })
529530
}
530531
if (util.isArray(locales)) {
@@ -559,8 +560,6 @@ export class Project {
559560
log.warn('bad postcss.config.json', e.message)
560561
}
561562
}
562-
// update buildID
563-
Object.assign(this, { buildID: this.mode + '.' + this.config.buildTarget })
564563
// update routing
565564
this.#routing = new Routing([], this.config.baseUrl, this.config.defaultLocale, this.config.locales)
566565
}
@@ -923,10 +922,10 @@ export class Project {
923922
break
924923
}
925924
}
926-
if (/^https?:\/\/[0-9a-z\.\-]+\/react(@[0-9a-z\.\-]+)?\/?$/i.test(dlUrl)) {
925+
if (/^(https?:\/\/[0-9a-z\.\-]+)?\/react(@[0-9a-z\.\-]+)?\/?$/i.test(dlUrl)) {
927926
dlUrl = this.config.reactUrl
928927
}
929-
if (/^https?:\/\/[0-9a-z\.\-]+\/react\-dom(@[0-9a-z\.\-]+)?(\/server)?\/?$/i.test(dlUrl)) {
928+
if (/^(https?:\/\/[0-9a-z\.\-]+)?\/react\-dom(@[0-9a-z\.\-]+)?(\/server)?\/?$/i.test(dlUrl)) {
930929
dlUrl = this.config.reactDomUrl
931930
if (/\/server\/?$/i.test(url)) {
932931
dlUrl += '/server'
@@ -1449,6 +1448,23 @@ export class Project {
14491448
Object.assign(globalThis, {
14501449
__createHTMLDocument: () => createHTMLDocument(),
14511450
document: createHTMLDocument(),
1451+
navigator: {
1452+
connection: {
1453+
downlink: 1.5,
1454+
effectiveType: "3g",
1455+
onchange: null,
1456+
rtt: 300,
1457+
saveData: false,
1458+
},
1459+
cookieEnabled: false,
1460+
deviceMemory: 8,
1461+
hardwareConcurrency: Deno.systemCpuInfo().cores,
1462+
language: 'en',
1463+
maxTouchPoints: 0,
1464+
onLine: true,
1465+
userAgent: `Deno/${Deno.version.deno}`,
1466+
vendor: "Deno Land",
1467+
},
14521468
location: {
14531469
protocol: 'http:',
14541470
host: 'localhost',

0 commit comments

Comments
 (0)