Fix statically replaced HASH_ROUTING env variables

Also moves the HASH_ROUTING env variable from being modified inside the
hashRouter.spec.ts into the webserver config in the
playwright.config.ipfs.ts

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-04-03 11:50:24 +02:00
committed by Rūdolfs Ošiņš
parent 6a03ccef2d
commit 4c3bd7ee04
10 changed files with 45 additions and 33 deletions
+1 -1
View File
@@ -23,7 +23,7 @@
if (!window.VITEST && !window.PLAYWRIGHT && import.meta.env.PROD) {
const plausible = Plausible({
domain: "app.radicle.xyz",
hashMode: window.HASH_ROUTING,
hashMode: import.meta.env.VITE_HASH_ROUTING,
});
plausible.enableAutoPageviews();
+14
View File
@@ -0,0 +1,14 @@
/* eslint-disable @typescript-eslint/naming-convention */
// Defined by vite or by custom passed env variables
// Custom entries will be defined as globals during dev and statically replaced during build.
interface ImportMeta extends Readonly<Record<string, unknown>> {
env: {
MODE: string;
BASE_URL: string;
PROD: boolean;
DEV: boolean;
SSR: boolean;
VITE_HASH_ROUTING: boolean;
};
}
-1
View File
@@ -8,7 +8,6 @@ declare global {
// production.
VITEST: boolean;
PLAYWRIGHT: boolean;
HASH_ROUTING: boolean;
// APP_CONFIG is set from within Playwright tests at runtime.
// To better understand how it works together, have a look at:
+4 -4
View File
@@ -16,7 +16,7 @@ export const activeRouteStore: Readable<Route> = derived(
},
);
export const base = window.HASH_ROUTING ? "./" : "/";
export const base = import.meta.env.VITE_HASH_ROUTING ? "./" : "/";
// Gets triggered when clicking on an anchor hash tag e.g. <a href="#header"/>
// Allows the jump to a anchor hash
@@ -97,7 +97,7 @@ export const push = (newRoute: Route): void => {
// one subsequent pop() anyway.
historyStore.set([...history, newRoute].slice(-10));
const path = window.HASH_ROUTING
const path = import.meta.env.VITE_HASH_ROUTING
? "#" + routeToPath(newRoute)
: routeToPath(newRoute);
@@ -116,7 +116,7 @@ export const pop = (): void => {
export function replace(newRoute: Route): void {
historyStore.set([newRoute]);
const path = window.HASH_ROUTING
const path = import.meta.env.VITE_HASH_ROUTING
? "#" + routeToPath(newRoute)
: routeToPath(newRoute);
@@ -142,7 +142,7 @@ function pathToRoute(path: string): Route | null {
}
const url = new URL(path, window.origin);
const segments = window.HASH_ROUTING
const segments = import.meta.env.VITE_HASH_ROUTING
? url.hash.substring(2).split("#")[0].split("/") // Try to remove any additional hashes at the end of the URL.
: url.pathname.substring(1).split("/");