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

withPlausibleProxy() causes Union type that is too complex for next.js Route #112

Open
yannxaver opened this issue Nov 28, 2023 · 8 comments

Comments

@yannxaver
Copy link

yannxaver commented Nov 28, 2023

I have attached a video to show the problem. Once I wrap my next.js config in withPlausibleProxy the union type with Route becomes too complex. Type checking also becomes extremely slow, hence you have to skip around 30 seconds in the video until the error shows up.

Error:

Expression produces a union type that is too complex to represent.
Kapture.2023-11-28.at.22.01.33.mp4
@4lejandrito
Copy link
Owner

hi! can you maybe share a small reproduction repo?

@yannxaver
Copy link
Author

I have tried reproducing it in a blank project, and I cannot.

@yannxaver
Copy link
Author

yannxaver commented Nov 29, 2023

Even if I comment out the function which causes the error, type compilation increases from ~3 to ~30 seconds. Since this prohibits me from using the withPlausibleProxy helper, is there another way that I can specify a custom path to load the script from? I am self hosting plausible at https://foo.bar.com.

If I set

<PlausibleProvider
	domain='bar.com'
	selfHosted
	customDomain='https://foo.bar.com'
/>

it will try to load the script from https://foo.bar.com/js/plausible.js. This will get blocked because the script name contains the word plausible.

I want to be able to set an absolute path, for example:

<PlausibleProvider
	domain='bar.com'
	selfHosted
	customDomain='https://bar.com/friendly-script'
/>

And then manually proxy https://bar.com/friendly-script to https://foo.bar.com/js/plausible.js using next.config.js rewrites.

How would I do that if I cannot use withPlausibleProxy? The library always appends /js/plausible.js to any customDomain I set, which gets blocked then.

@4lejandrito
Copy link
Owner

As a workaround until I find a better way, I recommend you disable statically typed links.

@yannxaver
Copy link
Author

As a workaround until I find a better way, I recommend you disable statically typed links.

Now I know why I couldn't reproduce it yesterday! I forgot to set typedRoutes: true. 😅 Once I set it to true, I can reproduce it easily.

Would there be another way to serve the script from a custom path without using withPlausibleProxy?

@4lejandrito
Copy link
Owner

4lejandrito commented Nov 29, 2023

Not for now, at least with next-plausible. You would have to proxy it yourself with a different mechanism.

You can overwrite the src path of the script via the scriptProps prop of PlausibleProvider and point it to wherever you want as long as the right script is proxied from there.

EDIT: you can skip withPlausibleProvider and just set up your own rewrite, and then apply the props change I mentioned above. This will work as long as all your PlausibleProvider props are static and not dependent on runtime.

@4lejandrito
Copy link
Owner

4lejandrito commented Nov 29, 2023

The reason why it takes so long to process the types is because withPlausibleProxy is setting a single rewrite for each of the possible combinations of modifiers. NextJS then automatically adds each of these rewrites to a TypeScript union type in the .next/types file, which ends up being huge and causing this performance issue.

