Skip to content

Commit

Permalink
fix: islands runtime error
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Oct 5, 2022
1 parent 517002d commit 785f6bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/node/build.ts
Expand Up @@ -155,7 +155,7 @@ class SSGBuilder {
return this.#baseBuild(false, {
build: {
minify: !process.env.NO_MINIFY,
outDir: TEMP_PATH,
outDir: join(this.#root, TEMP_PATH),
ssrManifest: false,
rollupOptions: {
external: DEFAULT_EXTERNALS,
Expand Down Expand Up @@ -215,7 +215,7 @@ class SSGBuilder {
this.#config.enableSpa!
);
const hasIsland = Object.keys(islandToPathMap).length > 0;
let injectIslandsCode = '';
let injectIslandsPath = '';
// In island mode, we will bundle and inject island components code to html
if (hasIsland && !this.#config.enableSpa) {
const islandHash = createHash(JSON.stringify(islandToPathMap));
Expand All @@ -225,11 +225,16 @@ class SSGBuilder {
const rawInjectCode = this.#generateIslandInjectCode(islandToPathMap);
injectBundlePromise = (async () => {
const injectBundle = await this.islandsBuild(rawInjectCode);
return injectBundle.output[0].code;
// Get complete css from server bundle
await copy(
join(this.#root, TEMP_PATH, 'assets'),
join(this.#root, DIST_PATH, 'assets')
);
return injectBundle.output[0].fileName;
})();
this.#islandsInjectCache.set(islandHash, injectBundlePromise);
}
injectIslandsCode = await injectBundlePromise;
injectIslandsPath = await injectBundlePromise;
}
const { helmet } = helmetContext.context!;

Expand Down Expand Up @@ -286,7 +291,7 @@ class SSGBuilder {
!this.#config.enableSpa && hasIsland
? `<script id="island-props">${JSON.stringify(
propsData
)}</script><script type="module">${injectIslandsCode}</script>`
)}</script><script type="module" src="/${injectIslandsPath}"></script>`
: ''
}
${
Expand Down Expand Up @@ -354,7 +359,7 @@ class SSGBuilder {
noExternal: ['lodash-es', 'react-router-dom']
},
build: {
minify: !process.env.NO_MINIFY,
minify: !process.env.NO_MINIFY && !isServer,
ssr: isServer,
outDir: isServer
? join(this.#root, TEMP_PATH, 'ssr')
Expand Down
2 changes: 1 addition & 1 deletion src/theme-default/components/Nav/index.tsx
Expand Up @@ -180,7 +180,7 @@ export function Nav() {
items-center=""
>
<div className="search" flex="sm:1" pl="sm:8">
<Search />
<Search __island />
</div>
<NavMenu menuItems={menuItems} />
{hasMultiLanguage && (
Expand Down
3 changes: 2 additions & 1 deletion src/theme-default/components/Search/index.tsx
@@ -1,6 +1,7 @@
import { ChangeEvent, useCallback, useEffect, useRef, useState } from 'react';
import { MatchResultItem, PageSearcher } from '../../logic/search';
import SearchSvg from './icons/search.svg';
import { ComponentPropsWithIsland } from '../../../shared/types/index';

function SuggestionContent(props: {
suggestion: MatchResultItem;
Expand Down Expand Up @@ -61,7 +62,7 @@ function SuggestionContent(props: {
);
}

export function Search() {
export function Search(_props: ComponentPropsWithIsland) {
const [suggestions, setSuggestions] = useState<MatchResultItem[]>([]);
const [query, setQuery] = useState('');
const [focused, setFocused] = useState(false);
Expand Down

0 comments on commit 785f6bd

Please sign in to comment.