Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docs site deploy #5930

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/docs/src/repl/bundled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qJsxDts from '../../node_modules/@builder.io/qwik/dist/jsx-runtime.d.ts?r
import qOptimizerCjs from '../../node_modules/@builder.io/qwik/dist/optimizer.cjs?raw';
import qServerCjs from '../../node_modules/@builder.io/qwik/dist/server.cjs?raw';
import qServerDts from '../../node_modules/@builder.io/qwik/dist/server.d.ts?raw';
import { isServer } from '@builder.io/qwik/build';

export const QWIK_PKG_NAME = '@builder.io/qwik';
const ROLLUP_VERSION = '2.75.6';
Expand Down Expand Up @@ -43,11 +44,14 @@ export const getNpmCdnUrl = (

// https://github.com/vitejs/vite/issues/15753
const blobUrl = (code: string) => {
if (isServer) {
return '';
}
const blob = new Blob([code], { type: 'application/javascript' });
return URL.createObjectURL(blob);
};

export const bundled: PkgUrls = {
const bundled: PkgUrls = {
[QWIK_PKG_NAME]: {
version: qwikVersion,
'/build/index.d.ts': blobUrl(qBuild),
Expand Down Expand Up @@ -80,3 +84,10 @@ export const bundled: PkgUrls = {
'/dist/bundle.min.js': blobUrl(terserJs),
},
};

export const getBundled = () =>
isServer
? {
[QWIK_PKG_NAME]: { version: qwikVersion },
}
: bundled;
7 changes: 6 additions & 1 deletion packages/docs/src/repl/monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type MonacoTypes from 'monaco-editor';
import type { EditorProps, EditorStore } from './editor';
import type { ReplStore } from './types';
import { getColorPreference } from '../components/theme-toggle/theme-toggle';
import { bundled, getNpmCdnUrl } from './bundled';
import { getBundled, getNpmCdnUrl } from './bundled';
import { isServer } from '@builder.io/qwik/build';

export const initMonacoEditor = async (
containerElm: any,
Expand Down Expand Up @@ -273,6 +274,7 @@ const loadDeps = async (qwikVersion: string) => {
return monacoCtx.deps;
};

const bundled = getBundled();
const fetchDep = async (cache: Cache, dep: NodeModuleDep) => {
const url = getNpmCdnUrl(bundled, dep.pkgName, dep.pkgVersion, dep.pkgPath);
const req = new Request(url);
Expand All @@ -292,6 +294,9 @@ const fetchDep = async (cache: Cache, dep: NodeModuleDep) => {
};

const getMonaco = async (): Promise<Monaco> => {
if (isServer) {
throw new Error('Monaco cannot be used on the server');
}
if (!monacoCtx.loader) {
// lazy-load the monaco AMD script ol' school
monacoCtx.loader = new Promise<Monaco>((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/repl/repl-detail-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bundled } from './bundled';
import { QWIK_PKG_NAME, getBundled } from './bundled';
import { ReplConsole } from './repl-console';
import { ReplOptions } from './repl-options';
import { ReplTabButton } from './repl-tab-button';
Expand Down Expand Up @@ -31,7 +31,7 @@ export const ReplDetailPanel = ({ input, store }: ReplDetailPanelProps) => {
<ReplOptions
input={input}
versions={store.versions}
qwikVersion={bundled['@builder.io/qwik'].version}
qwikVersion={getBundled()[QWIK_PKG_NAME].version}
/>
) : null}
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/repl/repl-version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { bundled } from './bundled';
import { QWIK_PKG_NAME, getBundled } from './bundled';

const bundledVersion = bundled['@builder.io/qwik'].version;
const bundledVersion = getBundled()[QWIK_PKG_NAME].version;

// The golden oldies
const keepList = new Set('1.0.0,1.1.5,1.2.13'.split(','));
Expand Down
13 changes: 12 additions & 1 deletion packages/docs/src/repl/repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import type { ReplStore, ReplUpdateMessage, ReplMessage, ReplAppInput } from './
import { ReplDetailPanel } from './repl-detail-panel';
import { getReplVersion } from './repl-version';
import { updateReplOutput } from './repl-output-update';
import { QWIK_PKG_NAME, bundled, getNpmCdnUrl } from './bundled';
import { QWIK_PKG_NAME, getBundled, getNpmCdnUrl } from './bundled';
import { isServer } from '@builder.io/qwik/build';

export const Repl = component$((props: ReplProps) => {
useStyles$(styles);
Expand Down Expand Up @@ -79,6 +80,9 @@ export const Repl = component$((props: ReplProps) => {

useVisibleTask$(
async () => {
if (isServer) {
return;
}
// only run on the client
// Get the version asap, most likely it will be cached.
const v = await getReplVersion(input.version, true);
Expand Down Expand Up @@ -132,6 +136,9 @@ export const receiveMessageFromReplServer = (
store: ReplStore,
input: ReplAppInput
) => {
if (isServer) {
return;
}
if (ev.origin !== window.origin) {
return;
}
Expand All @@ -158,6 +165,7 @@ export const receiveMessageFromReplServer = (
}
};

const bundled = getBundled();
const getDependencies = (input: ReplAppInput) => {
const out = { ...bundled };
if (input.version !== 'bundled') {
Expand All @@ -175,6 +183,9 @@ const getDependencies = (input: ReplAppInput) => {
};

export const sendUserUpdateToReplServer = (input: ReplAppInput, store: ReplStore) => {
if (isServer) {
return;
}
if (input.version && store.serverWindow) {
const msg: ReplUpdateMessage = {
type: 'update',
Expand Down
11 changes: 10 additions & 1 deletion packages/qwik/src/core/component/component.unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createDOM } from '../../testing/library';
import { expectDOM } from '../../testing/expect-dom';
import { inlinedQrl } from '../qrl/qrl';
import { useStylesQrl } from '../use/use-styles';
import { type PropsOf, component$ } from './component.public';
import { type PropsOf, component$, type Component } from './component.public';
import { useStore } from '../use/use-store.public';
import { useLexicalScope } from '../use/use-lexical-scope.public';
import { describe, test, expectTypeOf } from 'vitest';
Expand Down Expand Up @@ -221,6 +221,15 @@ describe('q-component', () => {
expectTypeOf<TestProps['test$']>().toMatchTypeOf<Parameters<typeof Test1>[0]['test$']>();
expectTypeOf<QRL<() => void>>().toMatchTypeOf<Parameters<typeof Test1>[0]['test$']>();
});

test('Inline Components should be able to use Component', () => () => {
const InlineComponent: Component<PropsOf<'div'>> = (props) => {
expectTypeOf(props).not.toBeAny();
return <div {...props} />;
};
// Passing a plain function should not error
return <InlineComponent onClick$={() => {}} />;
});
});

/////////////////////////////////////////////////////////////////////////////
Expand Down