krux / postscribe

Asynchronously write javascript, even with document.write.
MIT License
986 stars 156 forks source link

EXCEPTION: Cannot read property 'src' of null #369

Open arjenbrandenburgh opened 7 years ago

arjenbrandenburgh commented 7 years ago

Using Postscribe in combination with Angular2.

In my current project I'm looking to get a table from an external javascript file that contains a document.write. In the past we've done that in this fashion:

<script src="http://url.to.external.domain.com/file.ashx?sid=<ID>" type="text/javascript"></script>

Angular2 removes script tags from templates, so that is not a solution. I've used postscribe and that worked when Angular2 was still in RCs. At some point I suddenly noticed it stopped working, and can't trace back what package broke it.

I now get this error: stacktrace

The afterWrite callback still fires and the document.write in the external JS file has been written, but the done callback won't fire anymore. Since I'm working with an Angular2 SPA, the postscribe call won't happen again when opening a similar page, since it produced an error.

I've tried many things, but simply don't know what causes this. Was hoping anyone could help.

Plunkr: http://plnkr.co/edit/FHSVKDL2rv8TAQyTeqE2?p=preview You can see it's working, but in the console you see the same errors described above.

ghost commented 7 years ago

I ran into the same issue. Downgrading to v2.0.6 worked for me.

arjenbrandenburgh commented 7 years ago

@ghost's suggestion to downgrade to v2.0.6 indeed seems to have solved my problem.

Thanks. Leaving the issue open, since it still seems it should be fixed at some point.

giannoudak commented 7 years ago

Do you have any estimation on when this is going to be fixed? Thanks in advance