Skip to content

Commit

Permalink
fix(qrl.ts): dedupe sync$ (#5566)
Browse files Browse the repository at this point in the history
* fix(qrl.ts): dedupe sync$

* refactor(core): sync$ inlineFns key
  • Loading branch information
PatrickJS authored and mhevery committed Dec 15, 2023
1 parent ea0116a commit db13233
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/qwik/src/core/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface ContainerState {
$styleMoved$: boolean;
readonly $styleIds$: Set<string>;
readonly $events$: Set<string>;
readonly $inlineFns$: Map<Function, number>;
readonly $inlineFns$: Map<string, number>;
}

const CONTAINER_STATE = Symbol('ContainerState');
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik/src/core/container/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ const collectProps = (elCtx: QContext, collector: Collector) => {

const createCollector = (containerState: ContainerState): Collector => {
const inlinedFunctions: string[] = [];
containerState.$inlineFns$.forEach((id, fn) => {
containerState.$inlineFns$.forEach((id, fnStr) => {
while (inlinedFunctions.length <= id) {
inlinedFunctions.push('');
}
inlinedFunctions[id] = fn.toString();
inlinedFunctions[id] = fnStr;
});
return {
$containerState$: containerState,
Expand Down
7 changes: 4 additions & 3 deletions packages/qwik/src/core/qrl/qrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,13 @@ export const serializeQRL = (qrl: QRLInternal, opts: QRLSerializeOptions = {}) =
}
if (isSyncQrl(qrl)) {
if (opts.$containerState$) {
const fn = qrl.resolved;
const fn = qrl.resolved as Function;
const containerState = opts.$containerState$;
let id = containerState.$inlineFns$.get(fn as any);
const fnStrKey = fn.toString();
let id = containerState.$inlineFns$.get(fnStrKey);
if (id === undefined) {
id = containerState.$inlineFns$.size;
containerState.$inlineFns$.set(fn as any, id);
containerState.$inlineFns$.set(fnStrKey, id);
}
symbol = String(id);
} else {
Expand Down

0 comments on commit db13233

Please sign in to comment.