|
1 | 1 | # Max Safe URL Length Exceeded
|
2 | 2 |
|
3 |
| -This error occurs if your URI length exceeds 2,000 |
4 |
| -characters, there are varying browser limitations |
5 |
| -for max URL lengths. |
| 3 | +This error occurs if your URL length exceeds 2,000 characters. |
6 | 4 |
|
7 |
| -See [here](https://nuqs.47ng.com/docs/limits#max-url-lengths) for URL max lengths across different browsers. |
| 5 | +There are varying browser limitations for max URL lengths, [read more](https://nuqs.47ng.com/docs/limits#max-url-lengths). |
| 6 | + |
| 7 | +URLs that are too long might break in some browsers, or not be able to be |
| 8 | +processed by some servers. |
8 | 9 |
|
9 | 10 | ## Possible Solutions
|
10 | 11 |
|
11 |
| -Refactor your state architecture to ensure your total |
12 |
| -URL length doesn't exceed 2,000 characters. |
| 12 | +Keeping your URLs short is a good practice: not all state has to live in the URL. |
| 13 | + |
| 14 | +- Server state/data is best managed in a local cache like TanStack Query or SWR. |
| 15 | +- Transient state (that doesn't need persisting or sharing) can be managed in local state. |
| 16 | +- Device-persistent state can be managed in local storage. |
| 17 | + |
| 18 | +When deciding to put state in the URL, ask yourself: |
| 19 | + |
| 20 | +- Do I need it to persist across page refresh? |
| 21 | +- Do I need to share it with others? |
| 22 | +- Do I need to link to it from other places? |
| 23 | +- Do I need to be able to bookmark it? |
| 24 | +- Do I need to be able to use the Back/Forward buttons to navigate to it? |
| 25 | +- Is it always going to be a small amount of data? |
| 26 | + |
| 27 | +If the answer to any of these questions is no, then you might want to consider |
| 28 | +an alternative state storage solution. |
0 commit comments