Skip to content

Commit

Permalink
use symbol mapper from core
Browse files Browse the repository at this point in the history
  • Loading branch information
thejackshelton committed Jul 4, 2024
1 parent b87a9dd commit aba07d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion apps/node-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@astrojs/node": "^8.2.3",
"@astrojs/react": "^3.0.10",
"@builder.io/qwik": "^1.5.1",
"@builder.io/qwik": "https://pkg.pr.new/@builder.io/qwik@5382c66",
"@qwikdev/astro": "workspace:*",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
Expand Down
4 changes: 2 additions & 2 deletions libs/qwikdev-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
"vite-tsconfig-paths": "^4.2.1"
},
"devDependencies": {
"@builder.io/qwik": "1.5.6",
"@builder.io/qwik": "https://pkg.pr.new/@builder.io/qwik@5382c66",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.10.0",
"astro": "^4.5",
"typescript": "^5.4.2",
"vite": "^5.2.6"
},
"peerDependencies": {
"@builder.io/qwik": "1.5.6",
"@builder.io/qwik": "https://pkg.pr.new/@builder.io/qwik@5382c66",
"typescript": "^5.4.2"
}
}
21 changes: 3 additions & 18 deletions libs/qwikdev-astro/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
PrefetchServiceWorker,
jsx
} from "@builder.io/qwik";
import type { QwikManifest, SymbolMapperFn } from "@builder.io/qwik/optimizer";
import type { QwikManifest } from "@builder.io/qwik/optimizer";
import { symbolMapper } from '@builder.io/qwik/optimizer';

import { isDev } from "@builder.io/qwik/build";
import { getQwikLoaderScript, renderToString } from "@builder.io/qwik/server";
Expand Down Expand Up @@ -94,22 +95,6 @@ export async function renderToStaticMarkup(
children: [qwikScripts, ...(defaultSlot ? [defaultSlot] : []), ...slotValues]
});

/**
For a given symbol (QRL such as `onKeydown$`) the server needs to know which bundle the symbol is in.
Normally this is provided by Qwik's `q-manifest` . But `q-manifest` only exists after a full client build.
This would be a problem in dev mode. So in dev mode the symbol is mapped to the expected URL using the symbolMapper function above. For Vite the given path is fixed for a given symbol.
*/
const symbolMapper: SymbolMapperFn = (symbolName: string) => {
/* don't want to add a file path for sync$ */
if (symbolName === "<sync>") {
return;
}

return [symbolName, `/${process.env.SRC_DIR}/${symbolName.toLocaleLowerCase()}.js`];
};

if (shouldAddQwikLoader) {
qwikLoaderAdded.set(this.result, true);
}
Expand All @@ -124,7 +109,7 @@ export async function renderToStaticMarkup(
containerTagName: "div",
containerAttributes: { style: "display: contents" },
manifest: isDev ? ({} as QwikManifest) : manifest,
...(manifest ? undefined : { symbolMapper }),
...(manifest ? undefined : symbolMapper),
qwikLoader: { include: "never" }
});

Expand Down
15 changes: 8 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aba07d0

Please sign in to comment.