Skip to content

fix: avoid auto-parenthesis for special-keywords-only MediaQuery #15937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2025

Conversation

paoloricciuti
Copy link
Member

Closes #15930

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

Copy link

changeset-bot bot commented May 16, 2025

🦋 Changeset detected

Latest commit: 7eef30e

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

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

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

@paoloricciuti paoloricciuti changed the title fix: avoid auto-parenthesis for special keywords only MediaQuery fix: avoid auto-parenthesis for special-keywords-only MediaQuery May 16, 2025
@svelte-docs-bot
Copy link

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15937

Copy link

@techniq techniq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small typos in the comment

@Rich-Harris
Copy link
Member

This doesn't quite work yet — it fails on things like screen, print because of both the comma and the double space

@paoloricciuti
Copy link
Member Author

I couldn't quite remember the syntax for multiple of those...let me see if i can fix it

@paoloricciuti
Copy link
Member Author

@Rich-Harris I kinda found a good regex for this

.split(/[\s,]+/)

will basically split something, like,this, to to ['something','like','this','to']...however i also need to change the every to some because this can also be a true media query window.matchMedia('somethingrandom,screen')...luckily if there are no parenthesis and you use one of the keyword we should be able to assume you don't want parenthesis since there's no media feature that also include one of the keywords...should work no?

@Rich-Harris Rich-Harris merged commit a2ddca1 into main May 19, 2025
13 checks passed
@Rich-Harris Rich-Harris deleted the media-query-special-keyword branch May 19, 2025 18:25
@github-actions github-actions bot mentioned this pull request May 19, 2025
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.

MediaQuery does not work with screen and print media queries
3 participants