Skip to content

Commit

Permalink
Merge branch 'main' into fix/plugin-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin authored Nov 26, 2024
2 parents a93521d + 192f82e commit b0c2be6
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-trees-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modern-js/app-tools': patch
---

feat(app-tools): update preset type definitions
6 changes: 6 additions & 0 deletions .changeset/wet-trains-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/runtime': patch
---

fix: 只需要在 SSR 模式下才调用 hydrateRoot 函数,修复必定进入 hydrateRoot 函数的问题
fix: only call hydrateRoot in ssr mode, fix bug that always call hydrateRoot
10 changes: 6 additions & 4 deletions packages/runtime/plugin-runtime/src/core/browser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ export async function render(
};

if (isClientArgs(id)) {
// This field may suitable to be called `requestData`,
// because both SSR and CSR can get the context
const ssrData = getSSRData();
const loadersData = ssrData?.data?.loadersData || {};
const loadersData = ssrData.data?.loadersData || {};

const initialLoadersState = Object.keys(loadersData).reduce(
(res: any, key) => {
Expand All @@ -114,10 +116,10 @@ export async function render(
}),
// garfish plugin params
_internalRouterBaseName: App.props.basename,
...(ssrData ? { ssrContext: ssrData?.context } : {}),
...{ ssrContext: ssrData.context },
});

context.initialData = ssrData?.data?.initialData;
context.initialData = ssrData.data?.initialData;
const initialData = await runBeforeRender(context);
if (initialData) {
context.initialData = initialData;
Expand All @@ -141,7 +143,7 @@ export async function render(
}

// we should hydateRoot only when ssr
if (ssrData) {
if (window._SSR_DATA) {
return hydrateRoot(App, context, ModernRender, ModernHydrate);
}
return ModernRender(wrapRuntimeContextProvider(App, context));
Expand Down
143 changes: 82 additions & 61 deletions packages/solutions/app-tools/lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ declare namespace NodeJS {
}
}

// reference @rsbuild/core/types, but there are some differences, such as svg
/**
* Image assets
*/
declare module '*.bmp' {
const src: string;
export default src;
Expand All @@ -36,143 +40,152 @@ declare module '*.png' {
export default src;
}

declare module '*.avif' {
declare module '*.pjpeg' {
const src: string;
export default src;
}

declare module '*.ico' {
declare module '*.pjp' {
const src: string;
export default src;
}

declare module '*.webp' {
declare module '*.apng' {
const src: string;
export default src;
}

declare module '*.svg' {
import * as React from 'react';

export const ReactComponent: React.FunctionComponent<
React.SVGProps<SVGSVGElement>
>;

/**
* The default export type depends on the svgDefaultExport config,
* it can be a string or a ReactComponent
* */
const content: any;
export default content;
declare module '*.tif' {
const src: string;
export default src;
}

declare module '*.svg?react' {
const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
export default ReactComponent;
declare module '*.tiff' {
const src: string;
export default src;
}

declare module '*.bmp?inline' {
declare module '*.jfif' {
const src: string;
export default src;
}

declare module '*.gif?inline' {
declare module '*.avif' {
const src: string;
export default src;
}

declare module '*.jpg?inline' {
declare module '*.ico' {
const src: string;
export default src;
}

declare module '*.jpeg?inline' {
declare module '*.webp' {
const src: string;
export default src;
}

declare module '*.png?inline' {
/**
* Font assets
*/
declare module '*.woff' {
const src: string;
export default src;
}

declare module '*.avif?inline' {
declare module '*.woff2' {
const src: string;
export default src;
}

declare module '*.ico?inline' {
declare module '*.eot' {
const src: string;
export default src;
}

declare module '*.webp?inline' {
declare module '*.ttf' {
const src: string;
export default src;
}

declare module '*.svg?inline' {
import * as React from 'react';

export const ReactComponent: React.FunctionComponent<
React.SVGProps<SVGSVGElement>
>;

declare module '*.otf' {
const src: string;
export default src;
}

declare module '*.bmp?url' {
declare module '*.ttc' {
const src: string;
export default src;
}

declare module '*.gif?url' {
/**
* Media assets
*/
declare module '*.mp4' {
const src: string;
export default src;
}

declare module '*.jpg?url' {
declare module '*.webm' {
const src: string;
export default src;
}

declare module '*.jpeg?url' {
declare module '*.ogg' {
const src: string;
export default src;
}

declare module '*.png?url' {
declare module '*.mp3' {
const src: string;
export default src;
}

declare module '*.avif?url' {
declare module '*.wav' {
const src: string;
export default src;
}

declare module '*.ico?url' {
declare module '*.flac' {
const src: string;
export default src;
}

declare module '*.webp?url' {
declare module '*.aac' {
const src: string;
export default src;
}
declare module '*.mov' {
const src: string;
export default src;
}
declare module '*.m4a' {
const src: string;
export default src;
}
declare module '*.opus' {
const src: string;
export default src;
}

declare module '*.svg?url' {
declare module '*.svg' {
import * as React from 'react';

export const ReactComponent: React.FunctionComponent<
React.SVGProps<SVGSVGElement>
>;

/**
* The default export type depends on the svgDefaultExport config,
* it can be a string or a ReactComponent
* */
const content: any;
export default content;
}

declare module '*.svg?react' {
const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
export default ReactComponent;
}

/**
* Queries
*/
declare module '*?inline' {
const content: string;
export default content;
}

declare module '*?url' {
const src: string;
export default src;
}


declare module '*.css' {
const classes: { readonly [key: string]: string };
export default classes;
Expand All @@ -193,6 +206,9 @@ declare module '*.sass' {
export default classes;
}

/**
* CSS Modules
*/
declare module '*.module.css' {
const classes: { readonly [key: string]: string };
export default classes;
Expand Down Expand Up @@ -224,12 +240,17 @@ declare module '*.hbs' {
}

declare module '*.yaml' {
const src: string;
const src: Record<string, any>;
export default src;
}

declare module '*.yml' {
const content: Record<string, any>;
export default content;
}

declare module '*.toml' {
const src: string;
const src: Record<string, any>;
export default src;
}

Expand Down

0 comments on commit b0c2be6

Please sign in to comment.