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

test(html): do not wrap duplicated html #11515

Merged
merged 1 commit into from Dec 29, 2022
Merged

Conversation

fi3ework
Copy link
Member

@fi3ework fi3ework commented Dec 28, 2022

Description

When trying to add test for importmap in playground/html for #11492. I found that all the html will be wrapped into another html tag by pre-transform hook. Even there's already an existing <html> tag in the html file itself.

Files already have a html tag in playround/html

image

So, the transformed html of above looks like below (/emptyattr in dev mode)

<!DOCTYPE html>
<html lang="en">
  <head lang="en">
    <meta name="description" content="a vite app">

    <script type="importmap">
              {
                "imports": {
                  "vue": "https://unpkg.com/vue@3.2.0/dist/vue.runtime.esm-browser.js"
                }
              }
            </script>
    <script type="module" src="/@vite/client"></script>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test HTML transforms</title>
    <meta name="keywords" content="es modules">

  </head>
<body>
  <noscript><!-- this is prepended to body --></noscript>

  <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Empty Attr</title>
  </head>
  <body>
    <img src="" alt="" />
    <p class="inject">This is injected</p>
    <p class="server">This is injected only during dev</p>
    <noscript><!-- this is appended to body --></noscript>
  </body>
</html>

</body>
</html>

after fixing, will be

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="description" content="a vite app">

    <script type="importmap">
              {
                "imports": {
                  "vue": "https://unpkg.com/vue@3.2.0/dist/vue.runtime.esm-browser.js"
                }
              }
            </script>
    <script type="module" src="/@vite/client"></script>

    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Empty Attr</title>
    <meta name="keywords" content="es modules">

  </head>
  <body>
    <noscript><!-- this is prepended to body --></noscript>

    <img src="" alt="" />
    <p class="inject">This is injected</p>
    <p class="server">This is injected only during dev</p>
    <noscript><!-- this is appended to body --></noscript>
  </body>
</html>

Additional context

#11492 relies on this to add a test case with importmap, multiple heads in html will mess the test up.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

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

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy merged commit 7d20580 into vitejs:main Dec 29, 2022
@bluwy
Copy link
Member

bluwy commented Dec 29, 2022

Thanks!

@fi3ework fi3ework deleted the fix-test-html branch December 29, 2022 03:35
futurGH pushed a commit to futurGH/vite that referenced this pull request Feb 26, 2023
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.

None yet

2 participants