Skip to content

Commit

Permalink
fix: we should export getLoaderCtx from server-core (#6020)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Jul 30, 2024
1 parent 604ad3a commit 203c9eb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-buses-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/server-core': patch
---

fix: we should export `getLoaderCtx` from server-core
fix: 我们应该从 server-core 导出 `getLoaderCtx`
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Context } from '../../types';
import type { Context } from './types';

type LoaderContext = Map<string, unknown>;

Expand All @@ -10,14 +10,16 @@ interface Env {
Variables: Var;
}

const LOADER_CONTEXT = 'loaderContext';

export function getLoaderCtx(c: Context<Env>): LoaderContext {
const loaderContext = c.get('loaderContext');
const loaderContext = c.get(LOADER_CONTEXT);
if (loaderContext) {
return loaderContext;
} else {
const loaderContext = new Map();

c.set('loaderContext', loaderContext);
c.set(LOADER_CONTEXT, loaderContext);
return loaderContext;
}
}
1 change: 1 addition & 0 deletions packages/server/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type {
ServerManifest,
} from './types';

export { getLoaderCtx } from './helper';
export * from './plugins';
export * from './types/plugin';
export * from './types/render';
Expand Down
4 changes: 1 addition & 3 deletions packages/server/core/src/plugins/customServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { time } from '@modern-js/runtime-utils/time';
import { ServerBase } from '../../serverBase';
import { ServerHookRunner, Context, Middleware, ServerEnv } from '../../types';
import { transformResponse } from '../../utils';
import { getLoaderCtx } from '../../helper';
import { ServerTimings } from '../../constants';
import type { ServerNodeEnv } from '../../adapters/node/hono';
import type * as streamModule from '../../adapters/node/polyfills/stream';
import { getLoaderCtx } from './loader';
import {
getAfterMatchCtx,
getAfterRenderCtx,
Expand All @@ -19,8 +19,6 @@ import {
} from './context';
import { ResArgs, createBaseHookContext } from './base';

export { getLoaderCtx } from './loader';

// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};

Expand Down
2 changes: 2 additions & 0 deletions packages/server/core/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export {
} from './render';
export { faviconPlugin } from './favicon';
export { injectServerTiming, injectloggerPluigin } from './monitors';
export { processedByPlugin } from './processedBy';
export { logPlugin } from './log';
export {
createDefaultPlugins,
type CreateDefaultPluginsOptions,
Expand Down
7 changes: 2 additions & 5 deletions packages/server/core/src/plugins/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import {
import { ServerNodeEnv } from '../../adapters/node/hono';
import { initReporter } from '../monitors';
import { sortRoutes } from '../../utils';
import {
getLoaderCtx,
CustomServer,
getServerMidFromUnstableMid,
} from '../customServer';
import { CustomServer, getServerMidFromUnstableMid } from '../customServer';
import { getLoaderCtx } from '../../helper';

export * from './inject';

Expand Down

0 comments on commit 203c9eb

Please sign in to comment.