Skip to content

Commit 1ef59e9

Browse files
committed
chore: remove unnecessary logic as it is moved to the async computed signal fn
1 parent ece6a14 commit 1ef59e9

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

packages/qwik-router/src/runtime/src/server-functions.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
$,
33
implicit$FirstArg,
4-
isBrowser,
54
isDev,
65
isServer,
76
noSerialize,
@@ -24,7 +23,7 @@ import * as v from 'valibot';
2423
import { z } from 'zod';
2524
import type { RequestEventLoader } from '../../middleware/request-handler/types';
2625
import { QACTION_KEY, QDATA_KEY, QFN_KEY } from './constants';
27-
import { RouteLocationContext, RouteStateContext } from './contexts';
26+
import { RouteStateContext } from './contexts';
2827
import type {
2928
ActionConstructor,
3029
ActionConstructorQRL,
@@ -59,7 +58,6 @@ import type {
5958
import { useAction, useLocation, useQwikRouterEnv } from './use-functions';
6059

6160
import type { FormSubmitCompletedDetail } from './form-component';
62-
import { loadClientData } from './use-endpoint';
6361
import { deepFreeze } from './utils';
6462

6563
/** @internal */
@@ -200,7 +198,6 @@ export const routeLoaderQrl = ((
200198
function loader() {
201199
const iCtx = _useInvokeContext();
202200
const state = iCtx.$container$.resolveContext(iCtx.$hostElement$, RouteStateContext)!;
203-
const location = iCtx.$container$.resolveContext(iCtx.$hostElement$, RouteLocationContext)!;
204201

205202
if (!(id in state)) {
206203
throw new Error(`routeLoader$ "${loaderQrl.getSymbol()}" was invoked in a route where it was not declared.
@@ -210,16 +207,14 @@ export const routeLoaderQrl = ((
210207
If your are managing reusable logic or a library it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception.
211208
For more information check: https://qwik.dev/docs/re-exporting-loaders/`);
212209
}
213-
const loaderData = untrack(() => state[id].value);
214-
if (isBrowser && loaderData === _UNINITIALIZED) {
215-
// Request the loader data from the server and throw the Promise
216-
// so the client can load it synchronously.
217-
throw loadClientData(location.url, iCtx.$hostElement$, {
218-
loaderIds: [id],
219-
}).then((clientData) => {
220-
state[id].value = clientData?.loaders[id];
221-
});
222-
}
210+
// Force the signal to be initialized.
211+
// It is an async computed signal.
212+
// We have two options:
213+
// - we already have data from signal or from previous fetch
214+
// - we don't have data yet, so we need to fetch it from the server
215+
// Calling it will trigger fetch the data from the server.
216+
// Under the hood, it will throw a promise and await for it, so the client will load the data synchronously.
217+
untrack(() => state[id].value);
223218
return state[id];
224219
}
225220
loader.__brand = 'server_loader' as const;

0 commit comments

Comments
 (0)