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

[bug] translateHref is using the wrong context ($page) in preprocessor leading to invalid href/action urls #143

Closed
savar opened this issue Feb 3, 2024 · 2 comments · Fixed by opral/monorepo#2173 or opral/monorepo#2174
Assignees
Labels
bug Something isn't working

Comments

@savar
Copy link

savar commented Feb 3, 2024

Problem

At least (not tested with <a href="?some=var">) with <form action="?/myaction"> when navigating from one page to another where such a <form> is defined, the action gets prefixed (as long as not disabled via data-no-translate) with the path of the previous page I was coming from.

This can be seen even on the playground example.

If starting on a page /about
image
and then going to Sverdle by clicking on the link, the form gets the wrong url:

image

so when filling out the first line with chracters and then press the enter button

image

the action is not called on the /sverdle routing but on the /about routing:
image

While trying to debug, the preprocessor function translateHref() in ParaglideJS.svelte showed that the $page object was still having in the .url the previous url (so here the /about) instead of the (already in the browser url visible) /sverdle.

We saw that in our own project initially but as the example project shows the same behaviour, I hope it is easier to debug/hunt this down. Best guess: the preprocessor is called before the $page was updated or any kind of event is not working as expected.

If you reload the /sverdle page, then the url is correctly prefixed.

Expected behavior

Either that the correct prefix (the URL which is actually opened in that moment) is added or it stays relative and no URL is added at all (not sure though if this is the expected behaviour when it comes to translating URLs or good for SEO).

Reproduction

1. go to https://stackblitz.com/~/github.com/lorissigrist/paraglide-sveltekit-example

2. click on the ABOUT link at the top of the loaded test page

3. enter any word in the first row

4. press the ENTER button

5. you should see "METHOD NOT ALLOWED" as an error.

Other information

No response

@samuelstroschein
Copy link
Member

samuelstroschein commented Feb 3, 2024

@LorisSigrist off-topic [ no reply needed in this thread ]: the preprocessor seems to be the wrong architectural decision. we should probably push the svelte team to provide a native solution

  • seems like most bugs come from preprocessing
  • this situation reminds me of our first i18n lib that also used preprocessing and was ultimately scrapped because source code transformation leads to too many bugs

@LorisSigrist
Copy link
Member

@LorisSigrist LorisSigrist transferred this issue from opral/monorepo Jun 5, 2024
@LorisSigrist LorisSigrist added the bug Something isn't working label Jun 5, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants