Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 23, 2024
1 parent ea46d47 commit c22ec87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/qwik/src/core/v2/tests/container.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ describe('serializer v2', () => {
expect(qrl1._devOnlySymbolRef).toEqual((obj[1] as any)._devOnlySymbolRef);
expect(qrl2.$hash$).toEqual(obj[2].$hash$);
expect(qrl2.$captureRef$).toEqual(obj[2].$captureRef$);
expect(qrl2._devOnlySymbolRef).toEqual((obj[2] as any)._devOnlySymbolRef);
expect(qrl2._devOnlySymbolRef.toString()).toEqual(
(obj[2] as any)._devOnlySymbolRef.toString()
);
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/v2/tests/render-api.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ describe('render api', () => {
const document = createDocument(result.html);
const qwikFuncScriptElements = document.querySelectorAll('script[q\\:func=qwik/json]');
expect(qwikFuncScriptElements).toHaveLength(1);
expect(qwikFuncScriptElements[0].textContent).toEqual(
'document.currentScript.closest("[q\\\\:container]").qFuncs=[(p0)=>p0.value]'
expect(qwikFuncScriptElements[0].textContent).toMatch(
/document\["qFuncs_(\w{11})"\]=\[\(p0\)=>p0\.value\]/
);
});
});
Expand Down
17 changes: 11 additions & 6 deletions packages/qwik/src/server/v2-ssr-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
vNodeData_openFragment,
type VNodeData,
} from './v2-vnode-data';
import { QInstance } from '../core/util/markers';

export function ssrCreateContainer(
opts: {
Expand Down Expand Up @@ -204,6 +205,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
private unclaimedProjections: Array<ISsrComponentFrame | string | JSXChildren> = [];
unclaimedProjectionComponentFrameQueue: Array<ISsrComponentFrame> = [];
private cleanupQueue: CleanupQueue = [];
private instanceHash = hash();

constructor(opts: Required<Required<Parameters<typeof ssrCreateContainer>>[0]>) {
super(
Expand Down Expand Up @@ -296,19 +298,18 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
if (this.tag == 'html') {
this.write('<!DOCTYPE html>');
}
let qRender = isDev ? 'ssr-dev' : 'ssr';
if (this.renderOptions.containerAttributes?.[QRenderAttr]) {
qRender = `${this.renderOptions.containerAttributes[QRenderAttr]}-${qRender}`;
}

const qRender = this.renderOptions.containerAttributes?.[QRenderAttr];
const containerAttributes: Record<string, string> = {
...this.renderOptions.containerAttributes,
[QRuntimeAttr]: '2',
[QContainerAttr]: QContainerValue.PAUSED,
[QVersionAttr]: this.$version$ ?? 'dev',
[QRenderAttr]: qRender,
[QRenderAttr]: (qRender ? qRender + '-' : '') + (isDev ? 'ssr-dev' : 'ssr'),
[QBaseAttr]: this.buildBase,
[QLocaleAttr]: this.$locale$,
[QManifestHashAttr]: this.resolvedManifest.manifest.manifestHash,
[QInstance]: this.instanceHash,
};

const containerAttributeArray = Object.entries(containerAttributes).reduce<string[]>(
Expand Down Expand Up @@ -757,7 +758,7 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
scriptAttrs.push('nonce', this.renderOptions.serverData.nonce);
}
this.openElement('script', scriptAttrs);
this.write(Q_FUNCS_PREFIX);
this.write(Q_FUNCS_PREFIX.replace('HASH', this.instanceHash));
this.write('[');
this.writeArray(fns, ',');
this.write(']');
Expand Down Expand Up @@ -1133,3 +1134,7 @@ const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/; // eslint-disable-li
function isSSRUnsafeAttr(name: string): boolean {
return unsafeAttrCharRE.test(name);
}

function hash() {
return Math.random().toString(36).slice(2);
}

0 comments on commit c22ec87

Please sign in to comment.