Installing SvelteKit in WordPress: Page keeps reloading infinitely
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
Page keeps reloading in WordPress admin page after the all the build files have been referenced properly. It reloads in an infinite loop.
The +layout.js is set as,
export const prerender = true;
export const ssr = false;
The svelte.config.js file is condifgured as,
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter(),
paths: {
base: '/wp-content/plugins/astro-forms/assets'
}
},
preprocess: vitePreprocess()
};
export default config;
The vite.config.js is set as,
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()]
});
When the build is run it produces several files in an _app folder and a version.json file. The files are copied into the WordPress plugins assets folder and are referenced using the admin_head action hook to do the following,
public static function astroFormsModulePreloadLinks()
{
$version = '1.2';
echo '<link rel="modulepreload" href="' . AF_PLUGIN_URL . 'assets/_app/immutable/entry/start.7b810d09.js?v=' . $version . '">';
echo '<link rel="modulepreload" href="' . AF_PLUGIN_URL . 'assets/_app/immutable/chunks/scheduler.ec1e1a00.js?v=' . $version . '">';
echo '<link rel="modulepreload" href="' . AF_PLUGIN_URL . 'assets/_app/immutable/chunks/singletons.0451d5e2.js?v=' . $version . '">';
echo '<link rel="modulepreload" href="' . AF_PLUGIN_URL . 'assets/_app/immutable/chunks/index.0b861ccf.js?v=' . $version . '">';
echo '<link rel="modulepreload" href="' . AF_PLUGIN_URL . 'assets/_app/immutable/entry/app.749411f8.js?v=' . $version . '">';
echo '<link rel="modulepreload" href="' . AF_PLUGIN_URL . 'assets/_app/immutable/chunks/preload-helper.a4192956.js?v=' . $version . '">';
echo '<link rel="modulepreload" href="' . AF_PLUGIN_URL . 'assets/_app/immutable/chunks/index.a313f8a5.js?v=' . $version . '">';
}
The script within the body of the page is modified as follows,
{
const thisBase = new URL("<?php echo AF_PLUGIN_URL . 'assets/' ?>", location).pathname.slice(0, -1);
console.log( thisBase );
__sveltekit_h36q48 = {
assets: thisBase,
base: new URL(thisBase, location).pathname.slice(0, -1),
env: {}
};
const element = document.currentScript.parentElement;
Promise.all([
import( thisBase + "/_app/immutable/entry/start.7b810d09.js"),
import( thisBase + "/_app/immutable/entry/app.749411f8.js")
]).then(([kit, app]) => {
kit.start(app, element);
});
}
When the page is loaded, it keeps reloading.
Reproduction
Load the page when all the scripts have been properly referenced in the WordPress plugin
Logs
No response
System Info
Using,
- @sveltejs/kit v 1.20.4
- @sveltejs/adapter-static v 2.0.3
Building with,
- vite v 4.4.2
Severity
blocking all usage of SvelteKit
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with +layout.js, svelte.config.js, vite.config.js, and the WordPress admin_head bootstrap shown in the report. Reproduce the admin page load while inspecting browser console and network activity, then trace the generated _app entry files and version.json. Done means the embedded page initializes without an infinite reload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php, vite
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100