Skip to content

Type Error: illegal invocation #4239

Open
@hamedtahmasebi

Description

@hamedtahmasebi

Which project does this relate to?

Router

Describe the bug

Hi, I am using the following packages
@tanstack/react-router": "^1.117.0
vite: "^5.4.8
@tanstack/router-plugin": "^1.117.0

I am using file based routing, and in production I am getting this illegal invocation error for some of the users. I couldn't reproduce this but according to sentry it's happening for some of the users.

  const flush = () => {
    if (!next) {
      return;
    }
    history._ignoreSubscribers = true;
    (next.isPush ? win.history.pushState : win.history.replaceState)(  // This is where it happens
      next.state,
      "",
      next.href
    );
    history._ignoreSubscribers = false;

Following sentry stacktrace, when user clicks on one of the links in the app that redirects to another page ( using navigate and both pages are within my app, tanstack router ) it crashes due to illegal invocation.

My vite config:

export default defineConfig({
    // depending on your application, base can also be "/"
    base: "/web",
    plugins: [
        TanStackRouterVite({ target: 'react', autoCodeSplitting: true }),
        react(), svgr(), mkcert(),
        sentryVitePlugin({
            org: "****",
            project: "****",
            authToken: "****",
        }),
],
    build: {
        outDir: "build",
        sourcemap: true,
        minify: 'esbuild'

    },
    preview: {
        port: 3000,
    },
    server: {
        https: true,
        // this ensures that the browser opens upon server start
        open: true,
        // this sets a default port to 3000
        port: 3000,
    },
    resolve: {
        alias: {
            components: path.resolve("./src/components"),
            core: path.resolve("./src/core"),
            assets: path.resolve("./src/assets"),
            pages: path.resolve("./src/pages"),
            hooks: path.resolve("./src/hooks"),
            layouts: path.resolve("./src/layouts"),
        },
    },
    assetsInclude: ["**/*.webp", "**/*.png", "**/*.jpg"],
})

Thank you in advance for your help.

Your Example Website or App

Steps to Reproduce the Bug or Issue

Open the app
Click on one of the buttons that uses navigate ({to : url})
Crashed due to illegal invocation.

This flow was sentry stacktrace and I can NOT reproduce it but it's happening to the users ( more than 50 events and 40> unique users )

Expected behavior

Expected to navigate to the specified url but it crashes due to illegal invocation error

Screenshots or Videos

Image

Image

Platform

  • OS: Windows

  • Browser: Chrome

  • Version: 136.0.0

  • Brower: Firefox

  • Version: 138.0

  • Browser: Edge

  • Version: 136.0.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions