Skip to content

feat: add has function to createContext#18472

Open
soleuniverse101 wants to merge 5 commits into
sveltejs:mainfrom
soleuniverse101:main
Open

feat: add has function to createContext#18472
soleuniverse101 wants to merge 5 commits into
sveltejs:mainfrom
soleuniverse101:main

Conversation

@soleuniverse101

@soleuniverse101 soleuniverse101 commented Jun 27, 2026

Copy link
Copy Markdown

This is about #18471.

I hope it's okay, I went ahead and implemented this before having an answer on the issue about if this is okay as a feature. If it's not, I understand if this PR has to be closed, it was pretty quick to do.

If this PR is accepted, I have a few comments :

  • First of all, feel free to argue this but I don't think introducing this additional function is a breaking change since all previous uses of createContext should still work by disregarding the third function of the now triplet returned.
  • I replaced every [get, set] pair by a [get, set, has] triplet to reflect the new API so that people can notice the existence of the new has function. I was wondering if this was too much noise since people should probably mainly use get/set, while the use of has would be more rare.
  • I slightly altered the Context docs page to reflect the new signature, but I didn't include any example since it shouldn't be needed often.
  • To test this, I altered the runtime-runes/samples/create-context and runtime-runes/samples/create-context-programmatic tests. Is this okay or should I add new separate tests ?
  • Finally, I noticed that the documentation of createContext mentions since 5.40.0. I'm not sure if I should update that or not, given that while the function was introducted at that version, this new signature would be more recent. How should I proceed ?

PS : sorry for the length of this body

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6d5508d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant