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

[fix] don't strip type="application/.." tags #6887

Merged
merged 2 commits into from Sep 19, 2022

Conversation

dummdidumm
Copy link
Member

Fixes #6862

Please don't delete this checklist! 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

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

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Sep 19, 2022

🦋 Changeset detected

Latest commit: 1cceda8

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/package 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

@Rich-Harris
Copy link
Member

This approach will work in 99% of scenarios but it makes me a little nervous — what we should really be doing is stripping lang from top-level <script> elements while ignoring any inside elements (including <svelte:head>). Is there a straightforward way to do that?

@dummdidumm
Copy link
Member Author

svelte-preprocess transforms all script/style tags handed to it. Those tags are found through a Regex in Svelte core - so today more than the top level tags are transformed. Therefore, it would be inconcistent to only strip it from top level tags afterwards - it could theoretically produce bugs for people.

For Svelte 4 I'd like to rework the preprocessing by having a parser instead of a Regexp (that parser would make some assumptions about the form of the unpreprocessed code, balanced brackets etc) which would also help to preprocess mustache tags inside the markup so people could use TypeScript in there - but until we have that, the best we can do is string-checks.

@Rich-Harris
Copy link
Member

Ah, got it. In that case the good-enough solution is good enough

@Rich-Harris Rich-Harris merged commit e3de793 into master Sep 19, 2022
@Rich-Harris Rich-Harris deleted the fix-package-lang-strip branch September 19, 2022 15:07
@niktek
Copy link
Contributor

niktek commented Sep 21, 2022

Hi,

This seems to have broken our packaging for our project. It looks like there is no check on whether s4 contains a value before doing a startsWith in package/src/utils.js:55:34. When we run pnpm package we get the following:

> Cannot read properties of undefined (reading 'startsWith')
    at file:///Users/nik/code/skeleton/node_modules/.pnpm/@sveltejs+package@1.0.0-next.4_iprco5tylfmvffqgrvqxc46njy/node_modules/@sveltejs/package/src/utils.js:55:34
    at String.replace (<anonymous>)
    at strip_lang_tags (file:///Users/nik/code/skeleton/node_modules/.pnpm/@sveltejs+package@1.0.0-next.4_iprco5tylfmvffqgrvqxc46njy/node_modules/@sveltejs/package/src/utils.js:52:4)
    at process_file (file:///Users/nik/code/skeleton/node_modules/.pnpm/@sveltejs+package@1.0.0-next.4_iprco5tylfmvffqgrvqxc46njy/node_modules/@sveltejs/package/src/index.js:201:16)
    at async Module.build (file:///Users/nik/code/skeleton/node_modules/.pnpm/@sveltejs+package@1.0.0-next.4_iprco5tylfmvffqgrvqxc46njy/node_modules/@sveltejs/package/src/index.js:61:3)
    at async file:///Users/nik/code/skeleton/node_modules/.pnpm/@sveltejs+package@1.0.0-next.4_iprco5tylfmvffqgrvqxc46njy/node_modules/@sveltejs/package/src/cli.js:27:4

Looking at #6862 our project does nothing with application/ and I can't see any debug info as to what file in our project is making this check fail. It is managing to process a considerable amount of the project before it fails though.

@niktek niktek mentioned this pull request Sep 21, 2022
5 tasks
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.

svelte-package removes type="application/ld+json" from script tags
3 participants