marklogic-community / slush-marklogic-node

Slush generator for a MarkLogic/node project
https://github.com/marklogic-community/slush-marklogic-node/wiki
Other
40 stars 28 forks source link

detail router stripping '/' from uri on page refresh #303

Closed patrickmcelwee closed 8 years ago

patrickmcelwee commented 8 years ago

I confirmed this with a fresh application generated with bleeding-edge slush. When I load the sample data, eg, the page loads fine.

Though, for reasons I don't understand, it calls out to the REST API for the document twice. The first time is successful, but the second time, the URI is truncated: the preceding '/' is dropped.

The successful first call looks like:

http://localhost:3000/v1/documents?format=json&uri=%2Fdata-922.json

The second call drops the slash and so returns a 404:

http://localhost:3000/v1/documents?format=json&uri=data-922.json

If I refresh the page, or deep-link to it, I always get the second, broken version, and the page fails to load.

I confirmed that the uri in the resolve function in the angular router's detail state definition is incorrect (missing the 'slash') in these cases. The culprit seems to be squash: true ... everything works if I remove that. The odd thing is that this line has been present since July.

I am going to submit a pull request to delete that line. It seems to be working fine without it. According to the docs on squash, it is intended to clean up URLs. Perhaps in a older version of the router library, it helped clean up double-slashes (something like /detail//docs/1234.xml), but it doesn't seem necessary any longer.

grtjn commented 8 years ago

Thnx for reporting!

grtjn commented 8 years ago

Not observing this behavior in a recent project. Running with angular 1.4.9? I do recall Angular tends to remove trailing slashes, which cause things to get loaded twice sometimes..

patrickmcelwee commented 8 years ago

Here is the output of bower list:

├── angular#1.4.9 (latest is 1.5.1-build.4603+sha.f0f6da3)
├─┬ angular-bootstrap#0.13.4 (latest is 1.1.2)
│ └── angular#1.4.9 (1.5.1-build.4603+sha.f0f6da3 available)
├─┬ angular-cookies#1.4.9 (latest is 1.5.1-build.4603+sha.f0f6da3)
│ └── angular#1.4.9 (latest is 1.5.1-build.4603+sha.f0f6da3)
├─┬ angular-highlightjs#0.4.3 (latest is 0.5.1)
│ └── angular#1.4.9 (1.5.1-build.4603+sha.f0f6da3 available)
├─┬ angular-mocks#1.4.9 (latest is 1.5.1-build.4603+sha.f0f6da3)
│ └── angular#1.4.9
├─┬ angular-ui-router#0.2.18
│ └── angular#1.4.9 (1.5.1-build.4603+sha.f0f6da3 available)
├─┬ angular-ui-tinymce#0.0.13
│ ├── angular#1.4.9 (1.5.1-build.4603+sha.f0f6da3 available)
│ └── tinymce-dist#4.3.3
├─┬ angular-x2js#0.2.0
│ ├── angular#1.4.9 incompatible with ~1.3.0 (1.3.21-build.156+sha.63c83ff available, latest is 1.5.1-build.4603+sha.f0f6da3)
│ └── x2js#1.2.0
├─┬ bardjs#0.1.8
│ ├── angular#1.4.9 (1.5.1-build.4603+sha.f0f6da3 available)
│ ├── angular-mocks#1.4.9 (1.5.1-build.4603+sha.f0f6da3 available)
│ └── sinon#e-tag:208239-30
├─┬ bootstrap#3.3.6 (latest is 4.0.0-alpha.2)
│ └── jquery#2.1.4 (2.2.0 available, latest is 3.0.0-beta1)
├── font-awesome#4.4.0 (latest is 4.5.0)
├── highlightjs#8.7.0 (latest is 9.1.0)
├── jquery#2.1.4 (latest is 3.0.0-beta1)
├── lodash#3.10.1 (3.10.3-npm-packages available, latest is 4.3.0)
├─┬ ml-search-ng#0.2.4
│ ├── angular#1.4.9 (1.5.1-build.4603+sha.f0f6da3 available)
│ ├── lodash#3.10.1 (4.3.0 available)
│ └─┬ ml-common-ng#1.0.1
│   └── angular#1.4.9
├── ml-utils#7ad745f092
├─┬ ng-json-explorer#8c2a0f9104
│ └── angularjs#1.2.29 (1.2.30-build.605+sha.fb8f1dd available, latest is 1.5.1-build.4603+sha.f0f6da3)
├── sinon#e-tag:208239-30
└── vkbeautify-wrapper#b487a34530
grtjn commented 8 years ago

I had:

├─┬ angular-ui-router#0.2.15 (0.2.18 available)
│ └── angular#1.4.8 (1.5.1-build.4603+sha.f0f6da3 available)

Let me see what happens if I upgrade..

grtjn commented 8 years ago

I took latest bleeding edge, and am able to reproduce it with that in Chrome..

grtjn commented 8 years ago

It looks like it is a regression in angular-ui-router. It does not occur in angular-ui-router#0.2.15, but does in angular-ui-router#0.2.18.

On second thought looks like it is intentional :(, see http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider:

"squash --> true: The parameter's default value is omitted from the URL. If the parameter is preceeded and followed by slashes in the state's url declaration, then one of those slashes are omitted. This can allow for cleaner looking URLs."

grtjn commented 8 years ago

Let's drop that squash attribute, doesn't seem appropriate here..