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

Make "version" available from $app/environment #7436

Closed
CaptainCodeman opened this issue Oct 30, 2022 · 1 comment · Fixed by #7689
Closed

Make "version" available from $app/environment #7436

CaptainCodeman opened this issue Oct 30, 2022 · 1 comment · Fixed by #7689
Labels

Comments

@CaptainCodeman
Copy link
Contributor

Describe the problem

Caching is great, it makes things fast. But using a cached page after an app deploy means all the script references are wrong and "bad things". So some form of "app version" needs to be part of any cache key.

There is a generated version string, used for the update checks. That could be read from build/client/_app/version.jsonexcept ... it won't be there during the build if pre-rendering.

So you have to check if running in dev or prerendering mode before reading the file.

Describe the proposed solution

I would like to be able to access the version string from $app/environment

Alternatives considered

Maybe it's already exposed from '$service-worker'?

But I don't know if that only works if using a service-worker, and it feels odd importing it from there when it isn't really anything todo with a service-worker.

Importance

nice to have

Additional Information

No response

@emspaced
Copy link

emspaced commented Nov 1, 2022

Somewhat related to #7144 (see comments).

In the meantime, I also needed some form of app versioning for quick (mostly) client-side checks (to automatically clear some outdated localStorage objects), and until kit's appVersion is exposed as proposed, we could resort to defining a basic version key using a vite global var:

// vite.config.ts
import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';

const config: UserConfig = {
  plugins: [sveltekit()],
  define: {
    __VITE_DEV_APP_VERSION__: JSON.stringify(Date.now().toString()),
  },
};

export default config;
// lib/utils/version.ts
import { dev } from '$app/environment';

export const version = dev ? __VITE_DEV_APP_VERSION__ : __SVELTEKIT_APP_VERSION__;

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

Successfully merging a pull request may close this issue.

3 participants