Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solidjs/router

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solidjs/router - npm Package Compare versions

Comparing version 0.10.0-beta.1 to 0.10.0-beta.2

dist/data/response.d.ts

6

dist/components.jsx

@@ -12,3 +12,3 @@ /*@refresh skip*/

(isServer
? staticIntegration({ value: url || ((e = getRequestEvent()) && e.request.url) || "" })
? staticIntegration({ value: url || ((e = getRequestEvent()) && getPath(e.request.url)) || "" })
: pathIntegration());

@@ -22,2 +22,6 @@ const routeDefs = children(() => props.children);

};
function getPath(url) {
const u = new URL(url);
return u.pathname + u.search;
}
function Routes(props) {

@@ -24,0 +28,0 @@ const matches = createMemo(() => getRouteMatches(props.branches, props.routerState.location.pathname));

35

dist/data/action.js

@@ -52,2 +52,7 @@ import { $TRACK, createMemo, createSignal } from "solid-js";

const router = this;
async function handler(res) {
const data = await handleResponse(res, router.navigatorFactory());
data ? setResult({ data }) : submission.clear();
return data;
}
router.submissions[1](s => [

@@ -70,10 +75,3 @@ ...s,

const p = fn(variables);
p.then(async (data) => {
const keys = handleResponse(data, router.navigatorFactory());
await revalidate(keys);
data ? setResult({ data }) : submission.clear();
return data;
}).catch(error => {
setResult({ data: error });
});
p.then(handler, handler);
return p;

@@ -83,13 +81,6 @@ }

]);
p.then(async (data) => {
const keys = handleResponse(data, router.navigatorFactory());
await revalidate(keys);
data ? setResult({ data }) : submission.clear();
return data;
}).catch(error => {
setResult({ data: error });
});
p.then(handler, handler);
return p;
}
const url = fn.url || `action:${name}` || !isServer ? `action:${fn.name}` : "";
const url = fn.url || (name && `action:${name}`) || (!isServer ? `action:${fn.name}` : "");
mutate.toString = () => {

@@ -104,3 +95,4 @@ if (!url)

}
function handleResponse(response, navigate) {
async function handleResponse(response, navigate) {
let data;
if (response instanceof Response && redirectStatusCodes.has(response.status)) {

@@ -115,4 +107,7 @@ const locationUrl = response.headers.get("Location") || "/";

}
// return keys
return;
else
data = response;
// TODO: handle keys
await revalidate();
return data;
}

@@ -55,3 +55,3 @@ import { createSignal, getOwner, onCleanup, sharedConfig, startTransition } from "solid-js";

"then" in cached[1]
? cached[1].then(handleResponse)
? cached[1].then(handleResponse, handleResponse)
: handleResponse(cached[1]);

@@ -75,3 +75,3 @@ cached[2] = intent;

"then" in res
? res.then(handleResponse)
? res.then(handleResponse, handleResponse)
: handleResponse(res);

@@ -91,21 +91,21 @@ }

