Skip to content

Commit

Permalink
Merge pull request #65 from remix-pwa/fix/remix-v2
Browse files Browse the repository at this point in the history
upgrade to latest remix-run
  • Loading branch information
ShafSpecs authored Sep 21, 2023
2 parents 38f8e58 + db36fce commit 110e318
Show file tree
Hide file tree
Showing 12 changed files with 7,720 additions and 4,437 deletions.
12,081 changes: 7,683 additions & 4,398 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"prettier": "^3.0.3",
"prettier-plugin-organize-imports": "^3.2.3",
"semver": "^7.5.4",
"turbo": "^1.10.13",
"turbo": "^1.10.14",
"typescript": "^5.2.2",
"vitest": "^0.34.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"stdin-discarder": "^0.1.0"
},
"devDependencies": {
"@remix-run/dev": "^1.19.3",
"@remix-run/dev": "^2.0.0",
"@remix-pwa/worker-runtime": "^2.0.2",
"@remix-pwa/eslint-config": "^0.0.0",
"@remix-pwa/lint-staged-config": "^0.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/dev/worker-build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference lib="WebWorker" />
import type { AppData, AppLoadContext, DataFunctionArgs } from '@remix-run/server-runtime';
import type { ActionFunction, AppLoadContext, DataFunctionArgs, LoaderFunction } from '@remix-run/server-runtime';
import type { ServerRouteModule } from '@remix-run/server-runtime/dist/routeModules.js';
import type { ServerRoute } from '@remix-run/server-runtime/dist/routes.js';

Expand All @@ -19,12 +19,12 @@ export type WorkerDataFunctionArgs = Omit<DataFunctionArgs, 'context'> & {
export type WorkerLoaderArgs = WorkerDataFunctionArgs;
export type WorkerActionArgs = WorkerDataFunctionArgs;
export interface WorkerActionFunction {
(args: WorkerActionArgs): Promise<Response> | Response | Promise<AppData> | AppData;
(args: WorkerActionArgs): ReturnType<ActionFunction>;
}
export interface WorkerLoaderFunction {
(args: WorkerLoaderArgs): Promise<Response> | Response | Promise<AppData> | AppData;
(args: WorkerLoaderArgs): ReturnType<LoaderFunction>;
}
export type DefaultFetchHandler = WorkerActionFunction | WorkerLoaderFunction;
export type DefaultFetchHandler = (args: WorkerDataFunctionArgs) => Promise<Response>;
export type DefaultErrorHandler = (error: Error, args: WorkerDataFunctionArgs) => void;
export interface WorkerRouteModule extends ServerRouteModule {
workerAction?: WorkerActionFunction;
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
"test": "vitest --run --environment node --threads --single-thread --pass-with-no-tests"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-disable": "^2.0.3",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.7.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-security-node": "^1.1.1",
"eslint-plugin-sort-destructure-keys": "^1.5.0",
"eslint-plugin-turbo": "^1.10.13",
"eslint-plugin-turbo": "^1.10.14",
"eslint-plugin-vitest": "^0.3.1"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/sw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"@remix-pwa/cache": "^2.0.3",
"@remix-pwa/eslint-config": "^0.0.0",
"@remix-pwa/lint-staged-config": "^0.0.0",
"@remix-run/react": "^1.19.3",
"@remix-run/dev": "^1.19.3",
"@types/react": "^18.2.21",
"@remix-run/react": "^2.0.0",
"@remix-run/dev": "^2.0.0",
"@types/react": "^18.2.22",
"react": "^18.2.0",
"rimraf": "^5.0.1"
},
"dependencies": {
"@remix-run/server-runtime": "^1.19.3",
"@remix-run/server-runtime": "^2.0.0",
"idb": "^7.1.1",
"tiny-invariant": "^1.3.1"
}
Expand Down
12 changes: 6 additions & 6 deletions packages/sw/src/hooks/useSWEffect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RouteMatch } from '@remix-run/react';
import type { UIMatch } from '@remix-run/react';
import { useLocation, useMatches } from '@remix-run/react';
import { useEffect, useRef } from 'react';

Expand Down Expand Up @@ -35,6 +35,7 @@ export function useSWEffect(): void {
type: 'REMIX_NAVIGATION',
isMount: mounted,
location,
// @ts-expect-error
matches: matches.filter(filteredMatches).map(sanitizeHandleObject),
manifest: window.__remixManifest,
});
Expand All @@ -45,6 +46,7 @@ export function useSWEffect(): void {
type: 'REMIX_NAVIGATION',
isMount: mounted,
location,
// @ts-expect-error
matches: matches.filter(filteredMatches).map(sanitizeHandleObject),
manifest: window.__remixManifest,
});
Expand All @@ -56,7 +58,7 @@ export function useSWEffect(): void {
}
}

