Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/core/props/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ Error.stackTraceLimit = 9999;
const Q_IS_HYDRATED = '__isHydrated__';
export const Q_CTX = '__ctx__';

export function hydrateIfNeeded(element: Element): void {
const doc = getDocument(element);
export function hydrateIfNeeded(doc: Document): void {
const isHydrated = (doc as any)[Q_IS_HYDRATED];
if (!isHydrated) {
(doc as any)[Q_IS_HYDRATED] = true;
Expand All @@ -36,8 +35,6 @@ export interface QContext {
}

export function getContext(element: Element): QContext {
hydrateIfNeeded(element);

let ctx: QContext = (element as any)[Q_CTX];
if (!ctx) {
const cache = new Map();
Expand Down
5 changes: 3 additions & 2 deletions src/core/render/notify-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assertDefined } from '../assert/assert';
import { QHostAttr } from '../util/markers';
import { getQComponent } from '../component/component-ctx';
import { executeContextWithSlots, printRenderStats, RenderContext } from './cursor';
import { getContext } from '../props/props';
import { getContext, hydrateIfNeeded } from '../props/props';
import { qDev } from '../util/qdev';
import { getPlatform } from '../index';
import { getDocument } from '../util/dom';
Expand All @@ -25,8 +25,9 @@ import { getDocument } from '../util/dom';
// TODO(misko): this should take QComponent as well.
export function notifyRender(hostElement: Element): Promise<RenderContext> {
assertDefined(hostElement.getAttribute(QHostAttr));
const ctx = getContext(hostElement);
const doc = getDocument(hostElement);
hydrateIfNeeded(doc);
const ctx = getContext(hostElement);
const state = getRenderingState(doc);
if (ctx.dirty) {
// TODO
Expand Down
2 changes: 2 additions & 0 deletions src/core/render/render.public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { then } from '../util/promises';
import { getRenderingState } from './notify-render';
import { getDocument } from '../util/dom';
import { qDev } from '../util/qdev';
import { hydrateIfNeeded } from '../props/props';

/**
* Render JSX.
Expand All @@ -31,6 +32,7 @@ export function render(
}
const doc = isDocument(parent) ? parent : getDocument(parent);
const stylesParent = isDocument(parent) ? parent.head : parent.parentElement;
hydrateIfNeeded(doc);

const ctx: RenderContext = {
operations: [],
Expand Down
5 changes: 4 additions & 1 deletion src/core/use/use-lexical-scope.public.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { assertDefined } from '../assert/assert';
import { parseQRL } from '../import/qrl';
import { qInflate } from '../json/q-json';
import { getContext } from '../props/props';
import { getContext, hydrateIfNeeded } from '../props/props';
import { getDocument } from '../util/dom';
import { getInvokeContext } from './use-core';
import { useURL } from './use-url.public';

Expand All @@ -21,9 +22,11 @@ import { useURL } from './use-url.public';
// </docs>
export function useLexicalScope<VARS extends any[]>(): VARS {
const context = getInvokeContext();

const qrl = context.qrl ?? parseQRL(decodeURIComponent(String(useURL())));
if (qrl.captureRef == null) {
const el = context.element;
hydrateIfNeeded(getDocument(el));
const ctx = getContext(el);
assertDefined(qrl.capture);
qrl.captureRef = qrl.capture!.map((idx) => qInflate(idx, ctx));
Expand Down
25 changes: 23 additions & 2 deletions src/optimizer/src/rollup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '..';

import type { NormalizedOutputOptions, PluginContext, RollupError } from 'rollup';
import type { HmrContext, Plugin, ViteDevServer } from 'vite';
import type { HmrContext, Plugin, UserConfig, ViteDevServer } from 'vite';

const QWIK_BUILD = '@builder.io/qwik/build';
/**
Expand Down Expand Up @@ -167,14 +167,22 @@ export function qwikRollup(opts: QwikPluginOptions): any {
name: 'qwik',
enforce: 'pre',
log,
config(config, { command }) {
async config(config, { command }) {
if (!optimizer) {
optimizer = await createOptimizer();
}
if (command === 'serve') {
isBuild = false;
entryStrategy = { type: 'hook' };
if ((config as any).ssr) {
(config as any).ssr.noExternal = false;
}
}
if (command === 'build') {
// Removed if fixed: https://github.com/vitejs/vite/pull/7275
fixSSRInput(config, optimizer);
}

log(`vite command`, command);

return {
Expand Down Expand Up @@ -482,6 +490,19 @@ export const isBrowser = ${!isSSR};
`;
}

function slash(p: string): string {
return p.replace(/\\/g, '/');
}

function fixSSRInput(config: UserConfig, optimizer: Optimizer) {
if (typeof config?.build?.ssr === 'string' && config?.build.rollupOptions?.input) {
const resolvedRoot = optimizer.path.normalize(
slash(config.root ? optimizer.path.resolve(config.root) : process.cwd())
);
config.build.rollupOptions.input = optimizer.path.resolve(resolvedRoot, config.build.ssr);
}
}

/**
* @alpha
*/
Expand Down
1 change: 1 addition & 0 deletions starters/apps/base/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig(({ mode }) => {
return {
build: {
rollupOptions: {
input: ['src/main.tsx', 'index.html'],
output: {
chunkFileNames: 'q-[hash].js',
assetFileNames: 'q-[hash].[ext]',
Expand Down
1 change: 1 addition & 0 deletions starters/servers/express/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig(({ mode }) => {
return {
build: {
rollupOptions: {
input: ['src/main.tsx', 'index.html'],
output: {
// Qwik tends to generate long chunk names
chunkFileNames: 'q-[hash].js',
Expand Down