question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting an undefined kit.version.name in to a Date.now(), a hardcoded timestamp gets added and generates unique static files for each build

See original GitHub issue

Describe the bug

When you do not include a version.name, Svelte uses a Date.now().toString() (https://kit.svelte.dev/docs/configuration). This has the added benefit of always rendering a unique version. The downside of this is that this gets passed on and hardcoded in the singletons.js during a build. Consequently making the singletons.hash.js unique to each build. If your hosting does not “share” build assets while scaling horizontally this creates a problem in that you get 404’s (each container has a unique set of files).

Reproduction

  1. install sveltekit
  2. run a build
  3. rename output folder (to prevent overwriting it)
  4. run a second build (without any code changes)
  5. observe that build/_app/immutable/chunks/singletons-[hash].js is now different from the previous build

Logs

No response

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Pro
    Memory: 106.39 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
  Browsers:
    Brave Browser: 105.1.43.93
    Chrome: 105.0.5195.125
    Firefox Developer Edition: 106.0
    Safari: 16.0
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.42 => 1.0.0-next.43
    @sveltejs/kit: next => 1.0.0-next.491
    svelte: ^3.44.0 => 3.50.1
    vite: ^3.1.3 => 3.1.3

Severity

annoyance

Additional Information

Perhaps the singletons could uses a pointer to the version, and not a hardcoded version?

the original code can be found here: https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/utils.js#L140 which gets its contents from here: https://github.com/sveltejs/kit/blob/master/packages/kit/src/exports/vite/build/utils.js#L136

CC @s-rd

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
Rich-Harriscommented, Oct 4, 2022

If that were replaced by what’s being proposed above, I would need to sign in, get a server-rendered HTML page served to me, look at its source, and parse through for the version: portion

Unless we were to expose it?

import { version } from '$app/environment';
2reactions
Rich-Harriscommented, Oct 4, 2022

Perhaps if we didn’t embed the version in the generated files, but instead included it in the rendered HTML…

<script type="module" data-sveltekit-hydrate="1vcz4c4">
  import { start } from "./_app/immutable/start-425c5ea9.js";

  start({
    env: {},
    hydrate: {
      status: 200,
      error: null,
      node_ids: [0, 3],
      params: {},
      routeId: "",
      data: (function(a){return [a,a]}(null)),
      form: null
    },
    paths: {"base":"","assets":""},
    target: document.querySelector('[data-sveltekit-hydrate="1vcz4c4"]').parentNode,
    trailing_slash: "never",
+   version: 'xyz123'	
  });
</script>

…then it wouldn’t matter so much, since the assets themselves would retain the same hashes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Timestamp - How can I create a Timestamp with the date ...
@Bhanu The constructor takes the unix time in milliseconds. Use the static method valueOf if you want to get a timestamp from a...
Read more >
Handlebars helper reference - Celigo Help Center
Adds all of the specified variables. This helper adds JSON variables, “hard-coded” values, or a combination thereof. Absolute values do not require context ......
Read more >
GN Reference - Google Git
This command takes three arguments: out_dir is the path to the build directory. input_path is a path to a file containing a JSON...
Read more >
Karate | Test Automation Made Simple.
Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.
Read more >
Underscore.js
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found