Click to see the whole union type
type StaticRoutes = 
  | `/`
  | `/js/script.js`
  | `/js/script.exclusions.js`
  | `/js/script.exclusions.local.js`
  | `/js/script.exclusions.local.manual.js`
  | `/js/script.exclusions.local.manual.outbound-links.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.outbound-links.js`
  | `/js/script.exclusions.local.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.local.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.local.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.local.manual.outbound-links.js`
  | `/js/script.exclusions.file-downloads.local.manual.js`
  | `/js/script.exclusions.file-downloads.local.manual.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.manual.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.manual.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.manual.js`
  | `/js/script.exclusions.local.manual.tagged-events.js`
  | `/js/script.exclusions.local.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.manual.tagged-events.js`
  | `/js/script.exclusions.local.manual.pageview-props.js`
  | `/js/script.exclusions.local.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.manual.pageview-props.js`
  | `/js/script.exclusions.local.manual.revenue.js`
  | `/js/script.exclusions.hash.local.manual.revenue.js`
  | `/js/script.exclusions.hash.local.manual.js`
  | `/js/script.exclusions.local.outbound-links.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.outbound-links.js`
  | `/js/script.exclusions.local.outbound-links.tagged-events.js`
  | `/js/script.exclusions.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.outbound-links.tagged-events.js`
  | `/js/script.exclusions.local.outbound-links.pageview-props.js`
  | `/js/script.exclusions.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.outbound-links.pageview-props.js`
  | `/js/script.exclusions.local.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.local.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.local.outbound-links.js`
  | `/js/script.exclusions.file-downloads.local.js`
  | `/js/script.exclusions.file-downloads.local.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.local.tagged-events.js`
  | `/js/script.exclusions.file-downloads.local.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.pageview-props.js`
  | `/js/script.exclusions.file-downloads.local.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.local.js`
  | `/js/script.exclusions.local.tagged-events.js`
  | `/js/script.exclusions.local.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.pageview-props.tagged-events.js`
  | `/js/script.exclusions.local.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.local.tagged-events.js`
  | `/js/script.exclusions.local.pageview-props.js`
  | `/js/script.exclusions.local.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.local.pageview-props.js`
  | `/js/script.exclusions.local.revenue.js`
  | `/js/script.exclusions.hash.local.revenue.js`
  | `/js/script.exclusions.hash.local.js`
  | `/js/script.exclusions.manual.js`
  | `/js/script.exclusions.manual.outbound-links.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.outbound-links.js`
  | `/js/script.exclusions.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.outbound-links.tagged-events.js`
  | `/js/script.exclusions.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.manual.outbound-links.pageview-props.js`
  | `/js/script.exclusions.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.manual.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.manual.outbound-links.js`
  | `/js/script.exclusions.file-downloads.manual.js`
  | `/js/script.exclusions.file-downloads.manual.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.manual.tagged-events.js`
  | `/js/script.exclusions.file-downloads.manual.pageview-props.js`
  | `/js/script.exclusions.file-downloads.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.pageview-props.js`
  | `/js/script.exclusions.file-downloads.manual.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.manual.js`
  | `/js/script.exclusions.manual.tagged-events.js`
  | `/js/script.exclusions.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.pageview-props.tagged-events.js`
  | `/js/script.exclusions.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.manual.tagged-events.js`
  | `/js/script.exclusions.manual.pageview-props.js`
  | `/js/script.exclusions.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.manual.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.manual.pageview-props.js`
  | `/js/script.exclusions.manual.revenue.js`
  | `/js/script.exclusions.hash.manual.revenue.js`
  | `/js/script.exclusions.hash.manual.js`
  | `/js/script.exclusions.outbound-links.js`
  | `/js/script.exclusions.file-downloads.outbound-links.js`
  | `/js/script.exclusions.file-downloads.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.tagged-events.js`
  | `/js/script.exclusions.file-downloads.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.pageview-props.js`
  | `/js/script.exclusions.file-downloads.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.outbound-links.js`
  | `/js/script.exclusions.outbound-links.tagged-events.js`
  | `/js/script.exclusions.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.exclusions.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.outbound-links.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.outbound-links.tagged-events.js`
  | `/js/script.exclusions.outbound-links.pageview-props.js`
  | `/js/script.exclusions.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.outbound-links.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.outbound-links.pageview-props.js`
  | `/js/script.exclusions.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.outbound-links.revenue.js`
  | `/js/script.exclusions.hash.outbound-links.js`
  | `/js/script.exclusions.file-downloads.js`
  | `/js/script.exclusions.file-downloads.tagged-events.js`
  | `/js/script.exclusions.file-downloads.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.pageview-props.tagged-events.js`
  | `/js/script.exclusions.file-downloads.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.revenue.tagged-events.js`
  | `/js/script.exclusions.file-downloads.hash.tagged-events.js`
  | `/js/script.exclusions.file-downloads.pageview-props.js`
  | `/js/script.exclusions.file-downloads.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.pageview-props.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.pageview-props.js`
  | `/js/script.exclusions.file-downloads.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.revenue.js`
  | `/js/script.exclusions.file-downloads.hash.js`
  | `/js/script.exclusions.tagged-events.js`
  | `/js/script.exclusions.pageview-props.tagged-events.js`
  | `/js/script.exclusions.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.pageview-props.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.pageview-props.tagged-events.js`
  | `/js/script.exclusions.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.revenue.tagged-events.js`
  | `/js/script.exclusions.hash.tagged-events.js`
  | `/js/script.exclusions.pageview-props.js`
  | `/js/script.exclusions.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.pageview-props.revenue.js`
  | `/js/script.exclusions.hash.pageview-props.js`
  | `/js/script.exclusions.revenue.js`
  | `/js/script.exclusions.hash.revenue.js`
  | `/js/script.exclusions.hash.js`
  | `/js/script.local.js`
  | `/js/script.local.manual.js`
  | `/js/script.local.manual.outbound-links.js`
  | `/js/script.file-downloads.local.manual.outbound-links.js`
  | `/js/script.file-downloads.local.manual.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.local.manual.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.local.manual.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.outbound-links.js`
  | `/js/script.local.manual.outbound-links.tagged-events.js`
  | `/js/script.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.outbound-links.tagged-events.js`
  | `/js/script.local.manual.outbound-links.pageview-props.js`
  | `/js/script.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.local.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.local.manual.outbound-links.pageview-props.js`
  | `/js/script.local.manual.outbound-links.revenue.js`
  | `/js/script.hash.local.manual.outbound-links.revenue.js`
  | `/js/script.hash.local.manual.outbound-links.js`
  | `/js/script.file-downloads.local.manual.js`
  | `/js/script.file-downloads.local.manual.tagged-events.js`
  | `/js/script.file-downloads.local.manual.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.manual.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.manual.tagged-events.js`
  | `/js/script.file-downloads.local.manual.pageview-props.js`
  | `/js/script.file-downloads.local.manual.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.pageview-props.js`
  | `/js/script.file-downloads.local.manual.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.revenue.js`
  | `/js/script.file-downloads.hash.local.manual.js`
  | `/js/script.local.manual.tagged-events.js`
  | `/js/script.local.manual.pageview-props.tagged-events.js`
  | `/js/script.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.pageview-props.tagged-events.js`
  | `/js/script.local.manual.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.revenue.tagged-events.js`
  | `/js/script.hash.local.manual.tagged-events.js`
  | `/js/script.local.manual.pageview-props.js`
  | `/js/script.local.manual.pageview-props.revenue.js`
  | `/js/script.hash.local.manual.pageview-props.revenue.js`
  | `/js/script.hash.local.manual.pageview-props.js`
  | `/js/script.local.manual.revenue.js`
  | `/js/script.hash.local.manual.revenue.js`
  | `/js/script.hash.local.manual.js`
  | `/js/script.local.outbound-links.js`
  | `/js/script.file-downloads.local.outbound-links.js`
  | `/js/script.file-downloads.local.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.local.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.local.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.local.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.local.outbound-links.js`
  | `/js/script.local.outbound-links.tagged-events.js`
  | `/js/script.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.local.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.local.outbound-links.tagged-events.js`
  | `/js/script.local.outbound-links.pageview-props.js`
  | `/js/script.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.local.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.local.outbound-links.pageview-props.js`
  | `/js/script.local.outbound-links.revenue.js`
  | `/js/script.hash.local.outbound-links.revenue.js`
  | `/js/script.hash.local.outbound-links.js`
  | `/js/script.file-downloads.local.js`
  | `/js/script.file-downloads.local.tagged-events.js`
  | `/js/script.file-downloads.local.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.local.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.local.tagged-events.js`
  | `/js/script.file-downloads.local.pageview-props.js`
  | `/js/script.file-downloads.local.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.local.pageview-props.js`
  | `/js/script.file-downloads.local.revenue.js`
  | `/js/script.file-downloads.hash.local.revenue.js`
  | `/js/script.file-downloads.hash.local.js`
  | `/js/script.local.tagged-events.js`
  | `/js/script.local.pageview-props.tagged-events.js`
  | `/js/script.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.local.pageview-props.tagged-events.js`
  | `/js/script.local.revenue.tagged-events.js`
  | `/js/script.hash.local.revenue.tagged-events.js`
  | `/js/script.hash.local.tagged-events.js`
  | `/js/script.local.pageview-props.js`
  | `/js/script.local.pageview-props.revenue.js`
  | `/js/script.hash.local.pageview-props.revenue.js`
  | `/js/script.hash.local.pageview-props.js`
  | `/js/script.local.revenue.js`
  | `/js/script.hash.local.revenue.js`
  | `/js/script.hash.local.js`
  | `/js/script.manual.js`
  | `/js/script.manual.outbound-links.js`
  | `/js/script.file-downloads.manual.outbound-links.js`
  | `/js/script.file-downloads.manual.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.manual.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.manual.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.manual.outbound-links.js`
  | `/js/script.manual.outbound-links.tagged-events.js`
  | `/js/script.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.manual.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.manual.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.manual.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.manual.outbound-links.tagged-events.js`
  | `/js/script.manual.outbound-links.pageview-props.js`
  | `/js/script.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.manual.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.manual.outbound-links.pageview-props.js`
  | `/js/script.manual.outbound-links.revenue.js`
  | `/js/script.hash.manual.outbound-links.revenue.js`
  | `/js/script.hash.manual.outbound-links.js`
  | `/js/script.file-downloads.manual.js`
  | `/js/script.file-downloads.manual.tagged-events.js`
  | `/js/script.file-downloads.manual.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.manual.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.manual.tagged-events.js`
  | `/js/script.file-downloads.manual.pageview-props.js`
  | `/js/script.file-downloads.manual.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.manual.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.manual.pageview-props.js`
  | `/js/script.file-downloads.manual.revenue.js`
  | `/js/script.file-downloads.hash.manual.revenue.js`
  | `/js/script.file-downloads.hash.manual.js`
  | `/js/script.manual.tagged-events.js`
  | `/js/script.manual.pageview-props.tagged-events.js`
  | `/js/script.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.manual.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.manual.pageview-props.tagged-events.js`
  | `/js/script.manual.revenue.tagged-events.js`
  | `/js/script.hash.manual.revenue.tagged-events.js`
  | `/js/script.hash.manual.tagged-events.js`
  | `/js/script.manual.pageview-props.js`
  | `/js/script.manual.pageview-props.revenue.js`
  | `/js/script.hash.manual.pageview-props.revenue.js`
  | `/js/script.hash.manual.pageview-props.js`
  | `/js/script.manual.revenue.js`
  | `/js/script.hash.manual.revenue.js`
  | `/js/script.hash.manual.js`
  | `/js/script.outbound-links.js`
  | `/js/script.file-downloads.outbound-links.js`
  | `/js/script.file-downloads.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.outbound-links.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.outbound-links.tagged-events.js`
  | `/js/script.file-downloads.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.outbound-links.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.outbound-links.pageview-props.js`
  | `/js/script.file-downloads.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.outbound-links.revenue.js`
  | `/js/script.file-downloads.hash.outbound-links.js`
  | `/js/script.outbound-links.tagged-events.js`
  | `/js/script.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.outbound-links.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.outbound-links.pageview-props.tagged-events.js`
  | `/js/script.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.outbound-links.revenue.tagged-events.js`
  | `/js/script.hash.outbound-links.tagged-events.js`
  | `/js/script.outbound-links.pageview-props.js`
  | `/js/script.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.outbound-links.pageview-props.revenue.js`
  | `/js/script.hash.outbound-links.pageview-props.js`
  | `/js/script.outbound-links.revenue.js`
  | `/js/script.hash.outbound-links.revenue.js`
  | `/js/script.hash.outbound-links.js`
  | `/js/script.file-downloads.js`
  | `/js/script.file-downloads.tagged-events.js`
  | `/js/script.file-downloads.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.pageview-props.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.pageview-props.tagged-events.js`
  | `/js/script.file-downloads.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.revenue.tagged-events.js`
  | `/js/script.file-downloads.hash.tagged-events.js`
  | `/js/script.file-downloads.pageview-props.js`
  | `/js/script.file-downloads.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.pageview-props.revenue.js`
  | `/js/script.file-downloads.hash.pageview-props.js`
  | `/js/script.file-downloads.revenue.js`
  | `/js/script.file-downloads.hash.revenue.js`
  | `/js/script.file-downloads.hash.js`
  | `/js/script.tagged-events.js`
  | `/js/script.pageview-props.tagged-events.js`
  | `/js/script.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.pageview-props.revenue.tagged-events.js`
  | `/js/script.hash.pageview-props.tagged-events.js`
  | `/js/script.revenue.tagged-events.js`
  | `/js/script.hash.revenue.tagged-events.js`
  | `/js/script.hash.tagged-events.js`
  | `/js/script.pageview-props.js`
  | `/js/script.pageview-props.revenue.js`
  | `/js/script.hash.pageview-props.revenue.js`
  | `/js/script.hash.pageview-props.js`
  | `/js/script.revenue.js`
  | `/js/script.hash.revenue.js`
  | `/js/script.hash.js`
  | `/proxy/api/event`

