Skip to content
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

ESLint error message encountered on MetaProperty #136

Open
edmaala opened this issue Sep 14, 2023 · 7 comments
Open

ESLint error message encountered on MetaProperty #136

edmaala opened this issue Sep 14, 2023 · 7 comments

Comments

@edmaala
Copy link

edmaala commented Sep 14, 2023

I'm currently reviewing React Typescript with Vite. My React version is 18.2.0 and ESLint version 8.2.0.

I've been checking on ways to open a link on a new tab with a button. and found the following to be a valid way of nesting elements to do so:

function LinkNewTab() {
  return (
    <a target='_blank' rel='noreferrer' href={import.meta.env.VITE_URL}>
      <div>
        <button>Text</button>
      </div>
    </a>
  );
}

export default LinkNewTab;

The output was working as expected, but running the linter in my terminal returns the following message:

The prop value with an expression type of MetaProperty could not be resolved. Please file an issue ( https://github.com/jsx-eslint/jsx-ast-utils/issues/new ) to get this fixed immediately.
The prop value with an expression type of MetaProperty could not be resolved. Please file an issue ( https://github.com/jsx-eslint/jsx-ast-utils/issues/new ) to get this fixed immediately.

The error message no longer shows up when I modified my approach to simply trigger window.open upon clicking the button and removing the wrapping anchor and div tags.

function LinkNewTab() {
  return (
     <button onClick={() => window.open(import.meta.env.VITE_URL, '_blank')}>Text</button>
  );
}

export default LinkNewTab;
@ljharb
Copy link
Member

ljharb commented Sep 14, 2023

Be advised this isn't a good UX - things that navigate should only be links and should look like links. Also, the default type of button is submit, so you definitely want an explicit type="button".

That said, "MetaProperty" refers to import.meta and that's not present in your code sample. Are you sure that's the correct sample?

@edmaala
Copy link
Author

edmaala commented Sep 14, 2023

Oh. I was actually importing the href from a .env file. I'll be updating the sample then.

@ljharb
Copy link
Member

ljharb commented Sep 14, 2023

ok, then this duplicates #133 (but with much more info, thanks!) and #119.

However, we already have import.meta in our tests, which are passing. Can you perhaps make a repro case, with a repo or a codesandbox?

@ljharb ljharb changed the title ESLint error message encountered on specific nesting of elements ESLint error message encountered on MetaProperty Sep 14, 2023
@edmaala
Copy link
Author

edmaala commented Sep 15, 2023

Here it is https://codesandbox.io/p/sandbox/meta-property-repro-ml864q?file=%2Ftsconfig.json%3A19%2C38

Here's a screenshot as well.
image

I've also noticed that the error does not show up in the sandbox when I only had the basic Vite and ESLint setup. It only reappeared after I added airbnb and prettier as additional dev dependencies.

@edmaala
Copy link
Author

edmaala commented Oct 4, 2023

Hi @ljharb . Would just like to know if this has already been resolved. Should I close the issue?

@ljharb
Copy link
Member

ljharb commented Oct 5, 2023

It hasn't been, and no, the issue should stay open until it is.

@ljharb

This comment was marked as off-topic.

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

No branches or pull requests

2 participants