Skip to content

Commit

Permalink
Fix: serverDataLoader is not work when dataLoader is not defined (#6875)
Browse files Browse the repository at this point in the history
* fix: serverDataLoader is not work when dataLoader is not defined

* fix: condition
  • Loading branch information
ClarkXia authored Apr 29, 2024
1 parent 5e3bed3 commit 8fd6343
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @ice/runtime

## 1.4.6

- Fix: serverDataLoader is not work when dataLoader is not defined.

## 1.4.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/runtime",
"version": "1.4.5",
"version": "1.4.6",
"description": "Runtime module for ice.js",
"type": "module",
"types": "./esm/index.d.ts",
Expand Down
7 changes: 4 additions & 3 deletions packages/runtime/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function createRouteLoader(options: RouteLoaderOptions): LoaderFunction {
const { requestContext: defaultRequestContext, renderMode, routeId } = options;
const globalLoader = (typeof window !== 'undefined' && (window as any).__ICE_DATA_LOADER__) ? (window as any).__ICE_DATA_LOADER__ : null;

if (process.env.ICE_CORE_REMOVE_DATA_LOADER !== 'true') {
if (import.meta.renderer !== 'client' || process.env.ICE_CORE_REMOVE_DATA_LOADER !== 'true') {
if (globalLoader) {
dataLoaderConfig = globalLoader.getLoader(routeId);
} else if (renderMode === 'SSG') {
Expand All @@ -184,7 +184,8 @@ export function createRouteLoader(options: RouteLoaderOptions): LoaderFunction {
}

// if ICE_CORE_REMOVE_DATA_LOADER is true, dataLoaderConfig should be null and it already return above.
if (process.env.ICE_CORE_REMOVE_DATA_LOADER !== 'true') {
// dataLoader should be always called in server side because of the serverDataLoader.
if (import.meta.renderer !== 'client' || process.env.ICE_CORE_REMOVE_DATA_LOADER !== 'true') {
let loader: Loader;
let loaderOptions: DataLoaderOptions;

Expand All @@ -198,7 +199,7 @@ export function createRouteLoader(options: RouteLoaderOptions): LoaderFunction {

const getData = (requestContext: RequestContext) => {
let routeData: any;
if (process.env.ICE_CORE_REMOVE_DATA_LOADER !== 'true') {
if (import.meta.renderer !== 'client' || process.env.ICE_CORE_REMOVE_DATA_LOADER !== 'true') {
if (globalLoader) {
routeData = globalLoader.getData(routeId, { renderMode, requestContext });
} else {
Expand Down

0 comments on commit 8fd6343

Please sign in to comment.