The reason why next-plausible does this is because it cannot know in advance which modifiers you will be using, as they are set as props in the React component PlausibleProvider at render time.

The easiest way to fix this would be to use a clever regex as rewrite instead of so many individual ones. However nextjs regex support for rewrites is limited and does not cover this use case.

The next best option I see is to move away completely from withPlausibleProxy in the config file and instead provide the same logic but as a conditional middleware. Something like this (just an idea, not implemented):

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import {isNextPlausibleRequest, proxyNextPlausibleRequest} from 'next-plausible'
 
export function middleware(request: NextRequest) {
  if (isNextPlausibleRequest(request) {
    return proxyNextPlausibleRequest(request)
  }
}

Although I like the simplicity of withPlausibleProxy being just a config wrapper, it comes at the cost of having to use so many rewrites. On the other hand middleware is really the tool to use for these cases, only that it didn't exist when I first created next-plausible.

@yannxaver
Copy link
Author

yannxaver commented Nov 29, 2023

Not for now, at least with next-plausible. You would have to proxy it yourself with a different mechanism.

You can overwrite the src path of the script via the scriptProps prop of PlausibleProvider and point it to wherever you want as long as the right script is proxied from there.

EDIT: you can skip withPlausibleProvider and just set up your own rewrite, and then apply the props change I mentioned above. This will work as long as all your PlausibleProvider props are static and not dependent on runtime.

Thank you, this works! Probably obvious for you, but I will write it for others: you also need to set data-api because otherwise the page view post requests will be sent to the domain that the app is running on. Alternatively, you can also use a nextjs rewrite here.

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

No branches or pull requests

2 participants