Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
perf: don't recreate non-mutated context
  • Loading branch information
jeswr committed Oct 28, 2023
commit fb15661fce241f636f8c88c1ff6fada907eb2295
8 changes: 3 additions & 5 deletions lib/entryhandler/keyword/EntryHandlerKeywordType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ export class EntryHandlerKeywordType extends EntryHandlerKeyword {
if (hasTypedScopedContext) {
// Do not propagate by default
scopedContext = scopedContext.then((c) => {
let rawContext = c.getContextRaw();

// Set the original context at this depth as a fallback
// This is needed when a context was already defined at the given depth,
// and this context needs to remain accessible from child nodes when propagation is disabled.
if (rawContext['@propagate'] !== true) {
rawContext = { ...rawContext, '@propagate': false, '@__propagateFallback': context.getContextRaw() };
if (c.getContextRaw()['@propagate'] !== true) {
return new JsonLdContextNormalized({ ...c.getContextRaw(), '@propagate': false, '@__propagateFallback': context.getContextRaw() });
}

return new JsonLdContextNormalized(rawContext);
return c;
});

// Set the new context in the context tree
Expand Down