From 68ba53d6697ea36a59176ef838c96d1cf903e6b9 Mon Sep 17 00:00:00 2001 From: Mark Stuart <742884+mstuart@users.noreply.github.com> Date: Sat, 29 Aug 2026 13:06:34 +0000 Subject: [PATCH] fix: preserve explicitly scoped undefined values --- index.js | 8 ++++---- readme.md | 2 +- test.js | 8 ++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b697b75..4bef358 100644 --- a/index.js +++ b/index.js @@ -16,8 +16,8 @@ export default function createContext(defaultValue) { @returns {unknown} The current context value. */ get() { - const value = storage.getStore(); - return value === undefined ? defaultValue : value; + const store = storage.getStore(); + return store === undefined ? defaultValue : store.value; }, /** Run a function with the given value in the async context. @@ -27,7 +27,7 @@ export default function createContext(defaultValue) { @returns {unknown} The result of function_. */ run(value, function_) { - return storage.run(value, function_); + return storage.run({ value }, function_); }, /** @@ -37,7 +37,7 @@ export default function createContext(defaultValue) { @returns {(...arguments_: unknown[]) => unknown} A function that takes a function and runs it in the context. */ runWith(value) { - return (function_) => storage.run(value, function_); + return (function_) => storage.run({ value }, function_); }, }; } diff --git a/readme.md b/readme.md index b5689e6..f0d6c52 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ npm Ask DeepWiki Socket - Node 20+ + Node 22+

--- diff --git a/test.js b/test.js index 330e719..5f23dbe 100644 --- a/test.js +++ b/test.js @@ -151,3 +151,11 @@ test("false as context value", (t) => { t.false(context.get()); }); }); + +test("explicit undefined overrides the default value", (t) => { + const context = createContext("default"); + context.run(undefined, () => { + t.is(context.get(), undefined); + }); + t.is(context.get(), "default"); +});