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

SEO Support LD+JSON in head #785

Closed
lsabi opened this issue Mar 30, 2021 · 4 comments
Closed

SEO Support LD+JSON in head #785

lsabi opened this issue Mar 30, 2021 · 4 comments

Comments

@lsabi
Copy link

lsabi commented Mar 30, 2021

Describe the bug
When inserting structured information, for SEO purpose, into the head of a page in ld+json format, this is not possible. Instead, by omitting the type of the script, this renders with no visible error.

Logs
The error I get from vite in my browser

Cannot find module './transformers/ld+json'

To Reproduce
I'm using the latest available version of kit.

Simply add to one of the pages the following snippet

<svelte:head>
    <script type="application/ld+json">
        {
            "@context": "http://schema.org",
            "@type": "Product",
            "name": "",
            "description": "",
            "image": "",
            "brand": ""
        }
    </script>
</svelte:head>

Expected behavior
The expected behavior is to be able to specify the type of a script (at least, in this format)

Stacktraces
If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace

Cannot find module './transformers/ld+json'
Require stack:

  • /path/to/folder/ui/node_modules/svelte-preprocess/dist/autoProcess.js
  • /path/to/folder/ui/node_modules/svelte-preprocess/dist/index.js
  • /path/to/folder/ui/svelte.config.cjs
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at /path/to/folder/ui/node_modules/svelte-preprocess/dist/autoProcess.js:36:77
    at async Object.transform (/path/to/folder/ui/node_modules/svelte-preprocess/dist/autoProcess.js:36:29)
    at async /path/to/folder/ui/node_modules/svelte-preprocess/dist/autoProcess.js:109:29
    at async script (/path/to/folder/ui/node_modules/svelte-preprocess/dist/autoProcess.js:137:33)
    at async process_single_tag (/path/to/folder/ui/node_modules/svelte/compiler.js:30147:28
    Click outside or fix the code to dismiss.
    You can also disable this overlay with hmr: { overlay: false } in vite.config.js.

Information about your SvelteKit Installation:

  • The output of npx envinfo --system --npmPackages svelte,@sveltejs/kit --binaries --browsers
 System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz
    Memory: 248.39 MB / 7.66 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    npm: 7.7.4 - ~/.nvm/versions/node/v14.16.0/bin/npm
  Browsers:
    Firefox: 87.0
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.60 
    svelte: ^3.29.0 => 3.35.0 

  • Your browser
    Brave Browser Version 1.21.76 Chromium: 89.0.4389.86 (Official Build) (64-bit)

  • Your adapter (e.g. Node, static, Vercel, Begin, etc...)
    Plain node at the moment, since I'm still developing and discovering kit

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of SvelteKit entirely?

Note: the more honest and specific you are here the more we will take you seriously.

Additional context
Add any other context about the problem here.

@Conduitry
Copy link
Member

I believe this is an error coming from https://github.com/sveltejs/svelte-preprocess and that that library is being asked to transform all scripts, and it can't find an appropriate way to do so with that script. Before parsing, the Svelte compiler can't tell which <script> tags are top level vs. which are inside another element, so we can't skip preprocessing it altogether - we'll just have to make sure that preprocessing it does nothing.

@kaisermann Is there a way to make svelte-preprocess more careful about which script types it attempts to preprocess? I'm not sure where the call to svelte-preprocess lives (maybe in the Svelte Vite plugin?), but is there something we could or should do there so that svelte-preprocess doesn't try to convert things it doesn't know how to?

@Conduitry
Copy link
Member

Oh. The call to svelte-preprocess lives right in svelte.config.cjs, that's convenient. Presumably we need the template to do something smarter than preprocess: sveltePreprocess() or svelte-preprocess needs to do something smarter when it's not told what to preprocess.

@lsabi
Copy link
Author

lsabi commented Mar 30, 2021

I believed that since it's within the svelte:head tags, it wasn't supposed to be transformed, but rather just copied and pasted.

Alternatively, there could be another tag that injects the code as it is, without getting through the preprocessor.

@benmccann
Copy link
Member

You can use the preserve option for now: https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#auto-preprocessing-options

Closing as a duplicate of sveltejs/svelte-preprocess#305

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

No branches or pull requests

3 participants