return res;
function handleRedirect(response) {
startTransition(() => {
let url = response.headers.get(LocationHeader);
if (url && url.startsWith("/")) {
navigate(url, {
replace: true
function handleResponse(v) {
if (v instanceof Response && redirectStatusCodes.has(v.status)) {
if (navigate) {
startTransition(() => {
let url = v.headers.get(LocationHeader);
if (url && url.startsWith("/")) {
navigate(url, {
replace: true
});
}
else if (!isServer && url) {
window.location.href = url;
}
});
}
else if (!isServer && url) {
window.location.href = url;
}
});
}
function handleResponse(v) {
if (v instanceof Response && redirectStatusCodes.has(v.status)) {
if (navigate)
isServer ? handleRedirect(v) : setTimeout(() => handleRedirect(v), 0);
return;
}
if (v instanceof Error)
throw v;
if (isServer)

@@ -112,0 +112,0 @@ return v;

@@ -5,2 +5,11 @@ /**

import { type Accessor } from "solid-js";
export declare function createAsync<T>(fn: () => Promise<T>): Accessor<T | undefined>;
export declare function createAsync<T>(fn: () => Promise<T>, options: {
name?: string;
initialValue: T;
deferStream?: boolean;
}): Accessor<T>;
export declare function createAsync<T>(fn: () => Promise<T>, options?: {
name?: string;
initialValue?: T;
deferStream?: boolean;
}): Accessor<T | undefined>;

@@ -6,4 +6,4 @@ /**

import { isServer } from "solid-js/web";
export function createAsync(fn) {
const [resource] = createResource(() => subFetch(fn), v => v);
export function createAsync(fn, options) {
const [resource] = createResource(() => subFetch(fn), v => v, options);
return () => resource();

@@ -10,0 +10,0 @@ }

export { createAsync } from "./createAsync";
export { action, useSubmission, useSubmissions } from "./action";
export { cache, revalidate } from "./cache";
export { redirect } from "./response";
export { createAsync } from "./createAsync";
export { action, useSubmission, useSubmissions } from "./action";
export { cache, revalidate } from "./cache";
export { redirect } from "./response";
import { isServer, delegateEvents, getRequestEvent, createComponent as createComponent$1, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
import { createSignal, onCleanup, getOwner, runWithOwner, createMemo, createContext, useContext, untrack, createRenderEffect, on, startTransition, createComponent, resetErrorBoundaries, children, createRoot, Show, mergeProps, splitProps, createResource, sharedConfig, $TRACK } from 'solid-js';
import { createSignal, onCleanup, getOwner, runWithOwner, createMemo, createContext, useContext, untrack, createRenderEffect, on, startTransition, resetErrorBoundaries, createComponent, children, createRoot, Show, mergeProps, splitProps, createResource, sharedConfig, $TRACK } from 'solid-js';
import { createStore, reconcile } from 'solid-js/store';

@@ -573,2 +573,12 @@

};
const router = {
base: baseRoute,
location,
isRouting,
renderPath,
parsePath,
navigatorFactory,
beforeLeave,
submissions: createSignal(submissions)
};
function navigateFromRoute(route, to, options) {

@@ -606,3 +616,8 @@ // Untrack in case someone navigates in an effect - don't want to track `reference` or route paths

const e = getRequestEvent();
e && (e.response = Response.redirect(resolvedTo, 302));
e && (e.response = new Response(null, {
status: 302,
headers: {
Location: resolvedTo
}
}));
setSource({

@@ -763,3 +778,3 @@ value: resolvedTo,

const data = new FormData(evt.target);
actions.get(actionRef.slice(7))(data);
actions.get(actionRef).call(router, data);
evt.preventDefault();

@@ -800,12 +815,3 @@ }

}
return {
base: baseRoute,
location,
isRouting,
renderPath,
parsePath,
navigatorFactory,
beforeLeave,
submissions: createSignal(submissions)
};
return router;
}

@@ -857,3 +863,3 @@ function createRouteContext(router, parent, outlet, match, params) {

const integration = source || (isServer ? staticIntegration({
value: url || (e = getRequestEvent()) && e.request.url || ""
value: url || (e = getRequestEvent()) && getPath(e.request.url) || ""
}) : pathIntegration());

@@ -878,2 +884,6 @@ const routeDefs = children(() => props.children);

};
function getPath(url) {
const u = new URL(url);
return u.pathname + u.search;
}
function Routes(props) {

@@ -1015,4 +1025,4 @@ const matches = createMemo(() => getRouteMatches(props.branches, props.routerState.location.pathname));

*/
function createAsync(fn) {
const [resource] = createResource(() => subFetch(fn), v => v);
function createAsync(fn, options) {
const [resource] = createResource(() => subFetch(fn), v => v, options);
return () => resource();

@@ -1112,3 +1122,3 @@ }

cached[0] = now;
cached[1] = "then" in cached[1] ? cached[1].then(handleResponse) : handleResponse(cached[1]);
cached[1] = "then" in cached[1] ? cached[1].then(handleResponse, handleResponse) : handleResponse(cached[1]);
cached[2] = intent;

@@ -1130,3 +1140,3 @@ }

if (intent !== "preload") {
res = "then" in res ? res.then(handleResponse) : handleResponse(res);
res = "then" in res ? res.then(handleResponse, handleResponse) : handleResponse(res);
}

@@ -1143,19 +1153,19 @@ if (cached) {

return res;
function handleRedirect(response) {
startTransition(() => {
let url = response.headers.get(LocationHeader);
if (url && url.startsWith("/")) {
navigate(url, {
replace: true
function handleResponse(v) {
if (v instanceof Response && redirectStatusCodes.has(v.status)) {
if (navigate) {
startTransition(() => {
let url = v.headers.get(LocationHeader);
if (url && url.startsWith("/")) {
navigate(url, {
replace: true
});
} else if (!isServer && url) {
window.location.href = url;
}
});
} else if (!isServer && url) {
window.location.href = url;
}
});
}
function handleResponse(v) {
if (v instanceof Response && redirectStatusCodes.has(v.status)) {
if (navigate) isServer ? handleRedirect(v) : setTimeout(() => handleRedirect(v), 0);
return;
}
if (v instanceof Error) throw v;
if (isServer) return v;

@@ -1208,2 +1218,9 @@ setStore(key, reconcile(v, options));

const router = this;
async function handler(res) {
const data = await handleResponse(res, router.navigatorFactory());
data ? setResult({
data
}) : submission.clear();
return data;
}
router.submissions[1](s => [...s, submission = {

@@ -1224,32 +1241,10 @@ input: variables,

const p = fn(variables);
p.then(async data => {
const keys = handleResponse(data, router.navigatorFactory());
await revalidate(keys);
data ? setResult({
data
}) : submission.clear();
return data;
}).catch(error => {
setResult({
data: error
});
});
p.then(handler, handler);
return p;
}
}]);
p.then(async data => {
const keys = handleResponse(data, router.navigatorFactory());
await revalidate(keys);
data ? setResult({
data
}) : submission.clear();
return data;
}).catch(error => {
setResult({
data: error
});
});
p.then(handler, handler);
return p;
}
const url = fn.url || `action:${name}` || !isServer ? `action:${fn.name}` : "";
const url = fn.url || name && `action:${name}` || (!isServer ? `action:${fn.name}` : "");
mutate.toString = () => {

@@ -1262,3 +1257,4 @@ if (!url) throw new Error("Client Actions need explicit names if server rendered");

}
function handleResponse(response, navigate) {
async function handleResponse(response, navigate) {
let data;
if (response instanceof Response && redirectStatusCodes.has(response.status)) {

@@ -1271,7 +1267,26 @@ const locationUrl = response.headers.get("Location") || "/";

}
} else data = response;
// TODO: handle keys
await revalidate();
return data;
}
function redirect(url, init = 302) {
let responseInit = init;
if (typeof responseInit === "number") {
responseInit = {
status: responseInit
};
} else if (typeof responseInit.status === "undefined") {
responseInit.status = 302;
}
// return keys
return;
const headers = new Headers(responseInit.headers);
headers.set("Location", url);
const response = new Response(null, {
...responseInit,
headers: headers
});
return response;
}
export { A, A as Link, A as NavLink, Navigate, Route, Router, mergeSearchString as _mergeSearchString, action, cache, createAsync, createBeforeLeave, createIntegration, createMemoryHistory, hashIntegration, memoryIntegration, normalizeIntegration, pathIntegration, revalidate, staticIntegration, useBeforeLeave, useHref, useIsRouting, useLocation, useMatch, useNavigate, useParams, useResolvedPath, useSearchParams, useSubmission, useSubmissions };
export { A, A as Link, A as NavLink, Navigate, Route, Router, mergeSearchString as _mergeSearchString, action, cache, createAsync, createBeforeLeave, createIntegration, createMemoryHistory, hashIntegration, memoryIntegration, normalizeIntegration, pathIntegration, redirect, revalidate, staticIntegration, useBeforeLeave, useHref, useIsRouting, useLocation, useMatch, useNavigate, useParams, useResolvedPath, useSearchParams, useSubmission, useSubmissions };

@@ -220,2 +220,12 @@ import { createComponent, createContext, createMemo, createRenderEffect, createSignal, on, onCleanup, untrack, useContext, startTransition, resetErrorBoundaries } from "solid-js";

};
const router = {
base: baseRoute,
location,
isRouting,
renderPath,
parsePath,
navigatorFactory,
beforeLeave,
submissions: createSignal(submissions)
};
function navigateFromRoute(route, to, options) {

@@ -253,3 +263,4 @@ // Untrack in case someone navigates in an effect - don't want to track `reference` or route paths

const e = getRequestEvent();
e && (e.response = Response.redirect(resolvedTo, 302));
e &&
(e.response = new Response(null, { status: 302, headers: { Location: resolvedTo } }));
setSource({ value: resolvedTo, replace, scroll, state: nextState });

@@ -418,3 +429,3 @@ }

const data = new FormData(evt.target);
actions.get(actionRef.slice(7))(data);
actions.get(actionRef).call(router, data);
evt.preventDefault();

@@ -457,12 +468,3 @@ }

}
return {
base: baseRoute,
location,
isRouting,
renderPath,
parsePath,
navigatorFactory,
beforeLeave,
submissions: createSignal(submissions)
};
return router;
}

@@ -469,0 +471,0 @@ export function createRouteContext(router, parent, outlet, match, params) {

@@ -9,3 +9,3 @@ {

"license": "MIT",
"version": "0.10.0-beta.1",
"version": "0.10.0-beta.2",
"homepage": "https://github.com/solidjs/solid-router#readme",

@@ -12,0 +12,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc