angulartics2
angulartics2 copied to clipboard
AOT compilation breaks RegExp in idsRegExp
For support questions, please consider using Gitter - Chat
I'm submitting a ...
-
[X] bug report
-
[ ] feature request
-
[ ] question about the decisions made in the repository
-
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem Create an angulartics module with configuration:
const ANGULARTICS_CONF: Partial<Angulartics2Settings> = {
pageTracking: {
clearIds: true,
idsRegExp: new Regex('^(([a-z0-9]{14}(:[a-z0-9]{6})?)|DEMO)$'),
clearQueryParams: true
}
};
And compile the application with AOT.
Then, check any URL matching this regex
NOTE: I'm using this RegEx as example, but this happens with any other Regex as well
- What is the expected behavior?
The ids matching the regex to be filtered out. However, this does not happen.
I've ben debugging in lower level, and it seems that using a regular expression with new Regex()
ends with Angulartics2 loading the default value instead.
A workaround is to write it as a string and skipping the typescript checks.
// @ts-ignore
idsRegExp: '^(([a-z0-9]{14}(:[a-z0-9]{6})?)|DEMO)$',
I have also seen that I'm not the only one with the same issue: https://stackoverflow.com/questions/54826529/angulartics-new-regexp-doesnt-appear-in-aot
-
What is the motivation / use case for changing the behavior? If you try with JIT, it works as expected, but AOT seems to be breaking the regex somehow.
-
Environment:
Angular CLI: 7.3.3
Node: 11.9.0
OS: darwin x64
Angular: 7.2.6
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.13.3
@angular-devkit/build-angular 0.13.3
@angular-devkit/build-optimizer 0.13.3
@angular-devkit/build-webpack 0.13.3
@angular-devkit/core 7.3.3
@angular-devkit/schematics 7.3.3
@angular/cdk 7.3.3
@angular/cli 7.3.3
@angular/flex-layout 7.0.0-beta.23
@angular/material 7.3.3
@angular/pwa 0.13.3
@ngtools/webpack 7.3.3
@schematics/angular 7.3.3
@schematics/update 0.13.3
rxjs 6.4.0
typescript 3.2.4
webpack 4.29.0
I ran into this as well. I've reported it to the Angular repo here https://github.com/angular/angular/issues/29668
Thanks for the string workaround though, seems like it should work for the regex match here.