function filteredMatches(route: RouteMatch) {
function filteredMatches(route: UIMatch) {
if (route.data) {
return (
Object.values(route.data).filter(elem => {
Expand All @@ -67,18 +69,16 @@ export function useSWEffect(): void {
return true;
}

function sanitizeHandleObject(route: RouteMatch) {
function sanitizeHandleObject(route: UIMatch) {
let handle = route.handle;

if (handle) {
const filterInvalidTypes = ([, value]: any) => !isPromise(value) && !isFunction(value);

// @ts-ignore Seems like typescript had too much fun last night :(
handle = Object.fromEntries(Object.entries(route.handle!).filter(filterInvalidTypes));
}
return { ...route, handle };
}

return () => {};
return () => { };
}, [location, matches]);
}
10 changes: 4 additions & 6 deletions packages/sw/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference lib="WebWorker" />
import type { AppData, AppLoadContext, DataFunctionArgs } from '@remix-run/server-runtime';
import type { ActionFunction, AppLoadContext, DataFunctionArgs, LoaderFunction } from '@remix-run/server-runtime';
import type { ServerRouteModule } from '@remix-run/server-runtime/dist/routeModules.js';
import type { ServerRoute } from '@remix-run/server-runtime/dist/routes.js';

Expand Down Expand Up @@ -36,14 +36,14 @@ export type WorkerActionArgs = WorkerDataFunctionArgs;
* A worker action function.
*/
export interface WorkerActionFunction {
(args: WorkerActionArgs): Promise<Response> | Response | Promise<AppData> | AppData;
(args: WorkerActionArgs): ReturnType<ActionFunction>;
}

/**
* A worker loader function.
*/
export interface WorkerLoaderFunction {
(args: WorkerLoaderArgs): Promise<Response> | Response | Promise<AppData> | AppData;
(args: WorkerLoaderArgs): ReturnType<LoaderFunction>;
}

export interface WorkerRouteModule extends ServerRouteModule {
Expand All @@ -69,9 +69,7 @@ export interface WorkerRouteManifest {
*
* This acts as a fallback when a route doesn't have a worker action or loader.
*/
export type DefaultFetchHandler = (
args: WorkerDataFunctionArgs
) => Promise<Response> | Response | Promise<AppData> | AppData;
export type DefaultFetchHandler = (args: WorkerDataFunctionArgs) => Promise<Response>;

/**
* The default error handler.
Expand Down
2 changes: 1 addition & 1 deletion packages/worker-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@remix-run/router": "^1.9.0"
},
"devDependencies": {
"@remix-run/server-runtime": "^1.19.3",
"@remix-run/server-runtime": "^2.0.0",
"@remix-pwa/eslint-config": "^0.0.0",
"@remix-pwa/lint-staged-config": "^0.0.0",
"cross-env": "^7.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('handleRequest', () => {
const event = {
request: new Request('https://example.com/route2'),
} as FetchEvent;
const defaultHandler = vi.fn(() => new Response('Default handler response'));
const defaultHandler = vi.fn().mockResolvedValue(new Response('Default handler response'));
const errorHandler = vi.fn();
const loadContext = {} as WorkerLoadContext;

Expand Down
4 changes: 2 additions & 2 deletions packages/worker-runtime/src/utils/handle-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function handleLoader({ event, loadContext, loader, routeId, routePath }:
if (result === undefined) {
throw new Error(
`You defined a loader for route "${routeId}" but didn't return ` +
`anything from your \`worker loader\` function. Please return a value or \`null\`.`
`anything from your \`worker loader\` function. Please return a value or \`null\`.`
);
}

Expand Down Expand Up @@ -136,7 +136,7 @@ async function handleAction({ action, event, loadContext, routeId, routePath }:
if (result === undefined) {
throw new Error(
`You defined an action for route "${routeId}" but didn't return ` +
`anything from your \`worker action\` function. Please return a value or \`null\`.`
`anything from your \`worker action\` function. Please return a value or \`null\`.`
);
}

Expand Down
18 changes: 9 additions & 9 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@
"@remix-pwa/sw": "2.1.2",
"@remix-pwa/sync": "^2.0.1",
"@remix-pwa/worker-runtime": "^2.0.2",
"@remix-run/css-bundle": "^1.19.3",
"@remix-run/node": "^1.19.3",
"@remix-run/react": "^1.19.3",
"@remix-run/serve": "^1.19.3",
"@remix-run/css-bundle": "^2.0.0",
"@remix-run/node": "^2.0.0",
"@remix-run/react": "^2.0.0",
"@remix-run/serve": "^2.0.0",
"dexie": "^3.2.4",
"dotenv": "^16.3.1",
"isbot": "^3.6.13",
"isbot": "^3.7.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@remix-pwa/dev": "^2.0.12",
"@remix-run/dev": "^1.19.3",
"@remix-run/eslint-config": "^1.19.3",
"@types/react": "^18.2.21",
"@remix-run/dev": "^2.0.0",
"@remix-run/eslint-config": "^2.0.0",
"@types/react": "^18.2.22",
"@types/react-dom": "^18.2.7",
"eslint": "^8.49.0",
"npm-run-all": "^4.1.5",
"remix-pwa": "^3.0.4",
"remix-pwa": "^3.0.6",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2"
},
Expand Down

0 comments on commit 110e318

Please sign in to comment.