nanostores / router

A tiny (673 bytes) router for Nano Stores state manager
MIT License
246 stars 19 forks source link

Invalid regular expression: invalid group specifier name #38

Open gitlobster opened 3 months ago

gitlobster commented 3 months ago

Mobile Safari 14.1.2

Level: Error Invalid regular expression: invalid group specifier name

https://caniuse.com/js-regexp-lookbehind

ai commented 3 months ago

Show your router definition

gitlobster commented 3 months ago
const $router = createRouter({
  brands: '/brands/:value/:level2CategoryId?/:level3CategoryId?/:level4CategoryId?/:level5CategoryId?/',
  promo: '/promo/:value/:level2CategoryId?/:level3CategoryId?/:level4CategoryId?/:level5CategoryId?/',
  filter: [
    /\/catalog\/(.*)\/(.*)\/filter\/(.*)\/apply(.*)/,
    (rootCategory, level2CategoryId, smartFilterPath) => {
      return {
        rootCategory,
        level2CategoryId,
        smartFilterPath,
      }
    },
  ],
  section: [
    /\/catalog\/([^/]+)\/([^/]+)\/?([^/]*)\/?([^?]*)\/?([^?]*)/,
    (rootCategory, level2CategoryId, level3CategoryId, level4CategoryId) => {
      const clearLevel2 = level2CategoryId.replace(/\?.*/, '')
      const clearLevel3 = level3CategoryId.replace(/\?.*/, '')
      const clearLevel4 = level4CategoryId.replace(/\?.*/, '')
      return {
        rootCategory,
        level2CategoryId: clearLevel2,
        level3CategoryId: clearLevel3,
        level4CategoryId: clearLevel4,
      }
    }],
  actions: [
    /\/(actions)\/?([^/]*)\/?([^/]*)\/?([^/]*)\/?([^?]*)\/?([^?]*)/,
    (rootCategory, level2CategoryId, level3CategoryId, level4CategoryId) => {
      const clearLevel2 = level2CategoryId.replace(/\?.*/, '')
      const clearLevel3 = level3CategoryId.replace(/\?.*/, '')
      const clearLevel4 = level4CategoryId.replace(/\?.*/, '')
      return {
        rootCategory,
        level2CategoryId: clearLevel2,
        level3CategoryId: clearLevel3,
        level4CategoryId: clearLevel4,
      }
    }],
  cart: '/cart/',
  checkout: '/checkout/',
  'order-completed': '/checkout/:orderId',
  personal: '/my/',
  favorite: '/my/favorite/',
  compare: '/my/compare/',
  pickpoints: '/shops/',
  'pickpoints-city': '/shops/:city/',
  'pickpoints-pickpoint': '/shops/:city/:id/',
  delivery: '/delivery/',
  'delivery-city': '/delivery/:city/',
}, { links: false, search: true })

it's not spa, only some parts of site have logic on vue

ai commented 3 months ago

Hm, regexp-lookbehind really fits our needs and I do not want to make code worse to support old browsers.

You can achieve the same result without using RegExp by combining string-based router with compute() (where you will clean params).

What do you think about it? Or why do you think we should support Safari 14?

gitlobster commented 3 months ago

I have 8 such users in a couple of hours. Yesterday, because of this mistake, we lost a customer buying a pair of lawn mowers

I don't know javascript so deeply that I can quickly rewrite the code, but in general, if not, then no

gitlobster commented 3 months ago

image Not only safari 14

ai commented 3 months ago

To fix issue quickly you can downgrade @nanostores/routes to 0.14.x

ai commented 3 months ago

Safari 0.15 is about 0.83 % in global market statistic (other browser in the list is just a skin for Safari, anyway it related to the browser).

What is your market? Why you have so many old iOS users?

gitlobster commented 3 months ago

Version 14 contains this error too. I think the fact is that we have a lot of customers from the provinces, so there is so much old hardware

ai commented 3 months ago

Got it! It is related with this PR https://github.com/nanostores/router/pull/32

Move to 0.14.1.

But it fixed a real issue, I am not sure how we can revert it without breaking in another part.

@easing do you have any idea?

gitlobster commented 3 months ago

playing with the library versions didn't help, but I tweaked it a little for the option, which is not entirely true, but fits my particular case

the next step is to change the code in my business logic, I think I understood how it would work in my case

thnks