sveltekit-flash-message icon indicating copy to clipboard operation
sveltekit-flash-message copied to clipboard

Render error when using "$app/state"

Open directormac opened this issue 10 months ago • 7 comments

TypeError: __vite_ssr_import_8__.page.subscribe is not a function
TypeError: __vite_ssr_import_8__.page.subscribe is not a function
    at _layout (/web/src/routes/+layout.svelte:19:6)
    at Root (/web/.svelte-kit/generated/root.svelte:63:3)
    at render (/web/node_modules/svelte/src/internal/server/index.js:115:2)
    at Function._render [as render] (/web/node_modules/svelte/src/legacy/legacy-server.js:27:24)
    at render_response (/web/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:187:29)
    at async render_page (/web/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:305:10)
    at async resolve (/web/node_modules/@sveltejs/kit/src/runtime/server/respond.js:457:18)
    at async auth (/web/src/hooks.server.ts:43:10)
    at async respond (/web/node_modules/@sveltejs/kit/src/runtime/server/respond.js:330:20)
    at async file:/web/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:521:22

Versions

		"svelte": "^5.19.4",
		"sveltekit-flash-message": "^2.4.6",
		"@sveltejs/kit": "^2.16.1",

directormac avatar Jan 28 '25 17:01 directormac

Try deleting node_modules, reinstall them and restart VS Code.

ciscoheat avatar Jan 29 '25 01:01 ciscoheat

Hi @ciscoheat i did try that already,

Things to note idk if it affects it but i tired using both adapter-auto and adapter-node, still that same error pops up.

directormac avatar Jan 29 '25 12:01 directormac

Compare with this working example and check for differences: https://www.sveltelab.dev/m24gt8rvhwmthu1?files=.%2Fsrc%2Froutes%2F%2Blayout.svelte%2C.%2Fsrc%2Froutes%2F%2Bpage.server.ts

ciscoheat avatar Jan 29 '25 13:01 ciscoheat

Ah i see the problem now. it conflicts with houdini client.
where by default it exports it's own load on the root +layout.server.ts

Error: Transform failed with 1 error:
/web/src/routes/+layout.server.ts:10:9: ERROR: Multiple exports with the same name "load"
  errors: [
    {
      detail: undefined,
      id: '',
      location: [Object],
      notes: [Array],
      pluginName: '',
      text: 'Multiple exports with the same name "load"'
    }
  ],
  warnings: [],
  frame: '\n' +
    '\x1B[33mMultiple exports with the same name "load"\x1B[39m\n' +
    '8  |  }\n' +
    '9  |  \n' +
    '10 |  export { load } from "sveltekit-flash-message/server";\n' +
    '   |           ^\n',
  loc: {
    file: 'web/src/routes/+layout.server.ts',
    line: 10,
    column: 5
  },
  plugin: 'vite:esbuild',
  id: 'web/src/routes/+layout.server.ts',
  pluginCode: 'import { buildSessionObject } from "$houdini/plugins/houdini-svelte/runtime/session";\n' +
    '\n' +
    'export async function load(event) {\n' +
    '    return {\n' +
    '        ...buildSessionObject(event),\n' +
    '        ...{}\n' +
    '    };\n' +
    '}\n' +
    '\n' +
    'export { load } from "sveltekit-flash-message/server";',
  runnerError: Error: RunnerError

When i use this

export { load } from 'sveltekit-flash-message/server';

So i opted into using the flash, like this

import { loadFlash, flashCookieOptions } from 'sveltekit-flash-message/server';
flashCookieOptions.sameSite = 'lax';
export const load = loadFlash(async () => {});

I think it's doing it's error because this is being overriden by the houdini plugin, because that error went away.

Still doing "$app/state" import of page and loading it to flash gives me the original error, but not when importing the page from "$app/store".

directormac avatar Jan 29 '25 14:01 directormac

I have similar issue, the $app/store has been deprecated. I am trying to refactor my existing working code, but the code const flash = getFlash(page); is refering to the actual store and not the subscription $page. So how should we reference it if we change to $app/state?

benquan avatar Jan 30 '25 02:01 benquan

Having a similar issue using page from $app/state instead of page from $app/store. If using page from $app/state I don't get the flashing alert I set up unless I refresh the page, or navigate away, however with page from $app/store everything works as is, I assume there's some kind of subscription to be sent to getFlash in order for this to work with $app/state as its the preferred behaviour for svelte 5

maumercado avatar Mar 14 '25 17:03 maumercado

btw this issue has been fixed with this houdini pr. try upgrading houdini-svelte

ihsanmohamad avatar Apr 05 '25 16:04 ihsanmohamad